Skip to content

LSP server#239

Merged
0xGeorgii merged 3 commits into
mainfrom
33-feature-lsp-server
Jul 16, 2026
Merged

LSP server#239
0xGeorgii merged 3 commits into
mainfrom
33-feature-lsp-server

Conversation

@0xGeorgii

@0xGeorgii 0xGeorgii commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR is safe to merge — it adds a substantial new LSP server and IDE stack with no regressions to existing code paths.

All core paths — URI conversion, position encoding, diagnostics publishing, the shutdown handshake, and the VS Code lifecycle queue — are correctly implemented and well-covered by tests. The one behavioral edge case (inlay hints falling back to the whole file when a viewport range extends past the last line) is harmless in practice and does not affect correctness for any standard editor flow.

apps/lsp/src/handlers.rs — the inlay_hint range fallback is the only area worth a follow-up look before the feature ships to end users.

Important Files Changed

Filename Overview
apps/lsp/src/server.rs New: single-threaded message loop with inline shutdown handshake, request dispatch, and dependent-document republish logic; well-tested with unit coverage of all notification paths.
apps/lsp/src/handlers.rs New: per-request and per-notification handlers; inlay_hint silently falls back to returning all hints when the viewport range is out of bounds (text_range returns None).
apps/lsp/src/uri.rs New: hand-rolled file URI ↔ path conversion with explicit Windows drive-letter handling; comprehensive round-trip tests including percent-encoding, backslash, and query/fragment rejection.
apps/lsp/src/convert.rs New: byte-offset ↔ LSP position/range conversion and IDE→LSP type mappings; every variant is covered explicitly and tested.
ide/ide-db/src/database.rs New: RootDatabase with closure-aware invalidation; open/change/close correctly handles the newly-available widening case for missing imports.
ide/ide-db/src/hit_test.rs New: file-scoped AST hit-testing that descends to the smallest covering node; correctly guards against zero-width default locations claiming offset 0.
ide/ide-db/src/analysis.rs New: FileAnalysis computes type-check, analysis rules, and per-closure file metadata once; closure_paths always includes the entry path to prevent permanent cache poisoning.
ide/vfs/src/lib.rs New: path-interner plus in-memory overlay; no I/O, idempotent interning, correct overlay lifecycle.
editors/vscode/src/lsp/client.ts New: serialized LSP lifecycle management via a promise queue; doStop sets client=undefined before awaiting stop so re-entry is safe; correctly disposes the client on deactivation.
editors/vscode/src/lsp/resolve.ts New: pure binary-resolution helper (settings → managed path → PATH); vscode-free so it is directly unit-testable; correctly refuses to fall back when an explicit path is non-executable.
ide/ide/src/lib.rs New: AnalysisHost/Analysis facade exposing all IDE features by path; closure_line_index reuses the document's already-computed analysis for cross-file position conversion.
apps/lsp/src/main.rs Modified: spawns the server loop on a 64 MiB stack thread (mirrors rust-analyzer) to prevent deep-AST stack overflows on pathological inputs.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Editor as VS Code Editor
    participant Client as LSP Client (client.ts)
    participant Server as inference-lsp (server.rs)
    participant Handler as handlers.rs
    participant IDE as AnalysisHost (ide/src/lib.rs)
    participant DB as RootDatabase (ide-db/src/database.rs)
    participant VFS as Vfs (vfs/src/lib.rs)

    Editor->>Client: activate extension
    Client->>Server: initialize (stdio)
    Server-->>Client: capabilities (FULL sync, hover, def, completion, symbols, hints)

    Editor->>Client: didOpen(uri, text)
    Client->>Server: textDocument/didOpen
    Server->>Handler: did_open(params)
    Handler->>IDE: open_document(path, text)
    IDE->>DB: open_document(path, text)
    DB->>VFS: set_contents(id, text)
    DB->>DB: invalidate dependent analyses
    Handler->>IDE: analysis().diagnostics(path)
    IDE->>DB: analysis(path) compute and memoize FileAnalysis
    DB-->>IDE: FileAnalysis
    IDE-->>Handler: Vec Diagnostic
    Handler-->>Server: PublishDiagnosticsParams plus dependents
    Server->>Client: textDocument/publishDiagnostics x N open docs

    Editor->>Client: hover request
    Client->>Server: textDocument/hover
    Server->>Handler: hover(params)
    Handler->>IDE: analysis().line_index(path)
    Handler->>IDE: analysis().hover(path, offset)
    IDE-->>Handler: Option Hover
    Handler-->>Server: Option Hover
    Server-->>Client: result

    Editor->>Client: didClose(uri)
    Client->>Server: textDocument/didClose
    Server->>Handler: did_close(params)
    Handler->>IDE: close_document(path)
    IDE->>VFS: remove_contents(id)
    Handler-->>Server: empty PublishDiagnosticsParams
    Server->>Client: textDocument/publishDiagnostics clear diagnostics
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Editor as VS Code Editor
    participant Client as LSP Client (client.ts)
    participant Server as inference-lsp (server.rs)
    participant Handler as handlers.rs
    participant IDE as AnalysisHost (ide/src/lib.rs)
    participant DB as RootDatabase (ide-db/src/database.rs)
    participant VFS as Vfs (vfs/src/lib.rs)

    Editor->>Client: activate extension
    Client->>Server: initialize (stdio)
    Server-->>Client: capabilities (FULL sync, hover, def, completion, symbols, hints)

    Editor->>Client: didOpen(uri, text)
    Client->>Server: textDocument/didOpen
    Server->>Handler: did_open(params)
    Handler->>IDE: open_document(path, text)
    IDE->>DB: open_document(path, text)
    DB->>VFS: set_contents(id, text)
    DB->>DB: invalidate dependent analyses
    Handler->>IDE: analysis().diagnostics(path)
    IDE->>DB: analysis(path) compute and memoize FileAnalysis
    DB-->>IDE: FileAnalysis
    IDE-->>Handler: Vec Diagnostic
    Handler-->>Server: PublishDiagnosticsParams plus dependents
    Server->>Client: textDocument/publishDiagnostics x N open docs

    Editor->>Client: hover request
    Client->>Server: textDocument/hover
    Server->>Handler: hover(params)
    Handler->>IDE: analysis().line_index(path)
    Handler->>IDE: analysis().hover(path, offset)
    IDE-->>Handler: Option Hover
    Handler-->>Server: Option Hover
    Server-->>Client: result

    Editor->>Client: didClose(uri)
    Client->>Server: textDocument/didClose
    Server->>Handler: did_close(params)
    Handler->>IDE: close_document(path)
    IDE->>VFS: remove_contents(id)
    Handler-->>Server: empty PublishDiagnosticsParams
    Server->>Client: textDocument/publishDiagnostics clear diagnostics
Loading

Reviews (2): Last reviewed commit: "more tests" | Re-trigger Greptile

Context used:

  • Rule used - When reviewing LSP server code in this repo, prefe... (source)

@0xGeorgii 0xGeorgii self-assigned this Jul 16, 2026
@0xGeorgii 0xGeorgii added the lsp Language Server Protocol label Jul 16, 2026
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Comment thread apps/lsp/src/convert.rs
Comment thread apps/lsp/src/handlers.rs
This was referenced Jul 16, 2026
@0xGeorgii 0xGeorgii merged commit d8a17c3 into main Jul 16, 2026
7 checks passed
@0xGeorgii 0xGeorgii deleted the 33-feature-lsp-server branch July 16, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lsp Language Server Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant