tailwind-ctp-intellisense/src/lsp/util/css.ts

33 lines
651 B
TypeScript
Raw Normal View History

2020-04-11 22:34:03 +00:00
import { TextDocument, Position } from 'vscode-languageserver'
2020-04-16 21:39:16 +00:00
import { isInsideTag, isVueDoc, isSvelteDoc } from './html'
2020-04-11 21:20:45 +00:00
export const CSS_LANGUAGES = [
'css',
'less',
'postcss',
'sass',
'scss',
'stylus',
]
2020-04-11 22:34:03 +00:00
function isCssDoc(doc: TextDocument): boolean {
2020-04-11 21:20:45 +00:00
return CSS_LANGUAGES.indexOf(doc.languageId) !== -1
}
2020-04-11 22:34:03 +00:00
export function isCssContext(doc: TextDocument, position: Position): boolean {
if (isCssDoc(doc)) {
return true
}
2020-04-16 21:39:16 +00:00
if (isVueDoc(doc) || isSvelteDoc(doc)) {
2020-04-11 22:34:03 +00:00
let str = doc.getText({
start: { line: 0, character: 0 },
end: position,
})
return isInsideTag(str, ['style'])
}
return false
}