Skip to content

Add functionality for goto-def on imports#221

Open
JonatanWaern wants to merge 4 commits into
mainfrom
add-goto-def-on-import
Open

Add functionality for goto-def on imports#221
JonatanWaern wants to merge 4 commits into
mainfrom
add-goto-def-on-import

Conversation

@JonatanWaern
Copy link
Copy Markdown
Contributor

  • Improve error reports from failing method adjustment
  • correct file-covering span
  • Store canonpaths instead of strings for resolved imports
  • Add the ability to goto-definition on an import

Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
Signed-off-by: Jonatan Waern <jonatan.waern@intel.com>
Copy link
Copy Markdown

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 extends the language server’s reference model to include file-based references and uses that to support goto-definition on import statements (jumping to the resolved imported file). It also improves some internal error reporting around overridden-method reference adjustment and corrects a file-covering span.

Changes:

  • Introduces Reference::{CodeReference, FileReference} and wires parsing/analysis to emit file references for imports.
  • Stores resolved import targets as CanonPath (instead of String) across analysis, templating, and storage layers.
  • Implements goto-definition behavior for import targets in semantic lookup, plus a fix to the “span covering entire file” range.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
USAGE.md Documents goto-definition behavior on import statements.
src/analysis/templating/topology.rs Switches import resolution map values to CanonPath and updates dependent logic.
src/analysis/templating/objects.rs Propagates CanonPath import mapping and updates make_device to accept CanonPath.
src/analysis/structure/toplevel.rs Fixes the “whole file” span range construction.
src/analysis/structure/objects.rs Updates global template reference creation to use CodeReference wrapped into Reference.
src/analysis/reference.rs Splits references into CodeReference vs Reference enum (adds FileReference).
src/analysis/parsing/types.rs Updates reference emission to produce CodeReference then convert into Reference.
src/analysis/parsing/structure.rs Adds reference emission for import file tokens (FileReference).
src/analysis/parsing/expression.rs Updates noderef/global-ref emission to CodeReference then convert into Reference.
src/analysis/mod.rs Updates reference processing to only resolve code references eagerly; switches import map to CanonPath; improves internal error reporting.
src/actions/semantic_lookup.rs Adds goto-definition-on-import support by mapping FileReference to resolved import targets.
src/actions/mod.rs Updates comments around active-context tracking.
src/actions/analysis_storage.rs Changes stored import map values from String to CanonPath.
src/actions/analysis_queue.rs Propagates CanonPath import source mapping through device analysis job setup.
CHANGELOG.md Notes the new goto-definition-on-import feature.

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

Comment on lines +264 to +266
let contexts_map = analysis_info.import_map.get(&CanonPath::from_path_buf(import_file_ref.span.path()).unwrap());
let all_imports = contexts_map.map(|file_imports|file_imports.values());
let mut result = vec![];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is sort-of-true, but the actual fix is to more clearly separate out what is:

  • A path guaranteed to exist in VFS
  • A path guaranteed to exist in FS
  • A path in general

Which is a larger refactor than should be in this PR, for now we'll crash if somebody deletes a file after goto-defing in i

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