-
Notifications
You must be signed in to change notification settings - Fork 34
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
⚡️ provide exclude
patterns to file watcher args
#1607
Changes from all commits
4f36ed9
50dc305
370c3aa
abd7e4f
7c97718
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import type { Ignore } from 'ignore' | ||
import ignore from 'ignore' | ||
import { isAbsolute, resolve as resolvePath } from 'path' | ||
import url from 'url' | ||
import type { TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument' | ||
import { TextDocument } from 'vscode-languageserver-textdocument' | ||
import type { ExternalEventEmitter, Externals, FsWatcher, IntervalId } from '../common/index.js' | ||
|
@@ -185,6 +187,7 @@ export class Project implements ExternalEventEmitter { | |
config!: Config | ||
ignore: Ignore = ignore() | ||
readonly downloader: Downloader | ||
readonly #excludePaths: string[] = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is weirdly named, it should be |
||
readonly externals: Externals | ||
readonly fs: FileService | ||
readonly isDebugging: boolean | ||
|
@@ -395,16 +398,30 @@ export class Project implements ExternalEventEmitter { | |
const loadConfig = async () => { | ||
this.config = await this.#configService.load() | ||
this.ignore = ignore() | ||
await parseExcludePaths() | ||
for (const pattern of this.#excludePaths) { | ||
this.ignore.add(pattern) | ||
} | ||
} | ||
|
||
const parseExcludePaths = async () => { | ||
const paths = [] | ||
for (const pattern of this.config.env.exclude) { | ||
if (pattern === '@gitignore') { | ||
const gitignore = await this.readGitignore() | ||
if (gitignore) { | ||
this.ignore.add(gitignore) | ||
const gitignoreLines = gitignore.split(/\r?\n/) | ||
const gitignorePaths = gitignoreLines | ||
.filter((line) => line !== '' && !line.startsWith('#')) | ||
paths.push(...gitignorePaths) | ||
} | ||
} else { | ||
this.ignore.add(pattern) | ||
paths.push(pattern) | ||
} | ||
} | ||
// Chokidar never matches paths with a trailing (back)slash, so fix any paths | ||
// that may be specified as such | ||
this.#excludePaths.push(...paths.map((path) => path.replace(/(\\|\/)$/, ''))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a chokidar specific requirement, this should be moved to the |
||
} | ||
const callIntializers = async () => { | ||
const initCtx: ProjectInitializerContext = { | ||
|
@@ -514,9 +531,36 @@ export class Project implements ExternalEventEmitter { | |
resolve() | ||
return | ||
} | ||
|
||
const ignored = [] | ||
const absoluteExcludePaths = this.#excludePaths | ||
.filter(isAbsolute) | ||
.map((path) => resolvePath(path)) | ||
const matchesAbsolutePath = (path: string): boolean => { | ||
return absoluteExcludePaths.some((exclude) => { | ||
if (process.platform === 'win32') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break in the browser |
||
const normalizeWinPath = (p: string) => resolvePath(p).toLowerCase() | ||
return normalizeWinPath(path) === normalizeWinPath(exclude) | ||
} else { | ||
return exclude === path | ||
} | ||
}) | ||
} | ||
ignored.push(matchesAbsolutePath) | ||
|
||
const relativeExcludePaths = this.#excludePaths.filter((path) => !isAbsolute(path)) | ||
// Need to list the full file paths for chokidar to match | ||
for (const rootUri of this.projectRoots) { | ||
const absolutePaths = relativeExcludePaths.map((path) => | ||
url.fileURLToPath(`${rootUri}${path}`) | ||
) | ||
ignored.push(...absolutePaths) | ||
} | ||
|
||
this.#watchedFiles.clear() | ||
this.#watcherReady = false | ||
this.#watcher = this.externals.fs.watch(this.projectRoots, { | ||
ignored, | ||
usePolling: this.config.env.useFilePolling, | ||
}).once('ready', () => { | ||
this.#watcherReady = true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't directly use chokidar's
WatchOptions
, this is an interface that needs to be shared between the nodejs and browser externals