Skip to content

docs(language-server): spec for lazy document state + pull diagnostics#887

Draft
SevInf wants to merge 15 commits into
mainfrom
lsp-document-state
Draft

docs(language-server): spec for lazy document state + pull diagnostics#887
SevInf wants to merge 15 commits into
mainfrom
lsp-document-state

Conversation

@SevInf

@SevInf SevInf commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Specification-only PR for the lsp-document-state project. No implementation here — this commits the Drive project artifacts (spec, plan, slice spec) so the design can be reviewed before any code lands.

What this is

A settled design for reworking the language server's document-state lifecycle from eager, defensive reparse to invalidate-on-change + lazily materialize-on-read, synchronously, plus a move from push to pull diagnostics.

didChange  ──▶  mark the document's project dirty            (cheap; no parse)
read req   ──▶  await project load (only while uncached)      (async: config eval, cached)
            ──▶  ensureCurrent(project, uri)                  (SYNC: reparse iff version changed)
            ──▶  derive (completion / diagnostics / …)        (SYNC: no await before deriving)

Why

  • Today every edit parses twice (eager publish + currentDocumentArtifact per-request reparse with a whole-document text compare) to dodge a stale-buffer race the LSP spec says we should not have to fight.
  • We are single-threaded and synchronous, so tsserver's version-keyed lazy recompute fits; rust-analyzer's snapshot/cancellation machinery exists only because its reads run on background threads.
  • Async is confined to project/config load (executable prisma-next.config.ts, evaluated via dynamic import); parse/derive stays synchronous so a derived result is always internally consistent for one version.

Scope

  • One slice: lazy-state-and-pull-diagnostics (lazy lifecycle + pull diagnostics ship together — dropping eager compute requires the pull transport to exist).
  • TextDocuments is kept (demoted to text mirror / lifecycle / version source).
  • Diagnostics flags ship as { interFileDependencies: false, workspaceDiagnostics: false } with an honest scope-comment; the multi-input table flip is deferred.

Non-goals

Removing TextDocuments, the multi-input symbol table, multi-project membership, and any behavioural changes to completion/semantic-tokens/folding. See projects/lsp-document-state/spec.md § Non-goals.

Sequencing

Stacked on lsp-autocomplete (#871); base is lsp-autocomplete, not main. Merges after #871.

Artifacts

  • projects/lsp-document-state/spec.md
  • projects/lsp-document-state/plan.md
  • projects/lsp-document-state/slices/lazy-state-and-pull-diagnostics/spec.md

SevInf added 15 commits June 29, 2026 08:45
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Make red tokens navigable (parent, prev/next token) and add SyntaxNode.tokenAtOffset (none/single/between with left/right bias), coveringElement, first/lastToken, plus trivia-skip helpers (skipTriviaToken, nonTriviaSibling, previousNonTriviaToken). Mirrors rust-analyzer syntax idioms; no fake-identifier marker.

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
…navigation

Anchor classification on tokenAtOffset(offset).leftBiased() and navigate from token.parent, with one source_range()-style replacement helper. Removes findCursorContext, findTokenContext, findDeepestNodeAtOffset, tokensBetween, lineStartOffsetFromTokens, containsOnlyWhitespaceTokens, the duplicated prefix builders, and the unused UnsupportedPslCompletionReason. Behavior unchanged; matches rust-analyzer classifier shape.

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
…layground URL parsing

Address PR review: rebuild completion artifacts from the current buffer before classifying so completions after an edit are not stale; parse playground request URLs against a fixed local base and return 400 on malformed/absent URLs instead of trusting the incoming Host header.

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
…d review dispatch

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
…code comments

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
… AST

Replace the splitQualifiedPrefix source scan (which re-tokenized the qualified name by counting : and . in raw text) with QualifiedNameAst navigation: contract-space/namespace/name roles are resolved from colon()/dot() offsets and segment IdentifierAst offsets relative to the cursor. The only source touch left is slicing the cursor segments own identifier-token text. Deletes splitQualifiedPrefix, pathFromSegments, and segmentAt; behavior preserved, two new tests pin the colon-without-dot and cursor-mid-name cases.

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Order the Position/Range/SemanticTokens type imports merged during the rebase against main (semantic tokens + completion landed in parallel).

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
The namespace-qualifier candidate now inserts the bare namespace name (e.g. `auth`) instead of `auth.`; label/insertText/filterText all use the bare name. Member completion still works once the user types the dot.

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 69d57542-6492-4ef8-aa62-8d5eecc2059f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lsp-document-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SevInf SevInf force-pushed the lsp-autocomplete branch from ee9c443 to 82b8f4e Compare July 3, 2026 09:29
Base automatically changed from lsp-autocomplete to main July 3, 2026 15:06
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.

1 participant