diff options
author | 2021-08-26 13:14:47 -0400 | |
---|---|---|
committer | 2021-08-26 13:14:47 -0400 | |
commit | c4cfc0d5fb26e39be7c10ba1ecdc32656870b10d (patch) | |
tree | e8dde32fb8ef88f6b9bd6276e5ca9194fb487ba9 /tools/language-server/src/plugins/css/features/getIdClassCompletion.ts | |
parent | c83d4817336f73348dbcedf493f2e5d2402e9e49 (diff) | |
download | astro-c4cfc0d5fb26e39be7c10ba1ecdc32656870b10d.tar.gz astro-c4cfc0d5fb26e39be7c10ba1ecdc32656870b10d.tar.zst astro-c4cfc0d5fb26e39be7c10ba1ecdc32656870b10d.zip |
Remove VSCode and Langauge Server from this monorepo (#1230)
* Remove VSCode and Langauge Server from this monorepo
* Adds back in the syntax files
Diffstat (limited to 'tools/language-server/src/plugins/css/features/getIdClassCompletion.ts')
-rw-r--r-- | tools/language-server/src/plugins/css/features/getIdClassCompletion.ts | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/tools/language-server/src/plugins/css/features/getIdClassCompletion.ts b/tools/language-server/src/plugins/css/features/getIdClassCompletion.ts deleted file mode 100644 index 45acb5ad6..000000000 --- a/tools/language-server/src/plugins/css/features/getIdClassCompletion.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { CompletionItem, CompletionItemKind, CompletionList } from 'vscode-languageserver'; -import { AttributeContext } from '../../../core/documents/parseHtml'; -import { CSSDocument } from '../CSSDocument'; - -export function getIdClassCompletion(cssDoc: CSSDocument, attributeContext: AttributeContext): CompletionList | null { - const collectingType = getCollectingType(attributeContext); - - if (!collectingType) { - return null; - } - const items = collectSelectors(cssDoc.stylesheet as CSSNode, collectingType); - - console.log('getIdClassCompletion items', items.length); - return CompletionList.create(items); -} - -function getCollectingType(attributeContext: AttributeContext): number | undefined { - if (attributeContext.inValue) { - if (attributeContext.name === 'class') { - return NodeType.ClassSelector; - } - if (attributeContext.name === 'id') { - return NodeType.IdentifierSelector; - } - } else if (attributeContext.name.startsWith('class:')) { - return NodeType.ClassSelector; - } -} - -/** - * incomplete see - * https://github.com/microsoft/vscode-css-languageservice/blob/master/src/parser/cssNodes.ts#L14 - * The enum is not exported. we have to update this whenever it changes - */ -export enum NodeType { - ClassSelector = 14, - IdentifierSelector = 15, -} - -export type CSSNode = { - type: number; - children: CSSNode[] | undefined; - getText(): string; -}; - -export function collectSelectors(stylesheet: CSSNode, type: number) { - const result: CSSNode[] = []; - walk(stylesheet, (node) => { - if (node.type === type) { - result.push(node); - } - }); - - return result.map( - (node): CompletionItem => ({ - label: node.getText().substring(1), - kind: CompletionItemKind.Keyword, - }) - ); -} - -function walk(node: CSSNode, callback: (node: CSSNode) => void) { - callback(node); - if (node.children) { - node.children.forEach((node) => walk(node, callback)); - } -} |