Skip to content

Commit 1417211

Browse files
Ignore comments when matching class attributes (#1202)
Fixes #1200
1 parent 0aa935b commit 1417211

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/tailwindcss-language-service/src/completionProvider.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { TextDocument } from 'vscode-languageserver-textdocument'
1313
import dlv from 'dlv'
1414
import removeMeta from './util/removeMeta'
1515
import { formatColor, getColor, getColorFromValue } from './util/color'
16-
import { isHtmlContext } from './util/html'
16+
import { isHtmlContext, isHtmlDoc, isVueDoc } from './util/html'
1717
import { isCssContext } from './util/css'
1818
import { findLast, matchClassAttributes } from './util/find'
1919
import { stringifyConfigValue, stringifyCss } from './util/stringify'
@@ -728,10 +728,20 @@ async function provideClassAttributeCompletions(
728728
position: Position,
729729
context?: CompletionContext,
730730
): Promise<CompletionList> {
731-
let str = document.getText({
731+
let range: Range = {
732732
start: document.positionAt(Math.max(0, document.offsetAt(position) - SEARCH_RANGE)),
733733
end: position,
734-
})
734+
}
735+
736+
let str: string
737+
738+
if (isJsDoc(state, document)) {
739+
str = getTextWithoutComments(document, 'js', range)
740+
} else if (isHtmlDoc(state, document)) {
741+
str = getTextWithoutComments(document, 'html', range)
742+
} else {
743+
str = document.getText(range)
744+
}
735745

736746
let settings = (await state.editor.getConfiguration(document.uri)).tailwindCSS
737747

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Prerelease
44

55
- Show light color swatch from light-dark() functions ([#1199](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1199))
6+
- Ignore comments when matching class attributes ([#1202](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1202))
67

78
## 0.14.4
89

0 commit comments

Comments
 (0)