fix completions and hovers inside `<style>` (fixes #334)

master
Brad Cornes 2021-05-20 16:50:10 +01:00
parent b8dc88d699
commit b7bf51f156
2 changed files with 11 additions and 22 deletions

View File

@ -476,14 +476,14 @@ function provideClassNameCompletions(
position: Position, position: Position,
context?: CompletionContext context?: CompletionContext
): CompletionList { ): CompletionList {
if (isHtmlContext(state, document, position) || isJsContext(state, document, position)) {
return provideClassAttributeCompletions(state, document, position, context)
}
if (isCssContext(state, document, position)) { if (isCssContext(state, document, position)) {
return provideAtApplyCompletions(state, document, position) return provideAtApplyCompletions(state, document, position)
} }
if (isHtmlContext(state, document, position) || isJsContext(state, document, position)) {
return provideClassAttributeCompletions(state, document, position, context)
}
return null return null
} }

View File

@ -1,35 +1,24 @@
import type { TextDocument, Position } from 'vscode-languageserver' import type { TextDocument, Position } from 'vscode-languageserver'
import { isInsideTag, isVueDoc, isSvelteDoc, isHtmlDoc } from './html' import { isInsideTag, isVueDoc, isSvelteDoc, isHtmlDoc } from './html'
import { isJsDoc } from './js'
import { State } from './state' import { State } from './state'
export const CSS_LANGUAGES = [ export const CSS_LANGUAGES = ['css', 'less', 'postcss', 'sass', 'scss', 'stylus', 'sugarss']
'css',
'less',
'postcss',
'sass',
'scss',
'stylus',
'sugarss',
]
export function isCssDoc(state: State, doc: TextDocument): boolean { export function isCssDoc(state: State, doc: TextDocument): boolean {
const userCssLanguages = Object.keys( const userCssLanguages = Object.keys(state.editor.userLanguages).filter((lang) =>
state.editor.userLanguages CSS_LANGUAGES.includes(state.editor.userLanguages[lang])
).filter((lang) => CSS_LANGUAGES.includes(state.editor.userLanguages[lang])) )
return [...CSS_LANGUAGES, ...userCssLanguages].indexOf(doc.languageId) !== -1 return [...CSS_LANGUAGES, ...userCssLanguages].indexOf(doc.languageId) !== -1
} }
export function isCssContext( export function isCssContext(state: State, doc: TextDocument, position: Position): boolean {
state: State,
doc: TextDocument,
position: Position
): boolean {
if (isCssDoc(state, doc)) { if (isCssDoc(state, doc)) {
return true return true
} }
if (isHtmlDoc(state, doc) || isVueDoc(doc) || isSvelteDoc(doc)) { if (isHtmlDoc(state, doc) || isVueDoc(doc) || isSvelteDoc(doc) || isJsDoc(state, doc)) {
let str = doc.getText({ let str = doc.getText({
start: { line: 0, character: 0 }, start: { line: 0, character: 0 },
end: position, end: position,