增加scss支持

master
yutent 2023-03-03 17:17:11 +08:00
parent cec2620c5f
commit 2b1278bc74
7 changed files with 41 additions and 41 deletions

View File

@ -1,2 +1,18 @@
## string-html-css ## string-html-css
一个高亮js代码中的 html/css/scss/sass/less的字符串, 并支持emmet. 一个高亮js代码中的 html/css/scss/sass/less的字符串, 并支持emmet.
```js
const foo = css`
.foo { color: red }
`
const foo = scss`
.foo { color: red }
`
const foo = html`
<div>hello</div>
`
```

View File

@ -131,7 +131,8 @@ export class HTMLStyleCompletionItemProvider implements CompletionItemProvider {
export class CSSCompletionItemProvider implements CompletionItemProvider { export class CSSCompletionItemProvider implements CompletionItemProvider {
private _CSSLanguageService: CSSLanguageService = GetCSSLanguageService() 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() private _cache = new CompletionsCache()
public provideCompletionItems( public provideCompletionItems(

View File

@ -54,10 +54,7 @@ export function MatchOffset(
return null return null
} }
export function Match( export function Match(regex: RegExp, data: string): RegExpMatchArray {
regex: RegExp,
data: string
): RegExpMatchArray {
regex.exec(null) regex.exec(null)
let match: RegExpExecArray let match: RegExpExecArray
@ -115,9 +112,15 @@ export function TranslateHTMLTextEdits(
offset: number offset: number
): TextEdit[] { ): TextEdit[] {
return input.map((item: HTMLTextEdit) => { return input.map((item: HTMLTextEdit) => {
const startPosition = new Position(item.range.start.line + offset, item.range.start.character); const startPosition = new Position(
const endPosition = new Position(item.range.end.line + offset - 1, item.range.end.character); item.range.start.line + offset,
const itemRange = new Range(startPosition, endPosition); 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) return new TextEdit(itemRange, item.newText)
}) })
} }

View File

@ -1,15 +1,10 @@
{ {
"fileTypes": [ "fileTypes": ["js", "jsx", "ts", "tsx"],
"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", "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string",
"patterns": [ "patterns": [
{ {
"contentName": "meta.embedded.block.css", "contentName": "meta.embedded.block.css",
"begin": "(?x)(\\s*?(\\w+\\.)?(?:css|\/\\*\\s*css\\s*\\*\/)\\s*)(`)", "begin": "(?x)(\\s*?(\\w+\\.)?(?:css|/\\*\\s*css\\s*\\*/)\\s*)(`)",
"beginCaptures": { "beginCaptures": {
"0": { "0": {
"name": "string.template.ts, punctuation.definition.string.template.begin.ts" "name": "string.template.ts, punctuation.definition.string.template.begin.ts"

View File

@ -1,10 +1,5 @@
{ {
"fileTypes": [ "fileTypes": ["js", "jsx", "ts", "tsx"],
"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", "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string",
"injections": { "injections": {
"L:source": { "L:source": {
@ -19,7 +14,7 @@
"patterns": [ "patterns": [
{ {
"contentName": "meta.embedded.block.html", "contentName": "meta.embedded.block.html",
"begin": "(?x)(\\s*?(\\w+\\.)?(?:html|\/\\*\\s*html\\s*\\*\/)\\s*)(`)", "begin": "(?x)(\\s*?(\\w+\\.)?(?:html|/\\*\\s*html\\s*\\*/)\\s*)(`)",
"beginCaptures": { "beginCaptures": {
"0": { "0": {
"name": "string.template.ts, punctuation.definition.string.template.begin.ts" "name": "string.template.ts, punctuation.definition.string.template.begin.ts"

View File

@ -1,15 +1,10 @@
{ {
"fileTypes": [ "fileTypes": ["js", "jsx", "ts", "tsx"],
"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", "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string",
"patterns": [ "patterns": [
{ {
"contentName": "meta.embedded.block.css", "contentName": "meta.embedded.block.css",
"begin": "(?x)(\\s*?(\\w+\\.)?(?:\/\\*\\s*less\\s*\\*\/)\\s*)(`)", "begin": "(?x)(\\s*?(\\w+\\.)?(?:less|/\\*\\s*less\\s*\\*/)\\s*)(`)",
"beginCaptures": { "beginCaptures": {
"0": { "0": {
"name": "string.template.ts, punctuation.definition.string.template.begin.ts" "name": "string.template.ts, punctuation.definition.string.template.begin.ts"

View File

@ -1,15 +1,10 @@
{ {
"fileTypes": [ "fileTypes": ["js", "jsx", "ts", "tsx"],
"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", "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string",
"patterns": [ "patterns": [
{ {
"contentName": "meta.embedded.block.css", "contentName": "meta.embedded.block.css",
"begin": "(?x)(\\s*?(\\w+\\.)?(?:\/\\*\\s*scss\\s*\\*\/)\\s*)(`)", "begin": "(?x)(\\s*?(\\w+\\.)?(?:scss|/\\*\\s*scss\\s*\\*/)\\s*)(`)",
"beginCaptures": { "beginCaptures": {
"0": { "0": {
"name": "string.template.ts, punctuation.definition.string.template.begin.ts" "name": "string.template.ts, punctuation.definition.string.template.begin.ts"