Skip to content

✨ feat(lsp): improve goto definition to navigate to correct source files #1221

Merged
harehare merged 3 commits intomainfrom
feat/lsp-goto-definition-cross-module
Feb 5, 2026
Merged

✨ feat(lsp): improve goto definition to navigate to correct source files #1221
harehare merged 3 commits intomainfrom
feat/lsp-goto-definition-cross-module

Conversation

@harehare
Copy link
Copy Markdown
Owner

@harehare harehare commented Feb 5, 2026

- Add `url_by_source()` method to HIR for retrieving URLs by source ID
- Add `get_module_path()` to ModuleLoader and `get_path()` to ModuleResolver trait
- Update goto_definition to navigate to the symbol's actual source file
- Return None for builtin symbols (no file to navigate to)
- Add `-M/--module-path` CLI option to LSP for custom module search paths
- Add comprehensive tests for the new functionality
Copilot AI review requested due to automatic review settings February 5, 2026 13:33
Copy link
Copy Markdown
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 enhances the LSP's goto definition feature to correctly navigate to the actual source files where symbols are defined, including support for module imports. The implementation adds module path resolution and properly handles builtin symbols that have no file to navigate to.

Changes:

  • Added get_path method to ModuleResolver trait to retrieve the absolute file path of a module
  • Updated goto definition to resolve the correct target URL based on the symbol's source file instead of always using the current file
  • Added CLI support for configuring module search paths via the --module-path flag

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/mq-lang/src/module/resolver.rs Adds get_path method to ModuleResolver trait for retrieving module file paths
crates/mq-lang/src/module.rs Exposes get_module_path method in ModuleLoader to access module paths
crates/mq-wasm/src/script.rs Implements get_path for WASM module resolver (returns module name as-is)
crates/mq-hir/src/hir.rs Adds url_by_source method and updates module resolution to use actual file paths
crates/mq-lsp/src/goto_definition.rs Updates goto definition to navigate to the correct source file using symbol's source_id
crates/mq-lsp/src/main.rs Adds CLI argument parsing for module paths using clap
crates/mq-lsp/Cargo.toml Adds clap dependency with derive feature
crates/mq-formatter/src/formatter.rs Changes unused token variable to underscore

Copilot AI review requested due to automatic review settings February 5, 2026 13:38
Copy link
Copy Markdown
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

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.


fn get_path(&self, module_name: &str) -> Result<String, ModuleError> {
let file_path = search(module_name, &self.paths)?;
Ok(file_path.to_str().unwrap_or_default().to_string())
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

When to_str() returns None (invalid UTF-8 path), this silently returns an empty string. Consider returning a more descriptive error that explains the path could not be converted to UTF-8, which would help users debug path-related issues.

Suggested change
Ok(file_path.to_str().unwrap_or_default().to_string())
let path_str = file_path.to_str().ok_or_else(|| {
ModuleError::IOError(Cow::Owned(format!(
"Module path is not valid UTF-8: {:?}",
file_path
)))
})?;
Ok(path_str.to_string())

Copilot uses AI. Check for mistakes.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 5, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/lsp-goto-definition-cross-module (1ce312d) with main (73ed7c3)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (8e8d0b1) during the generation of this report, so 73ed7c3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@harehare harehare merged commit 45ee3f6 into main Feb 5, 2026
7 checks passed
@harehare harehare deleted the feat/lsp-goto-definition-cross-module branch February 5, 2026 13:51
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