Skip to content

Commit

Permalink
fix: shouldn't show completion in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
voorjaar committed May 19, 2021
1 parent 6dc24e9 commit ea30e03
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/lib/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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|... = "..."
Expand Down
7 changes: 5 additions & 2 deletions src/utils/filetypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions src/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ export class HTMLParser {
this.html = html;
}

removeComments() {
if (!this.html) return [];
const regex = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*|<!--[\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[] = [];
Expand Down

0 comments on commit ea30e03

Please sign in to comment.