Skip to content

Commit

Permalink
get rid of css parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Dec 28, 2023
1 parent 1488205 commit b3cb46a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 49 deletions.
33 changes: 2 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-html-css",
"displayName": "HTML CSS Support",
"description": "CSS Intellisense for HTML",
"version": "1.14.1",
"version": "1.14.2",
"license": "MIT",
"publisher": "ecmel",
"author": {
Expand Down Expand Up @@ -103,7 +103,6 @@
"@vscode/test-electron": "^2.3.8",
"@vscode/vsce": "^2.22.0",
"c8": "^8.0.1",
"css-tree": "^2.3.1",
"fast-glob": "^3.3.2",
"mocha": "^10.2.0",
"prettier": "^3.1.1",
Expand Down
25 changes: 9 additions & 16 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License
*/

import { parse, walk } from "css-tree";
import { glob } from "fast-glob";
import { basename, dirname, extname, isAbsolute, join } from "path";
import {
Expand Down Expand Up @@ -80,24 +79,18 @@ export class SelectorCompletionItemProvider
}

parseTextToItems(path: string, text: string, items: CompletionItem[]) {
walk(parse(text), (node) => {
let kind: CompletionItemKind;

switch (node.type) {
case "ClassSelector":
kind = CompletionItemKind.Enum;
break;
case "IdSelector":
kind = CompletionItemKind.Value;
break;
default:
return;
}
const regex = /([.#])(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)\s*{([^}]*)}/g;

let match;

while ((match = regex.exec(text))) {
items.push(
new CompletionItem({ label: node.name, description: path }, kind),
new CompletionItem(
{ label: match[2], description: path },
match[1] === "." ? CompletionItemKind.Enum : CompletionItemKind.Value,
),
);
});
}
}

async fetchLocal(path: string): Promise<void> {
Expand Down

0 comments on commit b3cb46a

Please sign in to comment.