From ea30e03469279005ae41e0ab698acec7d45cebb7 Mon Sep 17 00:00:00 2001 From: voorjaar Date: Thu, 20 May 2021 03:07:38 +0800 Subject: [PATCH] fix: shouldn't show completion in comments --- package-lock.json | 16 ++++++++-------- package.json | 2 +- src/lib/completions.ts | 2 +- src/utils/filetypes.ts | 7 +++++-- src/utils/parser.ts | 11 +++++++++++ 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index c5d7504..859855d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "requires": true, "packages": { "": { - "version": "0.16.1", + "version": "0.16.6", "license": "MIT", "devDependencies": { "@rollup/plugin-commonjs": "19.0.0", @@ -32,7 +32,7 @@ "ts-jest": "26.5.6", "tslib": "2.2.0", "typescript": "4.2.4", - "windicss": "3.0.8", + "windicss": "3.0.9", "windicss-analysis": "0.2.0" }, "engines": { @@ -8546,9 +8546,9 @@ "dev": true }, "node_modules/windicss": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/windicss/-/windicss-3.0.8.tgz", - "integrity": "sha512-Bae9xH1HIggOnxV0OtMs3qK8s8QT4fgLZvFxZMUqgvMdAPk6nohZIUCFIiRN0+9CrAj2XrCLvNUf67rU7dGGcg==", + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/windicss/-/windicss-3.0.9.tgz", + "integrity": "sha512-pv/SnYPfqYwz25672irDzNZpcEK/QlN9Dlhe2KUQXDjqd46wl/zLAi51BNB0pdfDZDbNjyvI1XgDXHk1oFF51A==", "dev": true, "bin": { "windicss": "cli/index.js" @@ -15441,9 +15441,9 @@ "dev": true }, "windicss": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/windicss/-/windicss-3.0.8.tgz", - "integrity": "sha512-Bae9xH1HIggOnxV0OtMs3qK8s8QT4fgLZvFxZMUqgvMdAPk6nohZIUCFIiRN0+9CrAj2XrCLvNUf67rU7dGGcg==", + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/windicss/-/windicss-3.0.9.tgz", + "integrity": "sha512-pv/SnYPfqYwz25672irDzNZpcEK/QlN9Dlhe2KUQXDjqd46wl/zLAi51BNB0pdfDZDbNjyvI1XgDXHk1oFF51A==", "dev": true }, "windicss-analysis": { diff --git a/package.json b/package.json index 4b3dada..65da36f 100644 --- a/package.json +++ b/package.json @@ -275,7 +275,7 @@ "ts-jest": "26.5.6", "tslib": "2.2.0", "typescript": "4.2.4", - "windicss": "3.0.8", + "windicss": "3.0.9", "windicss-analysis": "0.2.0" } } diff --git a/src/lib/completions.ts b/src/lib/completions.ts index ae5da7e..3adf4e8 100644 --- a/src/lib/completions.ts +++ b/src/lib/completions.ts @@ -343,7 +343,7 @@ export function registerCompletions(ctx: ExtensionContext, core: Core): Disposab // try one time update instead of line const documentText = document.getText(); const parser = new HTMLParser(documentText); - + parser.removeComments(); for (const attr of parser.parseAttrs()) { if (isAttrUtility(attr.key)) { // insert decoration in bg|text|... = "..." diff --git a/src/utils/filetypes.ts b/src/utils/filetypes.ts index eedaa10..ffd7896 100644 --- a/src/utils/filetypes.ts +++ b/src/utils/filetypes.ts @@ -36,11 +36,14 @@ export const fileTypes: {[key:string]: {pattern?: RegExp, type: string}} = { 'css': { type: 'css', }, + 'scss': { + type: 'css', + }, 'sass': { - type: 'sass', + type: 'css', }, 'less': { - type: 'less', + type: 'css', }, 'javascript': { type: 'js', diff --git a/src/utils/parser.ts b/src/utils/parser.ts index 6629561..97a971a 100644 --- a/src/utils/parser.ts +++ b/src/utils/parser.ts @@ -8,6 +8,17 @@ export class HTMLParser { this.html = html; } + removeComments() { + if (!this.html) return []; + const regex = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*|$/igm; + let match; + while ((match = regex.exec(this.html as string))) { + if (match) { + this.html = (this.html as string).slice(0, match.index) + ' '.repeat(regex.lastIndex - match.index) + this.html.slice(regex.lastIndex); + } + } + } + parseAttrs(): Attr[] { if (!this.html) return []; const output: Attr[] = [];