Skip to content

Add code symbols into outline#972

Merged
juliasilge merged 9 commits into
mainfrom
feat/code-cell-symbols
May 30, 2026
Merged

Add code symbols into outline#972
juliasilge merged 9 commits into
mainfrom
feat/code-cell-symbols

Conversation

@vezwork
Copy link
Copy Markdown
Member

@vezwork vezwork commented May 6, 2026

Addresses an issue mentioned by @juliasilge: #167 (comment)

Screenshot 2026-05-06 at 4 04 39 PM

Adds code symbols under code cells in the outline.

@vezwork vezwork requested a review from juliasilge May 6, 2026 20:06
@posit-snyk-bot
Copy link
Copy Markdown
Contributor

posit-snyk-bot commented May 6, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 6, 2026

I attempted to add tests until I remembered that our test setup does not have actual LSPs for Python or R in it, so we can't really test this. Well... now that I write that, I realize I could probably mock one out. That seems a little contrived, but maybe still worth it.

@juliasilge
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

I seem to be getting two of everything, at least in Positron:

Image

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 19, 2026

I was able to reproduce duplicated language symbols in code cells in Positron with inline outputs enabled. Looking into what is happening.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 19, 2026

@juliasilge In qmds in Positron with Positron › Quarto › Inline Output: Enabled enabled, the following command (from getCodeCellSymbols in this PR) is returning duplicated symbols:

await commands.executeCommand<DocumentSymbol[] | SymbolInformation[]>(
  "vscode.executeDocumentSymbolProvider",
  uri
);

I checked the surrounding context, including the vdoc content. Everything seems to be in order, nothing strange otherwise. When I disabled Positron › Quarto › Inline Output: Enabled and re-open the document, I no longer experience the duplicated symbols issue. It appears to me that the "vscode.executeDocumentSymbolProvider" command does not function as expected when inline outputs are enabled.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 19, 2026

@seeM mocked out fake LSPs in #980. Maybe I can copy that approach for tests in this PR.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 21, 2026

Cell Diagnostics tests were failing with a message about timing out in CI. The current run of the tests passed, but there wasn't a code change that would've affected the tests or the code tested. The tests seem to be flakey for some reason. Let's keep our eye on that.

Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

I looked into the issue with inline output and it is some change we'll need to make over on the Positron side; I'll log that once this is merged.

I do think we need to add at least some basic tests, with a fake in-process symbol provider (not a real LSP). We already do this for the formatting tests. I think the steps would be:

  1. Register a temporary provider in symbols.test.ts with vscode.languages.registerDocumentSymbolProvider({ scheme: "file", pattern: "**/.vdoc.*" }, ...) so it only handles Quarto virtual docs.
  2. Make that provider return each shape in separate tests:
    • DocumentSymbol[]
    • SymbolInformation[]
    • undefined
  3. Run vscode.executeDocumentSymbolProvider on format/basics.qmd or another example file and assert:
    • no throw for undefined
    • code-cell symbols still exist
    • returned embedded symbol names appear under/alongside code-cell outline entries for both result shapes.

That will give us coverage of the middleware logic without having to set up real LSPs.

Comment thread apps/vscode/src/lsp/client.ts Outdated
Comment thread apps/vscode/src/lsp/client.ts Outdated
@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 22, 2026

Ok I added tests but frustratingly was not able to get them to work when run in sequence, only in isolation. Doubly confusing is that mocking a SymbolInformation provider somehow results in duplicated results in the outline in the test, but idk why. Couldn't figure it out today :|

@juliasilge
Copy link
Copy Markdown
Collaborator

In a0506c9 I made some changes to how we run this new testing. The SymbolInformation[] test was skipped because it failed when run after other tests but passed in isolation, and showed duplicated symbols. The cause was not provider.dispose() actually in the end. What I believe it was instead is that vscode.executeDocumentSymbolProvider caches results per document URI (VS Code's OutlineModel cache). Because every test opened the same format/basics.qmd, a stale cached symbol tree from a previous test (or another suite that opened the same file) was served instead of re-invoking the middleware. That leaked the previous test's symbols, dropped the current test's, and surfaced duplicates.

I added a new helper function to address this in test-utils, which opens a unique on-disk copy of an example file so each test gets a fresh URI and the provider actually runs. I only set it up to be used in the new code cell symbol tests but this likely will be useful for other LSP features that work like this with caching.

@juliasilge
Copy link
Copy Markdown
Collaborator

I opened posit-dev/positron#13907 to fix the duplicated symbols with inline output.

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.

3 participants