Repository navigation
fix: refresh workspace match and watch state on reload - #984
Conversation
b2d5970 to
fb766ef
Compare
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the workspace management and file watching capabilities of the language server. The primary goal is to eliminate issues where configuration changes were not fully applied until a restart, leading to stale analysis states and incorrect file indexing. By introducing a centralized file matcher, a more robust reload mechanism with decoupled debounce tasks, and improved open file handling, the language server now provides a more consistent and responsive experience when workspace configurations are updated. This also includes better management of external library roots and dynamic file watcher registration. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and well-executed refactoring to address how the language server handles workspace configuration reloads. The changes ensure that modifications to workspace.library, workspace.packageDirs, and workspace.workspaceRoots are correctly applied without requiring a server restart. Key improvements include separating config reload and re-indexing tasks, preserving unsaved buffer content across reloads, and enhancing the file watching mechanism. The code is more robust and maintainable. I have one suggestion regarding performance in the new file matching logic.
|
|
||
| for entry in &self.entries { | ||
| let Ok(relative_path) = path.strip_prefix(&entry.root) else { | ||
| continue; | ||
| }; | ||
|
|
||
| if entry.exclude_dir.iter().any(|dir| path.starts_with(dir)) { | ||
| continue; | ||
| } | ||
|
|
||
| if !entry.exclude.is_empty() { | ||
| match wax::any(entry.exclude.iter().map(|s| s.as_str())) { | ||
| Ok(exclude_set) if wax::Pattern::is_match(&exclude_set, relative_path) => { | ||
| continue; | ||
| } | ||
| Ok(_) => {} | ||
| Err(_) => log::error!("Invalid exclude pattern"), | ||
| } | ||
| } | ||
|
|
||
| if wax::Pattern::is_match(&include_set, relative_path) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| false | ||
| } | ||
|
|
||
| pub fn watch_roots(&self) -> HashSet<PathBuf> { | ||
| self.watch_roots.clone() | ||
| } | ||
|
|
||
| pub fn source_file_globs(&self) -> &[String] { | ||
| &self.include | ||
| } |
There was a problem hiding this comment.
The is_match function re-compiles glob patterns on every call by using wax::any with string slices. This can be inefficient, especially since is_match might be called frequently for file events. To improve performance, consider pre-compiling the glob patterns into wax::Glob<'static> and storing them in WorkspaceFileMatcher and WorkspaceMatchEntry structs. You could then pass references to these compiled globs to wax::any.
For example, you could change the fields in WorkspaceFileMatcher and WorkspaceMatchEntry:
// In WorkspaceFileMatcher
use wax::Glob;
pub struct WorkspaceFileMatcher {
include: Vec<Glob<'static>>,
// ...
}
// In WorkspaceMatchEntry
struct WorkspaceMatchEntry {
// ...
exclude: Vec<Glob<'static>>,
// ...
}You would then need to update the builder functions to perform the compilation once. wax::Glob has an into_owned() method that can be used to create a 'static version from a String.
0f05387 to
5ac5952
Compare
Config reloads were rebuilding analysis state, but the workspace manager kept using stale match roots and watched-file registrations. After changing `workspace.library`, `workspace.packageDirs`, or `workspace.workspaceRoots`, newly added roots were not treated as workspace files until restart, removed roots could stay indexed, and external roots could keep stale watcher coverage. Fix that by rebuilding the effective workspace folder set whenever config is loaded and using that same resolved view for indexing, file matching, and watch registration. This change: - rebuilds workspace folders from the base workspace roots plus configured workspace roots, libraries, and package dirs - refreshes `WorkspaceFileMatcher` state on reload so membership checks track the new config immediately - re-registers dynamic watched-file globs and recreates notify watchers for roots outside the editor workspace - clears non-stdlib workspaces before reloading files so removed roots drop out of analysis - preserves open-buffer text across reloads so unsaved edits survive when a file enters or leaves the workspace - clears push diagnostics for files removed by a reload - separates debounced config reloads from reindex requests so saves no longer cancel a pending config reload Add high-level tests covering: - config reload surviving a concurrent reindex request - configured workspace roots being loaded after reload - removed libraries being dropped from analysis and diagnostics - unsaved open text surviving workspace membership changes - watcher state being rebuilt for external library roots
5ac5952 to
bd63057
Compare
Summary
Config reload rebuilt analysis state, but the language server could keep using stale workspace matching state and stale watched-file registrations. In practice, changes to
workspace.library,workspace.packageDirs, orworkspace.workspaceRootswere not always reflected until restart, removed roots could stay indexed, and external library roots could keep outdated watch coverage.What changed
workspaceRootslibrarypackageDirsemmylua_code_analysisandemmylua_lsto remove duplicated matching logicWhy
Before this change: