From 2b1278bc743d3fd6fb3a97965f618acabf31ada5 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 3 Mar 2023 17:17:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0scss=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +++++++++++++++++- src/providers/css.ts | 3 ++- src/util.ts | 17 ++++++++++------- syntaxes/es6.inline.css.json | 11 +++-------- syntaxes/es6.inline.html.json | 11 +++-------- syntaxes/es6.inline.less.json | 11 +++-------- syntaxes/es6.inline.scss.json | 11 +++-------- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 95f6381..9e92606 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ ## string-html-css -一个高亮js代码中的 html/css/scss/sass/less的字符串, 并支持emmet. \ No newline at end of file +一个高亮js代码中的 html/css/scss/sass/less的字符串, 并支持emmet. + +```js + +const foo = css` + .foo { color: red } +` + +const foo = scss` + .foo { color: red } +` + +const foo = html` +
hello
+` + +``` \ No newline at end of file diff --git a/src/providers/css.ts b/src/providers/css.ts index f1b329e..c8395f6 100644 --- a/src/providers/css.ts +++ b/src/providers/css.ts @@ -131,7 +131,8 @@ export class HTMLStyleCompletionItemProvider implements CompletionItemProvider { export class CSSCompletionItemProvider implements CompletionItemProvider { private _CSSLanguageService: CSSLanguageService = GetCSSLanguageService() - private _expression = /(\/\*\s*(css|less|scss)\s*\*\/\s*`|css\s*`)([^`]*)(`)/g + private _expression = + /(\/\*\s*(css|less|scss|sass)\s*\*\/\s*`|(scss|sass|less|css)\s*`)([^`]*)(`)/g private _cache = new CompletionsCache() public provideCompletionItems( diff --git a/src/util.ts b/src/util.ts index 109cfc6..044ef7c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -54,10 +54,7 @@ export function MatchOffset( return null } -export function Match( - regex: RegExp, - data: string -): RegExpMatchArray { +export function Match(regex: RegExp, data: string): RegExpMatchArray { regex.exec(null) let match: RegExpExecArray @@ -115,9 +112,15 @@ export function TranslateHTMLTextEdits( offset: number ): TextEdit[] { return input.map((item: HTMLTextEdit) => { - const startPosition = new Position(item.range.start.line + offset, item.range.start.character); - const endPosition = new Position(item.range.end.line + offset - 1, item.range.end.character); - const itemRange = new Range(startPosition, endPosition); + const startPosition = new Position( + item.range.start.line + offset, + item.range.start.character + ) + const endPosition = new Position( + item.range.end.line + offset - 1, + item.range.end.character + ) + const itemRange = new Range(startPosition, endPosition) return new TextEdit(itemRange, item.newText) }) } diff --git a/syntaxes/es6.inline.css.json b/syntaxes/es6.inline.css.json index cc936b6..af2f3a0 100644 --- a/syntaxes/es6.inline.css.json +++ b/syntaxes/es6.inline.css.json @@ -1,15 +1,10 @@ { - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], + "fileTypes": ["js", "jsx", "ts", "tsx"], "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string", "patterns": [ { "contentName": "meta.embedded.block.css", - "begin": "(?x)(\\s*?(\\w+\\.)?(?:css|\/\\*\\s*css\\s*\\*\/)\\s*)(`)", + "begin": "(?x)(\\s*?(\\w+\\.)?(?:css|/\\*\\s*css\\s*\\*/)\\s*)(`)", "beginCaptures": { "0": { "name": "string.template.ts, punctuation.definition.string.template.begin.ts" @@ -38,4 +33,4 @@ } ], "scopeName": "es6.inline.css" -} \ No newline at end of file +} diff --git a/syntaxes/es6.inline.html.json b/syntaxes/es6.inline.html.json index 32a8ff0..66b6fe9 100644 --- a/syntaxes/es6.inline.html.json +++ b/syntaxes/es6.inline.html.json @@ -1,10 +1,5 @@ { - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], + "fileTypes": ["js", "jsx", "ts", "tsx"], "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string", "injections": { "L:source": { @@ -19,7 +14,7 @@ "patterns": [ { "contentName": "meta.embedded.block.html", - "begin": "(?x)(\\s*?(\\w+\\.)?(?:html|\/\\*\\s*html\\s*\\*\/)\\s*)(`)", + "begin": "(?x)(\\s*?(\\w+\\.)?(?:html|/\\*\\s*html\\s*\\*/)\\s*)(`)", "beginCaptures": { "0": { "name": "string.template.ts, punctuation.definition.string.template.begin.ts" @@ -48,4 +43,4 @@ } ], "scopeName": "es6.inline.html" -} \ No newline at end of file +} diff --git a/syntaxes/es6.inline.less.json b/syntaxes/es6.inline.less.json index 8c41997..d06d604 100644 --- a/syntaxes/es6.inline.less.json +++ b/syntaxes/es6.inline.less.json @@ -1,15 +1,10 @@ { - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], + "fileTypes": ["js", "jsx", "ts", "tsx"], "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string", "patterns": [ { "contentName": "meta.embedded.block.css", - "begin": "(?x)(\\s*?(\\w+\\.)?(?:\/\\*\\s*less\\s*\\*\/)\\s*)(`)", + "begin": "(?x)(\\s*?(\\w+\\.)?(?:less|/\\*\\s*less\\s*\\*/)\\s*)(`)", "beginCaptures": { "0": { "name": "string.template.ts, punctuation.definition.string.template.begin.ts" @@ -38,4 +33,4 @@ } ], "scopeName": "es6.inline.less" -} \ No newline at end of file +} diff --git a/syntaxes/es6.inline.scss.json b/syntaxes/es6.inline.scss.json index 55591da..72fdc54 100644 --- a/syntaxes/es6.inline.scss.json +++ b/syntaxes/es6.inline.scss.json @@ -1,15 +1,10 @@ { - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], + "fileTypes": ["js", "jsx", "ts", "tsx"], "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string", "patterns": [ { "contentName": "meta.embedded.block.css", - "begin": "(?x)(\\s*?(\\w+\\.)?(?:\/\\*\\s*scss\\s*\\*\/)\\s*)(`)", + "begin": "(?x)(\\s*?(\\w+\\.)?(?:scss|/\\*\\s*scss\\s*\\*/)\\s*)(`)", "beginCaptures": { "0": { "name": "string.template.ts, punctuation.definition.string.template.begin.ts" @@ -38,4 +33,4 @@ } ], "scopeName": "es6.inline.scss" -} \ No newline at end of file +}