Skip to content

lsp: non-entry file opened standalone resolves imports against its own directory — false missing-import diagnostics on valid projects #243

Description

@0xGeorgii

Follow-up from the comprehensive review of PR #239 (LSP server). Line numbers reference the PR branch at review time.

Severity: major (reproduced by execution during review; known v1 trade-off, now confirmed user-visible)

Import paths are source-root-relative for every file in a closure (one src_root per walk; project.rs enqueue_imports uses module_file_path(self.src_root, ...)), but RootDatabase analyzes each open file as its own entry with its own directory as source root (ide/ide-db/src/database.rs:14 area).

Repro: project main.inf (use lib::a;), lib/a.inf (use lib::b;), lib/b.inf. From the entry all 3 files resolve with 0 import problems. Opening lib/a.inf standalone resolves lib::b against /proj/lib as root, probing /proj/lib/lib/b.inf → 1 missing-import problem. Since the LSP server pushes diagnostics per open document from that document's own-entry analysis, any user who goto-defs or browses into a subdirectory file of a multi-directory project immediately gets false "file not found for import" squiggles (plus missing symbols / type errors) on a file the compiler accepts — the exact compiler/IDE disagreement the shared FileLoader seam was built to prevent.

This is the AD-4 limitation from the original design (open non-entry file analyzed as its own entry); manifest-aware entry mapping was noted as the forward path.

Suggested fix: resolve a project root for opened files (walk up to a workspace/manifest root, or reuse the closure of an already-analyzed entry that contains the file) before falling back to file-as-own-entry; at minimum suppress missing-import diagnostics for documents already present in another open entry's closure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglspLanguage Server Protocol

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions