Skip to content

Conversation

@381181295
Copy link

Summary

  • Server panicked on init when rootUri is invalid (e.g., file:// with no path)
  • to_file_path().unwrap() failed in server_formatter.rs and server_linter.rs
  • Changed ToolBuilder::build_boxed to return Option<Box<dyn Tool>>
  • Worker now uses filter_map() to skip tools that fail to build
  • Server responds with capabilities instead of crashing

Repro (before fix)

echo 'Content-Length: 95

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"capabilities":{},"rootUri":"file://"}}' | oxc_language_server
# Panics: called Option::unwrap() on a None value

After fix

Server returns capabilities JSON and continues running.

@381181295 381181295 requested a review from camc314 as a code owner December 26, 2025 19:53
Copilot AI review requested due to automatic review settings December 26, 2025 19:53
@381181295 381181295 requested a review from Sysix as a code owner December 26, 2025 19:53
@github-actions github-actions bot added A-editor Area - Editor and Language Server C-bug Category - Bug labels Dec 26, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a panic that occurred when the language server received an invalid rootUri during initialization (e.g., file:// with no path). The fix gracefully handles URI conversion failures by making tool builders return Option and filtering out failed tool builds.

Key changes:

  • Modified ToolBuilder::build_boxed to return Option<Box<dyn Tool>> instead of Box<dyn Tool>
  • Updated ServerLinterBuilder::build and ServerFormatterBuilder::build to return Option and handle invalid URIs with the ? operator
  • Added graceful fallback behavior in WorkspaceWorker::is_responsible_for_uri and start_worker to handle invalid root URIs

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_language_server/src/tool.rs Changed build_boxed trait method signature to return Option<Box<dyn Tool>> with updated documentation
crates/oxc_language_server/src/worker.rs Updated is_responsible_for_uri to return false for invalid URIs and modified start_worker to filter out failed tool builds using filter_map
crates/oxc_language_server/src/linter/server_linter.rs Changed build and build_boxed to return Option, added error logging for invalid URIs, and removed outdated panic documentation
crates/oxc_language_server/src/formatter/server_formatter.rs Changed build and build_boxed to return Option, added error logging for invalid URIs, and removed outdated panic documentation
crates/oxc_language_server/src/tests.rs Updated FakeToolBuilder to return Some(Box::new(FakeTool)) and adjusted test code to work with the new Option return type
crates/oxc_language_server/src/linter/tester.rs Added .expect("test requires valid root URI") to ensure tests fail clearly if the root URI is invalid
crates/oxc_language_server/src/formatter/tester.rs Added .expect("test requires valid root URI") to ensure tests fail clearly if the root URI is invalid

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@Sysix Sysix left a comment

Choose a reason for hiding this comment

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

Can you explain a bit more why this is needed?
I would never expect an invalid file URI for workspace/root URI's:)

@camc314 I do not think we will support non-file URIs for a tool base.
If we are 100% sure, we should probably add a check in the initialize request and return an Err instead of panicking.

@381181295
Copy link
Author

@Sysix I was debugging oxfmt not formatting on save in Zed, noticed an LSP crashed logand traced back to to_file_path().unwrap() in server_formatter.rs. Don't know exactly what Zed sent that triggered it originally.

@381181295 381181295 force-pushed the fix/language-server-invalid-root-uri branch from 2c1204b to 7ffcc21 Compare December 27, 2025 00:46
When LSP clients send an invalid rootUri (e.g., 'file://' with no path),
to_file_path() returns None. Previously this caused a panic via unwrap().

Now build_boxed() returns Option<Box<dyn Tool>>, allowing worker to skip
tools that fail to initialize. Server responds with capabilities instead
of crashing.
@381181295 381181295 force-pushed the fix/language-server-invalid-root-uri branch from 7ffcc21 to da003e0 Compare December 27, 2025 01:22
graphite-app bot pushed a commit that referenced this pull request Dec 27, 2025
…ris are not valid file paths (#17388)

Follow up from #17376 (review)
Tell the client, the server will not be started when we can create "cwd" for the tools.
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.

Even if we don't know what case causes this, it seems reasonable to handle by retuning an err (over unwrapping)

@camc314
Copy link
Contributor

camc314 commented Dec 27, 2025

Hmm I'm thinking the latest vscode failure isn't a flake

381181295 and others added 3 commits December 27, 2025 16:30
String prefix matching incorrectly matched file:///path/test_workspace_second
against root file:///path/test_workspace. Path::starts_with respects
directory boundaries.
@381181295
Copy link
Author

@camc314 fixed the vscode failur, is_responsible_for_uri was using string prefix matching instead of file path comparison, this was causing root_second to incorrectly match root.

reverted to path based comparison with error handling and added regression test in case it makes sense

@Sysix
Copy link
Member

Sysix commented Dec 28, 2025

Because is_responsible_for_uri uses again for to_file_path on the workspace worker root URI, no workspace worker is responsible for a URI ⇒ No tasks are done.

this was causing root_second to incorrectly match root.
I guess we need to sort the workspace workers before setting them in Backend. Or add a trailing slash at the URI, so it does not match similar names, like root and root_xyz

After #17388 I am not sure, if this PR is needed anymore.
@camc314 your thoughts? Fix sorting/trailing or closing this PR :)?

@camc314 camc314 self-assigned this Dec 28, 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-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants