add emmet noise check (#146)

master
Brad Cornes 2020-12-10 17:22:06 +00:00
parent 84e3bf4b3a
commit 4b10581005
2 changed files with 37 additions and 5 deletions

View File

@ -12,6 +12,8 @@ import {
WorkspaceFolder, WorkspaceFolder,
Uri, Uri,
ConfigurationScope, ConfigurationScope,
commands,
SymbolInformation,
} from 'vscode' } from 'vscode'
import { import {
LanguageClient, LanguageClient,
@ -154,6 +156,7 @@ export function activate(context: ExtensionContext) {
let emitter = createEmitter(client) let emitter = createEmitter(client)
registerConfigErrorHandler(emitter) registerConfigErrorHandler(emitter)
registerColorDecorator(client, context, emitter) registerColorDecorator(client, context, emitter)
onMessage(client, 'getConfiguration', async (scope) => { onMessage(client, 'getConfiguration', async (scope) => {
return { return {
tabSize: tabSize:
@ -161,6 +164,15 @@ export function activate(context: ExtensionContext) {
...Workspace.getConfiguration('tailwindCSS', scope), ...Workspace.getConfiguration('tailwindCSS', scope),
} }
}) })
onMessage(client, 'getDocumentSymbols', async ({ uri }) => {
return {
symbols: await commands.executeCommand<SymbolInformation[]>(
'vscode.executeDocumentSymbolProvider',
Uri.parse(uri)
),
}
})
}) })
client.start() client.start()

View File

@ -767,11 +767,10 @@ async function provideEmmetCompletions(
let settings = await getDocumentSettings(state, document) let settings = await getDocumentSettings(state, document)
if (settings.emmetCompletions !== true) return null if (settings.emmetCompletions !== true) return null
const syntax = isHtmlContext(state, document, position) const isHtml = isHtmlContext(state, document, position)
? 'html' const isJs = !isHtml && isJsContext(state, document, position)
: isJsContext(state, document, position)
? 'jsx' const syntax = isHtml ? 'html' : isJs ? 'jsx' : null
: null
if (syntax === null) { if (syntax === null) {
return null return null
@ -801,6 +800,27 @@ async function provideEmmetCompletions(
return null return null
} }
if (isJs) {
const abbreviation: string = extractAbbreviationResults.abbreviation
if (abbreviation.startsWith('this.')) {
return null
}
const { symbols } = await state.emitter.emit('getDocumentSymbols', {
uri: document.uri,
})
if (
symbols &&
symbols.find(
(symbol) =>
abbreviation === symbol.name ||
(abbreviation.startsWith(symbol.name + '.') &&
!/>|\*|\+/.test(abbreviation))
)
) {
return null
}
}
const emmetItems = emmetHelper.doComplete(document, position, syntax, {}) const emmetItems = emmetHelper.doComplete(document, position, syntax, {})
if (!emmetItems || !emmetItems.items || emmetItems.items.length !== 1) { if (!emmetItems || !emmetItems.items || emmetItems.items.length !== 1) {