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

⚡️ provide exclude patterns to file watcher args #1607

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TheAfroOfDoom
Copy link
Contributor

@TheAfroOfDoom TheAfroOfDoom commented Sep 27, 2024

right now we filter files for Spyglass to care about after we've already told chokidar to watch all our root directories.

chokidar ends up watching every file in the directory and is very slow, even if we later ignore certain files based on config.env.exclude.

not only that, but i couldn't get exclude patterns to work that you'd expect to work. for instance:


datapacks/omega-flowey/data/*/test wouldn't match the corresponding test directory relative to any of the project roots (mostly fixed ✅)

so i'd get lots of spyglass errors due to packtest's non-vanilla commands just on project open

before after
image image

Spyglass still shows errors if you open the file, but this is progress.

we could fix ^ by hooking the exclude config into connection.onHover (etc.) somewhere, but that's out of scope here


explicitly ignored datapack directories would still get parsed and show up in references/definitions (also mostly fixed ✅)

i have a build directory that is .gitignored, and this would still show up when i open a function's references.

on project load, these files are no longer bound to the function references, but they unfortunately still are bound again if you open the file. still an improvement though, and we can probably remedy further with similar methods to the packtest related stuff above

before, project load -> parses the explicitly .gitignore'd directory
image
after, project load -> doesnt parse (still parses if opened though)
image

resourcepack/pack.mcmeta (from project root(s)) wouldn't match a RP pack.mcmeta; i'd still get pack version errors ⚠️

note that while the watcher is no longer watching this file if i add it to my exclude list, Spyglass still finds it because findPackMcmeta doesn't use the exclude config yet.

maybe less relevant though bc i know Misode's been working on improving that specific bug anyway


major performance gain

regardless of the above issues being partially remedied, the biggest gain we get is from chokidar not recursively adding every file under every project root to the watched files list. with a properly formatted ignored list, chokidar stops early at a directory that matches an ignore pattern.

profile comparisons:

#ready time

before, gitignore specified but broken parsing after
image image

watch file count

before, gitignore specified but broken parsing after
image image

- known pitfall of chokidar described in the comment. we can help users avoid this easy mistake
- i think in the vast majority of cases, users won't want us parsing any files in there (.git, .yarn, ...)
- useful for excluding a project root that is only for references and Spyglass doesn't need to parse
- windows made this a pain, but it works for me locally; i can specify an absolute path (e.g. a workspace root i want to exclude) and the watcher skips the root's files.
- making it case-insensitive for windows was the annoying part
@TheAfroOfDoom TheAfroOfDoom changed the title WIP exclude improvements ⚡️ pass exclude paths to file watcher Sep 27, 2024
@TheAfroOfDoom TheAfroOfDoom marked this pull request as ready for review September 27, 2024 06:22
@TheAfroOfDoom TheAfroOfDoom changed the title ⚡️ pass exclude paths to file watcher ⚡️ pass-in exclude paths to file watcher args Sep 27, 2024
@TheAfroOfDoom TheAfroOfDoom changed the title ⚡️ pass-in exclude paths to file watcher args ⚡️ provide exclude paths to file watcher args Sep 27, 2024
watch(locations: FsLocation[], options: { usePolling?: boolean }): FsWatcher
watch(
locations: FsLocation[],
options: WatchOptions,
Copy link
Member

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

}
}
// 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(/(\\|\/)$/, '')))
Copy link
Member

Choose a reason for hiding this comment

The 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 NodeJsExternals watch handler.

@@ -185,6 +187,7 @@ export class Project implements ExternalEventEmitter {
config!: Config
ignore: Ignore = ignore()
readonly downloader: Downloader
readonly #excludePaths: string[] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weirdly named, it should be excludePatterns

.map((path) => resolvePath(path))
const matchesAbsolutePath = (path: string): boolean => {
return absoluteExcludePaths.some((exclude) => {
if (process.platform === 'win32') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break in the browser

@TheAfroOfDoom TheAfroOfDoom changed the title ⚡️ provide exclude paths to file watcher args ⚡️ provide exclude patterns to file watcher args Sep 27, 2024
@TheAfroOfDoom
Copy link
Contributor Author

TODO should maybe also bump cache version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants