Skip to content

refactor(language_server): move gitignore_glob to ServerLinter#10762

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_
May 7, 2025
Merged

refactor(language_server): move gitignore_glob to ServerLinter#10762
graphite-app[bot] merged 1 commit intomainfrom
05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_

Conversation

@Sysix
Copy link
Member

@Sysix Sysix commented May 2, 2025

No description provided.

Copy link
Member Author

Sysix commented May 2, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-editor Area - Editor and Language Server C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 2, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 2, 2025

CodSpeed Instrumentation Performance Report

Merging #10762 will not alter performance

Comparing 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ (9ec13f6) with main (6de5a43)

Summary

✅ 36 untouched benchmarks

@Sysix Sysix force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from 96c2cbb to c6e2d45 Compare May 3, 2025 09:39
@Sysix Sysix force-pushed the 05-02-refactor_language_server_move_functions_related_to_serverlinter_to_serverlinter_ branch from 1a95dc4 to 66aea30 Compare May 3, 2025 09:39
@Sysix Sysix force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from c6e2d45 to 794f6a2 Compare May 3, 2025 11:34
@Boshen Boshen force-pushed the 05-02-refactor_language_server_move_functions_related_to_serverlinter_to_serverlinter_ branch from 66aea30 to 54592e0 Compare May 4, 2025 01:47
@graphite-app graphite-app bot changed the base branch from 05-02-refactor_language_server_move_functions_related_to_serverlinter_to_serverlinter_ to graphite-base/10762 May 4, 2025 01:51
@graphite-app graphite-app bot force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from 794f6a2 to 5087608 Compare May 4, 2025 07:12
@graphite-app graphite-app bot force-pushed the graphite-base/10762 branch from 66aea30 to 3d794f6 Compare May 4, 2025 07:12
@graphite-app graphite-app bot changed the base branch from graphite-base/10762 to main May 4, 2025 07:13
@graphite-app graphite-app bot force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from 5087608 to 8c611a6 Compare May 4, 2025 07:13
@Sysix Sysix marked this pull request as ready for review May 4, 2025 07:38
@coderabbitai
Copy link

coderabbitai bot commented May 4, 2025

Walkthrough

The changes centralize ignore pattern handling within the ServerLinter component by adding a gitignore_glob field that stores ignore patterns from .gitignore, .eslintignore, and inline configuration. The previously public create_ignore_glob method is made private and returns these patterns. A new private method is_ignored checks if a file URI matches any ignore pattern and skips linting for such files in the run_single method.

In contrast, the WorkspaceWorker struct removes its ignore pattern logic, including the gitignore_glob field and the is_ignored method. The method for refreshing linter configuration is renamed and simplified to only recreate the ServerLinter. The lint_file method no longer checks for ignored files before updating diagnostics, and the update_diagnostics method’s return type changes to an Option to indicate the presence or absence of diagnostics. These updates consolidate ignore pattern filtering within ServerLinter and simplify the WorkspaceWorker logic.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c611a6 and 88072e4.

