Skip to content

fix: hide generated template functions from document symbols - #3114

Open
colecrouter wants to merge 1 commit into
sveltejs:masterfrom
colecrouter:fix/snippet-document-symbols
Open

fix: hide generated template functions from document symbols#3114
colecrouter wants to merge 1 commit into
sveltejs:masterfrom
colecrouter:fix/snippet-document-symbols

Conversation

@colecrouter

Copy link
Copy Markdown
Contributor

Multi-line snippets currently generate garbage output. Detect generated anonymous functions by first checking if they are in a template & checking if they were written by the user, then skip those symbols.

Before:
image

After:
image

Tests cases include parametrized and non-parametrized snippets, as well as user-defined anonymous functions.

@changeset-bot

changeset-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dbb1a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-language-server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@colecrouter colecrouter changed the title fix: hide generated snippet document symbols fix: hide generated template functions from document symbols Aug 31, 2026
@colecrouter

colecrouter commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

I've since noticed this solves a second bug with comments inside templates:

image image

—though, this is also a TextMate grammar bug (and I'd interject that Prettier shouldn't be forcefully collapsing template brackets here in the first place). I will open a separate PR for that.

Edit: See #3115 & #3116.

// actually wrote.
if (
!isInScript(symbol.location.range.start, document) &&
!isInFunctionExpression(tsDoc.svelteNodeAt(symbol.location.range.start))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of finding the exact node, then walk up the AST tree. It'll be slightly more performant to walk down the AST until a function expression or a snippet block where the document symbol position is inside the start tag({#snippet ...})

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.

2 participants