Skip to content

Commit 4b10581

Browse files
committed
add emmet noise check (#146)
1 parent 84e3bf4 commit 4b10581

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

packages/tailwindcss-intellisense/src/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
WorkspaceFolder,
1313
Uri,
1414
ConfigurationScope,
15+
commands,
16+
SymbolInformation,
1517
} from 'vscode'
1618
import {
1719
LanguageClient,
@@ -154,13 +156,23 @@ export function activate(context: ExtensionContext) {
154156
let emitter = createEmitter(client)
155157
registerConfigErrorHandler(emitter)
156158
registerColorDecorator(client, context, emitter)
159+
157160
onMessage(client, 'getConfiguration', async (scope) => {
158161
return {
159162
tabSize:
160163
Workspace.getConfiguration('editor', scope).get('tabSize') || 2,
161164
...Workspace.getConfiguration('tailwindCSS', scope),
162165
}
163166
})
167+
168+
onMessage(client, 'getDocumentSymbols', async ({ uri }) => {
169+
return {
170+
symbols: await commands.executeCommand<SymbolInformation[]>(
171+
'vscode.executeDocumentSymbolProvider',
172+
Uri.parse(uri)
173+
),
174+
}
175+
})
164176
})
165177

166178
client.start()

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,10 @@ async function provideEmmetCompletions(
767767
let settings = await getDocumentSettings(state, document)
768768
if (settings.emmetCompletions !== true) return null
769769

770-
const syntax = isHtmlContext(state, document, position)
771-
? 'html'
772-
: isJsContext(state, document, position)
773-
? 'jsx'
774-
: null
770+
const isHtml = isHtmlContext(state, document, position)
771+
const isJs = !isHtml && isJsContext(state, document, position)
772+
773+
const syntax = isHtml ? 'html' : isJs ? 'jsx' : null
775774

776775
if (syntax === null) {
777776
return null
@@ -801,6 +800,27 @@ async function provideEmmetCompletions(
801800
return null
802801
}
803802

803+
if (isJs) {
804+
const abbreviation: string = extractAbbreviationResults.abbreviation
805+
if (abbreviation.startsWith('this.')) {
806+
return null
807+
}
808+
const { symbols } = await state.emitter.emit('getDocumentSymbols', {
809+
uri: document.uri,
810+
})
811+
if (
812+
symbols &&
813+
symbols.find(
814+
(symbol) =>
815+
abbreviation === symbol.name ||
816+
(abbreviation.startsWith(symbol.name + '.') &&
817+
!/>|\*|\+/.test(abbreviation))
818+
)
819+
) {
820+
return null
821+
}
822+
}
823+
804824
const emmetItems = emmetHelper.doComplete(document, position, syntax, {})
805825

806826
if (!emmetItems || !emmetItems.items || emmetItems.items.length !== 1) {

0 commit comments

Comments
 (0)