📒 Files selected for processing (2)
  • crates/oxc_language_server/src/linter/server_linter.rs (5 hunks)
  • crates/oxc_language_server/src/worker.rs (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/oxc_language_server/src/worker.rs
  • crates/oxc_language_server/src/linter/server_linter.rs
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Benchmark (formatter)
  • GitHub Check: Benchmark (codegen)
  • GitHub Check: Benchmark (minifier)
  • GitHub Check: Test wasm32-wasip1-threads
  • GitHub Check: Benchmark (semantic)
  • GitHub Check: Test Linux
  • GitHub Check: Benchmark (isolated_declarations)
  • GitHub Check: Benchmark (transformer)
  • GitHub Check: Benchmark (parser)
  • GitHub Check: Clippy
  • GitHub Check: Build Linter Benchmark
  • GitHub Check: Test
  • GitHub Check: Benchmark (lexer)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
crates/oxc_language_server/src/worker.rs (1)

106-119: ⚠️ Potential issue

Stale diagnostics remain for newly-ignored files

When run_single returns None (e.g. the file has just become ignored via a new .gitignore rule),
we exit early without purging the previous entry in diagnostics_report_map.
As a result, the client will keep showing old diagnostics for files that should now be ignored.

-        if let Some(diagnostics) = diagnostics {
-            self.diagnostics_report_map
-                .read()
-                .await
-                .pin()
-                .insert(uri.to_string(), diagnostics.clone());
-
-            return Some(diagnostics);
-        }
-
-        None
+        match diagnostics {
+            Some(reports) => {
+                self.diagnostics_report_map
+                    .read()
+                    .await
+                    .pin()
+                    .insert(uri.to_string(), reports.clone());
+                Some(reports)
+            }
+            None => {
+                // Clear stale diagnostics for ignored / deleted files
+                self.diagnostics_report_map
+                    .read()
+                    .await
+                    .pin()
+                    .remove(&uri.to_string());
+                None
+            }
+        }

Ensuring the cache is cleaned keeps the client view consistent with the server’s ignore logic.

🧹 Nitpick comments (4)
crates/oxc_language_server/src/worker.rs (2)

70-80: Minimise lock-holding while rebuilding the linter

refresh_server_linter keeps a read lock on nested_configs for the whole duration of ServerLinter::create_server_linter(..).
That helper clones the entire map (pin().iter() … collect) and also performs filesystem I/O when rebuilding configs, which can be slow.
Holding the read-lock that long prevents writers (e.g. did_change_watched_files) from mutating nested_configs, so a burst of rebuilds could starve writers.

A lighter pattern:

-let nested_configs = self.nested_configs.read().await;
-let server_linter = ServerLinter::create_server_linter(
-    self.root_uri.get().unwrap(),
-    &options,
-    &nested_configs,
-);
+let nested_snapshot = {
+    // clone while we *briefly* hold the lock …
+    self.nested_configs.read().await.clone()
+};
+let server_linter = ServerLinter::create_server_linter(
+    self.root_uri.get().unwrap(),
+    &options,
+    &nested_snapshot,
+);

This confines the critical section to an inexpensive clone and removes any contention between config updates and linter rebuilds.


252-253: Avoid unnecessary full linter rebuilds

refresh_server_linter() is called unconditionally after every watched-file event when nested configs are enabled, even when the change was not to an oxlint config file (earlier guards may bail-out, but the call still happens).
Rebuilding the linter is expensive (re-parsing every config, re-walking ignore files).

Consider invoking the refresh only when:

  1. file_event.typ implies creation / update / deletion and
  2. the file matched OXC_CONFIG_FILE.

This yields the same behaviour with far less CPU.

crates/oxc_language_server/src/linter/server_linter.rs (2)

70-116: create_ignore_glob can become O(N·files) & block the server

The function recursively walks the entire workspace on every linter rebuild to locate
.gitignore / .eslintignore files.
In large mono-repos this can take seconds and is performed on the async-runtime thread, blocking other requests.

Suggestions:

  1. Cache the resulting Vec<Gitignore> in WorkspaceWorker and only refresh it when a watched ignore file changes.
  2. Restrict the walk to directories actually referenced by the current uri being linted (lazily load).
  3. Off-load the walk to a blocking task: tokio::task::spawn_blocking.

These changes would keep latency predictable even for huge repositories.


200-206: Run-time check now relies on ignore logic – add unit tests

run_single short-circuits on is_ignored, which is great, but there are no
tests exercising workspace ignore rules (only nested-config tests exist).

Adding fixtures such as:

fixtures/linter/ignore_patterns
 ├─ .gitignore       (# ignore *.ts)
 └─ src/ignored.ts

and asserting that run_single returns None for ignored.ts would lock this
behaviour in place and prevent future regressions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d794f6 and 8c611a6.

📒 Files selected for processing (2)
  • crates/oxc_language_server/src/linter/server_linter.rs (5 hunks)
  • crates/oxc_language_server/src/worker.rs (6 hunks)

@Sysix Sysix force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from 8c611a6 to 88072e4 Compare May 4, 2025 08:44
@Sysix Sysix requested review from camc314 and camchenry May 5, 2025 10:27
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

looks good to me, but looks like there's conflicts

@Sysix Sysix force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from 88072e4 to fb5a464 Compare May 7, 2025 11:40
@Sysix Sysix added the 0-merge Merge with Graphite Merge Queue label May 7, 2025
Copy link
Member Author

Sysix commented May 7, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch from fb5a464 to 9ec13f6 Compare May 7, 2025 11:58
@graphite-app graphite-app bot merged commit 9ec13f6 into main May 7, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 05-02-refactor_language_server_move_gitignore_glob_to_serverlinter_ branch May 7, 2025 12:01
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-editor Area - Editor and Language Server C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants