From 8ada472afd7307c3a7818e4c11d738ab97531344 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Mon, 12 Aug 2024 02:20:05 +0800 Subject: [PATCH 1/5] fix: optimize matching of scoped class --- packages/language-core/lib/utils/parseCssClassNames.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-core/lib/utils/parseCssClassNames.ts b/packages/language-core/lib/utils/parseCssClassNames.ts index cdd39a7179..e70618729c 100644 --- a/packages/language-core/lib/utils/parseCssClassNames.ts +++ b/packages/language-core/lib/utils/parseCssClassNames.ts @@ -1,6 +1,6 @@ import { clearComments } from './parseCssVars'; -const cssClassNameReg = /(?=([\.]{1}[a-zA-Z_]+[\w\_\-]*)[\s\.\,\+\{\>#\:]{1})/g; +const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#[{])/gi; export function* parseCssClassNames(styleContent: string) { styleContent = clearComments(styleContent); From cb9e020b25f336799bb9f4ec679fe8921b429111 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 13 Aug 2024 11:31:46 +0800 Subject: [PATCH 2/5] fix: optimize matching of `v-bind()` --- .../language-core/lib/utils/parseCssClassNames.ts | 8 +++----- packages/language-core/lib/utils/parseCssVars.ts | 12 +++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/language-core/lib/utils/parseCssClassNames.ts b/packages/language-core/lib/utils/parseCssClassNames.ts index e70618729c..b8f63168ba 100644 --- a/packages/language-core/lib/utils/parseCssClassNames.ts +++ b/packages/language-core/lib/utils/parseCssClassNames.ts @@ -6,11 +6,9 @@ export function* parseCssClassNames(styleContent: string) { styleContent = clearComments(styleContent); const matches = styleContent.matchAll(cssClassNameReg); for (const match of matches) { - if (match.index !== undefined) { - const matchText = match[1]; - if (matchText !== undefined) { - yield { offset: match.index, text: matchText }; - } + const matchText = match[1]; + if (matchText) { + yield { offset: match.index, text: matchText }; } } } diff --git a/packages/language-core/lib/utils/parseCssVars.ts b/packages/language-core/lib/utils/parseCssVars.ts index 305a02eaec..4d83fc29e4 100644 --- a/packages/language-core/lib/utils/parseCssVars.ts +++ b/packages/language-core/lib/utils/parseCssVars.ts @@ -1,6 +1,6 @@ // https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61 -const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g; +const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w+))\s*\)/gi; const commentReg1 = /\/\*([\s\S]*?)\*\//g; const commentReg2 = /\/\/([\s\S]*?)\n/g; @@ -8,12 +8,10 @@ export function* parseCssVars(styleContent: string) { styleContent = clearComments(styleContent); const matchs = styleContent.matchAll(vBindCssVarReg); for (const match of matchs) { - if (match.index !== undefined) { - const matchText = match[1] ?? match[2] ?? match[3]; - if (matchText !== undefined) { - const offset = match.index + styleContent.slice(match.index).indexOf(matchText); - yield { offset, text: matchText }; - } + const matchText = match.slice(1).find(t => t); + if (matchText) { + const offset = match.index + styleContent.slice(match.index).indexOf(matchText); + yield { offset, text: matchText }; } } } From 99f7be2ee53c2b6454518560bfd274a69c121ffc Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 13 Aug 2024 11:33:10 +0800 Subject: [PATCH 3/5] fix: `\w*` --- packages/language-core/lib/utils/parseCssVars.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-core/lib/utils/parseCssVars.ts b/packages/language-core/lib/utils/parseCssVars.ts index 4d83fc29e4..adcdec35d5 100644 --- a/packages/language-core/lib/utils/parseCssVars.ts +++ b/packages/language-core/lib/utils/parseCssVars.ts @@ -1,6 +1,6 @@ // https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61 -const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w+))\s*\)/gi; +const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi; const commentReg1 = /\/\*([\s\S]*?)\*\//g; const commentReg2 = /\/\/([\s\S]*?)\n/g; From f5c42d4b6204bc89ffe9aa7d896a07101439e58c Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 13 Aug 2024 11:42:54 +0800 Subject: [PATCH 4/5] test: drop incorrect case --- test-workspace/language-service/rename/css-vars/input/entry.vue | 1 - test-workspace/language-service/rename/css-vars/output/entry.vue | 1 - 2 files changed, 2 deletions(-) diff --git a/test-workspace/language-service/rename/css-vars/input/entry.vue b/test-workspace/language-service/rename/css-vars/input/entry.vue index d5243c4f62..7f747c1926 100644 --- a/test-workspace/language-service/rename/css-vars/input/entry.vue +++ b/test-workspace/language-service/rename/css-vars/input/entry.vue @@ -9,7 +9,6 @@ const foo = 1; /* ^^^rename: bar */ .bar { color: v-bind('foo'); } .bar { color: v-bind("foo"); } -.bar { color: v-bind(foo + foo); } .bar { color: v-bind('foo + foo'); } .bar { color: v-bind("foo + foo"); } .bar { color: v-bind(); } diff --git a/test-workspace/language-service/rename/css-vars/output/entry.vue b/test-workspace/language-service/rename/css-vars/output/entry.vue index 356c312f92..2ec8fa1311 100644 --- a/test-workspace/language-service/rename/css-vars/output/entry.vue +++ b/test-workspace/language-service/rename/css-vars/output/entry.vue @@ -9,7 +9,6 @@ const bar = 1; /* ^^^rename: bar */ .bar { color: v-bind('bar'); } .bar { color: v-bind("bar"); } -.bar { color: v-bind(bar + bar); } .bar { color: v-bind('bar + bar'); } .bar { color: v-bind("bar + bar"); } .bar { color: v-bind(); } From 7d095d615b48ca86cf7bdb6647791d7668865088 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Mon, 26 Aug 2024 06:56:47 +0800 Subject: [PATCH 5/5] Update renaming.spec.ts --- .../language-server/tests/renaming.spec.ts | 43 ++++--------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/packages/language-server/tests/renaming.spec.ts b/packages/language-server/tests/renaming.spec.ts index 5dfb44718d..eeb0e85dac 100644 --- a/packages/language-server/tests/renaming.spec.ts +++ b/packages/language-server/tests/renaming.spec.ts @@ -185,7 +185,6 @@ describe('Renaming', async () => { .bar { color: v-bind(foo|); } .bar { color: v-bind('foo'); } .bar { color: v-bind("foo"); } - .bar { color: v-bind(foo + foo); } .bar { color: v-bind('foo + foo'); } .bar { color: v-bind("foo + foo"); } .bar { color: v-bind(); } @@ -199,32 +198,6 @@ describe('Renaming', async () => { { "changes": { "file://\${testWorkspacePath}/fixture.vue": [ - { - "newText": "bar", - "range": { - "end": { - "character": 34, - "line": 10, - }, - "start": { - "character": 31, - "line": 10, - }, - }, - }, - { - "newText": "bar", - "range": { - "end": { - "character": 28, - "line": 10, - }, - "start": { - "character": 25, - "line": 10, - }, - }, - }, { "newText": "bar", "range": { @@ -256,11 +229,11 @@ describe('Renaming', async () => { "range": { "end": { "character": 35, - "line": 12, + "line": 11, }, "start": { "character": 32, - "line": 12, + "line": 11, }, }, }, @@ -269,11 +242,11 @@ describe('Renaming', async () => { "range": { "end": { "character": 29, - "line": 12, + "line": 11, }, "start": { "character": 26, - "line": 12, + "line": 11, }, }, }, @@ -282,11 +255,11 @@ describe('Renaming', async () => { "range": { "end": { "character": 35, - "line": 11, + "line": 10, }, "start": { "character": 32, - "line": 11, + "line": 10, }, }, }, @@ -295,11 +268,11 @@ describe('Renaming', async () => { "range": { "end": { "character": 29, - "line": 11, + "line": 10, }, "start": { "character": 26, - "line": 11, + "line": 10, }, }, },