Fix getTokensFromNode template scanning issue #1560
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
getTokensFromNode
function ininternal/ls/signaturehelp.go
was incorrectly tokenizing template expressions, producingNoSubstitutionTemplateLiteral
tokens that spanned across template boundaries instead of recognizing proper template structure.Issue
When scanning a template expression like:
The function would incorrectly produce a
NoSubstitutionTemplateLiteral
token from the closing backtick to the next token (e.g., ";"
instead of separate "`" and ";" tokens). This happened because the scanner wasn't aware of template context when starting from a specific position within a template expression.Root Cause
The scanner would interpret closing backticks as the beginning of new
NoSubstitutionTemplateLiteral
tokens rather thanTemplateTail
tokens, because it lacked the proper template context when initialized at arbitrary positions within template expressions.Solution
Added special handling for
TemplateExpression
nodes ingetTokensFromNode
:TemplateHead
→ expressions →TemplateMiddle
→ expressions →TemplateTail
Verification
The fix correctly tokenizes the example above as:
TemplateHead
: "Hello ${"
value
TemplateMiddle
:"} world ${"
value
TemplateTail
:"}!
"`All existing tests pass and signature help for tagged templates now works correctly.
Fixes #1554.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.