Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vscode): ts server restart on file change #1424

Merged
merged 17 commits into from
May 30, 2023
28 changes: 24 additions & 4 deletions packages/vscode/src/plugins/prisma-language-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path'
import FileWatcher from 'watcher'
import type { type as FileWatcherType } from 'watcher'
import minimatch from 'minimatch'

import {
CancellationToken,
Expand Down Expand Up @@ -59,6 +58,19 @@ const activateClient = (
context.subscriptions.push(disposable)
}

/**
* These are the paths that are watched by the file watcher. We have to specify
* the full paths that we will watch, otherwise we will get a lot of events.
* All these paths are necessary for the file watcher to work properly. Read
* > ignore: https://github.com/fabiospampinato/watcher#options
*/
const watchedPaths = [
/node_modules$/,
/node_modules[\\/]\.prisma$/,
/node_modules[\\/]\.prisma[\\/]client$/,
/node_modules[\\/]\.prisma[\\/]client[\\/]index\.d\.ts$/,
]

const startFileWatcher = (rootPath: string) => {
console.debug('Starting File Watcher')
// https://github.com/fabiospampinato/watcher
Expand All @@ -74,10 +86,18 @@ const startFileWatcher = (rootPath: string) => {
recursive: true,
ignoreInitial: true,
ignore: (targetPath) => {
if (targetPath === rootPath) {
return false
if (targetPath === rootPath) return false

// we ignore all files that are not a match
const isIgnored = watchedPaths.reduce((acc, regex) => {
return acc && targetPath.match(regex) === null
}, true)
millsp marked this conversation as resolved.
Show resolved Hide resolved

if (isIgnored === false) {
console.log(`File Watcher: Watching ${targetPath}`)
}
return !minimatch(targetPath, '**/node_modules/.prisma/client/index.d.ts')

return isIgnored
},
// // ignore dotfiles (except .prisma) adjusted from chokidar README example
// ignored: /(^|[\/\\])\.(?!prisma)./,
Expand Down