Skip to content

fix(lsp): offer Run and Evaluate code lenses only on model files on disk - #1838

Merged
HuiJun merged 1 commit into
developfrom
fix/notebook-run-lenses
Nov 2, 2026
Merged

HuiJun merged 1 commit into
developfrom
fix/notebook-run-lenses

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Follow-up to #1833. The server offered Run/Evaluate code lenses on documents the VS Code runner cannot read: run() in editors/vscode/src/run.ts refuses any lens whose uri is not a file: URI ("… is not declared in a file on disk, so sysml cannot read it."), so on those documents every Run/Evaluate lens was a button that could only fail.

  • internal/frontend/lsp/codelens.go CodeLens: the runCommand lens is emitted only when params.TextDocument.URI has the file scheme (onDisk). Reference-count lenses are unchanged.
  • internal/frontend/lsp/notebook_requests.go cellRequest (textDocument/codeLens): drops lenses whose Command.Command == runElementCommand. The kernel runs a cell, so a cell gets only its reference-count lenses, which still resolve through codeLens/resolve in the cell's terms.
  • run.ts keeps its client-side check unchanged, as a defensive fallback.

Which guard removes the cell lenses. Guard 1 alone does not cover cells. cellRequest calls CodeLens with nameToURI(nb.name), which is uri.File(...) of the notebook's path, so it is always a file: URI. With only guard 1 applied, the new notebook test failed: the cell's answer still had Run Go / Evaluate Area lenses with "uri":"file:///…/model.ipynb". The runElementCommand filter in cellRequest is what removes them, so it is not redundant.

Which URIs reach CodeLens from VS Code. editors/vscode/src/selector.ts documentSelector registers {scheme: "file"}, {scheme: stdlibScheme} (library documents, which CodeLens already answers with nothing) and {notebook: "*"} cells. It does not include untitled, so from VS Code an untitled editor never reaches the server, and a cell's request reaches CodeLens through cellRequest with the notebook's file: URI. The scheme guard is still right for other LSP clients that send non-file URIs (untitled:, virtual file systems), and the new test locks it in with untitled:Untitled-1.

Docs: docs/reference/lsp.md (the codeLens-on-a-cell sentence), docs/guide/12-jupyter.md (what a cell has), docs/guide/08-editors.md (the running-an-element paragraph and the code-lens feature row) and editors/vscode/README.md (notebook cells, "Running an element from a code lens") now say that Run/Evaluate lenses are offered only for model files on disk, that the kernel runs a cell, and that reference-count lenses work in cells. Changelog: changes/unreleased/notebook-run-lenses.fixed.md.

How it was verified

New tests in internal/frontend/lsp:

  • TestNotebookCellLensesCountReferencesAndRunNothing (notebook_test.go): a cell with part def A, action def Go and calc def Area, plus a second cell using them. The cell's textDocument/codeLens answer has reference lenses on P::A, P::Go and P::Area and no opensysml.runElement lens, and codeLens/resolve on P::A gives 1 reference located in the second cell. It fails with guard 1 alone (see above).
  • TestCodeLensRunsOnlyFilesOnDisk (editor_facts_test.go): editorFactsModel opened as untitled:Untitled-1 gets reference lenses on Demo::Fall, Demo::Rover, Demo::Charge, Demo::Mission and Demo::Positive, and no command lens. With the guard forced off it fails (lens "Evaluate Fall" (opensysml.runElement) on a document not on disk, …).
  • The existing file-document tests (TestCodeLensOffersReferenceCountsAndRunCommands, TestCodeLensResolveCountsReferences, TestCodeLensTellsOverloadsApart, TestRunServesSignatureHelpCodeLensAndInlayHints) are unchanged and pass, so a file: document still gets Run/Evaluate.
$ go build ./...                      # ok
$ go vet ./...                        # ok
$ gofmt -l .                          # (empty)
$ go test ./internal/frontend/...     # all ok (lsp 26.2s, repl 73.7s, jupyter, mcp/*, stdiorpc, …)
$ go test -count=1 ./tests/hygiene/...
ok  	github.com/Open-MBEE/OpenSysML/tests/hygiene	14.185s
$ go test -race -count=3 -run 'TestCodeLens|TestNotebook' ./internal/frontend/lsp
ok  	github.com/Open-MBEE/OpenSysML/internal/frontend/lsp	2.323s
$ make lint                           ✓ Lint passed (staticcheck + gosec)
$ go run -C tools ./cmd/doc-counts -check
doc-counts: already current
$ python3 scripts/check-doc-links.py
0 broken link(s)

No TypeScript was touched, so the extension's npm test was not run.

Checklist

  • make lint passes locally; the touched packages' tests pass (go test ./internal/frontend/..., ./tests/hygiene/...); the full make test is left to CI
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md)
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (compliance rows need nothing: the census is counted at docs build). No gate count moved (doc-counts -check is current)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

The VS Code runner reads the element's file from disk and refuses any lens whose
URI is not a file: URI, so a Run or Evaluate lens anywhere else could only fail.
CodeLens now emits the run command only for a file: document, and a notebook
cell, answered from the notebook's own file: document, drops its run lenses
since the kernel runs a cell. Reference-count lenses are unchanged.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 2, 2026 06:50

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@HuiJun
HuiJun merged commit 2594376 into develop Nov 2, 2026
30 of 51 checks passed
@HuiJun
HuiJun deleted the fix/notebook-run-lenses branch November 2, 2026 13:10
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