Skip to content

fix(emmet): pass syntax hint to extractAbbreviation in expandEmmetAbbreviation#309181

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/emmet-class-expansion-mapped-languages
Open

fix(emmet): pass syntax hint to extractAbbreviation in expandEmmetAbbreviation#309181
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/emmet-class-expansion-mapped-languages

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Upstream fix for #233969

Problem

When a language is mapped to HTML via emmet.includeLanguages (e.g. "erb": "html"), typing a class abbreviation like .foo and pressing Tab fails to expand it. The abbreviation extractor picks up an empty or incorrect range because it does not know whether to apply stylesheet or markup extraction rules.

Root Cause

expandEmmetAbbreviation calls helper.extractAbbreviation(...) without the syntax option, so the helper defaults to markup mode for all documents — including stylesheet languages — and vice versa. Compare with defaultCompletionProvider.ts which already passes the correct syntax value:

// defaultCompletionProvider.ts (correct)
helper.extractAbbreviation(doc, pos, { lookAhead: false, syntax: isStyleSheet(syntax) ? 'stylesheet' : 'markup' });

Fix

Add the same syntax option to the extractAbbreviation call inside expandEmmetAbbreviation:

// Before
const extractedResults = helper.extractAbbreviation(
    toLSTextDocument(editor.document), position, { lookAhead: false });

// After  
const extractedResults = helper.extractAbbreviation(
    toLSTextDocument(editor.document), position,
    { lookAhead: false, syntax: isStyleSheet(syntax) ? 'stylesheet' : 'markup' });

This is a one-line change that aligns expandEmmetAbbreviation with the existing behaviour in defaultCompletionProvider.ts.

…breviation expansion

When expanding Emmet abbreviations via Tab in languages mapped to HTML
(e.g. ERB mapped to HTML via emmet.includeLanguages), dot-class shortcuts
like `.something` were expanded to `.<div class="something"></div>` instead
of `<div class="something"></div>`.

The root cause was that extractAbbreviation() was called without a `syntax`
option, causing the helper to use default extraction behavior that does not
include the leading `.` in the abbreviation range. The completion provider
already passes `syntax: 'markup'` or `syntax: 'stylesheet'` correctly; this
change aligns the Tab expansion path with the same approach.

Fixes microsoft#233969
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