From 09a81fe5280b5504edad306d40dbafe46455a52b Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 13 Aug 2024 12:08:44 +0800 Subject: [PATCH 01/12] fix: typescript-semantic renaming first --- packages/language-service/lib/plugins/css.ts | 49 +++++++++++++++++++- packages/language-service/package.json | 1 + pnpm-lock.yaml | 3 ++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index 9c6128dc2a..d67e0ef0b3 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -1,5 +1,10 @@ import type { LanguageServicePlugin, LanguageServicePluginInstance } from '@volar/language-service'; -import { create as baseCreate } from 'volar-service-css'; +import type { TextDocument } from 'vscode-languageserver-textdocument'; +import * as css from 'vscode-css-languageservice'; +import { create as baseCreate, type Provide } from 'volar-service-css'; + +const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#[{])/gi; +const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w+))\s*\)/gi; export function create(): LanguageServicePlugin { const base = baseCreate({ scssDocumentSelector: ['scss', 'postcss'] }); @@ -7,6 +12,11 @@ export function create(): LanguageServicePlugin { ...base, create(context): LanguageServicePluginInstance { const baseInstance = base.create(context); + const { + 'css/languageService': getCssLs, + 'css/stylesheet': getStylesheet + } = baseInstance.provide as Provide; + return { ...baseInstance, async provideDiagnostics(document, token) { @@ -18,7 +28,44 @@ export function create(): LanguageServicePlugin { } return diagnostics; }, + provideRenameRange(document, position) { + return worker(document, (stylesheet, cssLs) => { + const text = document.getText(); + const offset = document.offsetAt(position); + + for (const [start, end] of forEachRegExp()) { + if (offset >= start && offset <= end) { + return; + } + } + return cssLs.prepareRename(document, position, stylesheet); + + function* forEachRegExp() { + for (const reg of [ + cssClassNameReg, + vBindCssVarReg + ]) { + for (const match of text.matchAll(reg)) { + const matchText = match.slice(1).find(t => t); + if (matchText) { + const start = match.index + text.slice(match.index).indexOf(matchText) + const end = start + matchText.length; + yield [start, end]; + } + } + } + } + }); + } }; + + async function worker(document: TextDocument, callback: (stylesheet: css.Stylesheet, cssLs: css.LanguageService) => T) { + const cssLs = getCssLs(document); + if (!cssLs) { + return; + } + return callback(getStylesheet(document, cssLs), cssLs); + } }, }; } diff --git a/packages/language-service/package.json b/packages/language-service/package.json index 2f707cefa1..beb66e35b0 100644 --- a/packages/language-service/package.json +++ b/packages/language-service/package.json @@ -33,6 +33,7 @@ "volar-service-pug-beautify": "0.0.59", "volar-service-typescript": "0.0.59", "volar-service-typescript-twoslash-queries": "0.0.59", + "vscode-css-languageservice": "^6.3.0", "vscode-html-languageservice": "^5.2.0", "vscode-languageserver-textdocument": "^1.0.11", "vscode-uri": "^3.0.8" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 14b9628443..fb06913d71 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -238,6 +238,9 @@ importers: volar-service-typescript-twoslash-queries: specifier: 0.0.59 version: 0.0.59(@volar/language-service@2.4.0-alpha.18) + vscode-css-languageservice: + specifier: ^6.3.0 + version: 6.3.0 vscode-html-languageservice: specifier: ^5.2.0 version: 5.3.0 From 934cd9c27e93c78a0c0e24db3dcd54594d3232b5 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 13 Aug 2024 12:52:16 +0800 Subject: [PATCH 02/12] fix: determine scoped --- packages/language-service/lib/plugins/css.ts | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index d67e0ef0b3..3154d5ca01 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -1,7 +1,9 @@ import type { LanguageServicePlugin, LanguageServicePluginInstance } from '@volar/language-service'; import type { TextDocument } from 'vscode-languageserver-textdocument'; -import * as css from 'vscode-css-languageservice'; +import { VueVirtualCode } from '@vue/language-core'; import { create as baseCreate, type Provide } from 'volar-service-css'; +import * as css from 'vscode-css-languageservice'; +import { URI } from 'vscode-uri'; const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#[{])/gi; const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w+))\s*\)/gi; @@ -29,6 +31,25 @@ export function create(): LanguageServicePlugin { return diagnostics; }, provideRenameRange(document, position) { + + const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri)); + const sourceScript = decoded && context.language.scripts.get(decoded[0]); + const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); + + const regexps: RegExp[] = []; + + if (virtualCode?.id.startsWith('style_')) { + const i = Number(virtualCode.id.slice('style_'.length)); + if (sourceScript?.generated?.root instanceof VueVirtualCode) { + const style = sourceScript.generated.root.sfc.styles[i]; + const option = sourceScript.generated.root.vueCompilerOptions.experimentalResolveStyleCssClasses; + if (option === 'always' || (option === 'scoped' && style.scoped)) { + regexps.push(cssClassNameReg); + } + } + } + regexps.push(vBindCssVarReg); + return worker(document, (stylesheet, cssLs) => { const text = document.getText(); const offset = document.offsetAt(position); @@ -41,10 +62,7 @@ export function create(): LanguageServicePlugin { return cssLs.prepareRename(document, position, stylesheet); function* forEachRegExp() { - for (const reg of [ - cssClassNameReg, - vBindCssVarReg - ]) { + for (const reg of regexps) { for (const match of text.matchAll(reg)) { const matchText = match.slice(1).find(t => t); if (matchText) { From 111043c5ce8568a832ec2f38f636cb4b7103359a Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 13 Aug 2024 13:41:30 +0800 Subject: [PATCH 03/12] feat: support module --- packages/language-service/lib/plugins/css.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index 3154d5ca01..275b74d2d6 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -43,7 +43,7 @@ export function create(): LanguageServicePlugin { if (sourceScript?.generated?.root instanceof VueVirtualCode) { const style = sourceScript.generated.root.sfc.styles[i]; const option = sourceScript.generated.root.vueCompilerOptions.experimentalResolveStyleCssClasses; - if (option === 'always' || (option === 'scoped' && style.scoped)) { + if (option === 'always' || (option === 'scoped' && style.scoped) || style.module) { regexps.push(cssClassNameReg); } } From a90cbe8ae1e490dddb966e94da3205af71ee0112 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 23 Oct 2024 19:25:12 +0800 Subject: [PATCH 04/12] chore: deps --- packages/language-service/package.json | 2 +- pnpm-lock.yaml | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/language-service/package.json b/packages/language-service/package.json index 643ac1e8b8..c8caa67bcf 100644 --- a/packages/language-service/package.json +++ b/packages/language-service/package.json @@ -34,7 +34,7 @@ "volar-service-pug-beautify": "0.0.62", "volar-service-typescript": "0.0.62", "volar-service-typescript-twoslash-queries": "0.0.62", - "vscode-css-languageservice": "^6.3.0", + "vscode-css-languageservice": "^6.3.1", "vscode-html-languageservice": "^5.2.0", "vscode-languageserver-textdocument": "^1.0.11", "vscode-uri": "^3.0.8" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a576ab6f4..af79130174 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -243,7 +243,7 @@ importers: version: 0.0.62(@volar/language-service@2.4.2) vscode-css-languageservice: specifier: ^6.3.0 - version: 6.3.0 + version: 6.3.1 vscode-html-languageservice: specifier: ^5.2.0 version: 5.3.1 @@ -967,46 +967,55 @@ packages: resolution: {integrity: sha512-ztRJJMiE8nnU1YFcdbd9BcH6bGWG1z+jP+IPW2oDUAPxPjo9dverIOyXz76m6IPA6udEL12reYeLojzW2cYL7w==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.21.2': resolution: {integrity: sha512-flOcGHDZajGKYpLV0JNc0VFH361M7rnV1ee+NTeC/BQQ1/0pllYcFmxpagltANYt8FYf9+kL6RSk80Ziwyhr7w==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.21.2': resolution: {integrity: sha512-69CF19Kp3TdMopyteO/LJbWufOzqqXzkrv4L2sP8kfMaAQ6iwky7NoXTp7bD6/irKgknDKM0P9E/1l5XxVQAhw==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.21.2': resolution: {integrity: sha512-48pD/fJkTiHAZTnZwR0VzHrao70/4MlzJrq0ZsILjLW/Ab/1XlVUStYyGt7tdyIiVSlGZbnliqmult/QGA2O2w==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.21.2': resolution: {integrity: sha512-cZdyuInj0ofc7mAQpKcPR2a2iu4YM4FQfuUzCVA2u4HI95lCwzjoPtdWjdpDKyHxI0UO82bLDoOaLfpZ/wviyQ==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.21.2': resolution: {integrity: sha512-RL56JMT6NwQ0lXIQmMIWr1SW28z4E4pOhRRNqwWZeXpRlykRIlEpSWdsgNWJbYBEWD84eocjSGDu/XxbYeCmwg==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.21.2': resolution: {integrity: sha512-PMxkrWS9z38bCr3rWvDFVGD6sFeZJw4iQlhrup7ReGmfn7Oukrr/zweLhYX6v2/8J6Cep9IEA/SmjXjCmSbrMQ==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.21.2': resolution: {integrity: sha512-B90tYAUoLhU22olrafY3JQCFLnT3NglazdwkHyxNDYF/zAxJt5fJUB/yBoWFoIQ7SQj+KLe3iL4BhOMa9fzgpw==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.21.2': resolution: {integrity: sha512-7twFizNXudESmC9oneLGIUmoHiiLppz/Xs5uJQ4ShvE6234K0VB1/aJYU3f/4g7PhssLGKBVCC37uRkkOi8wjg==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.21.2': resolution: {integrity: sha512-9rRero0E7qTeYf6+rFh3AErTNU1VCQg2mn7CQcI44vNUWM9Ze7MSRS/9RFuSsox+vstRt97+x3sOhEey024FRQ==} From d5611584617be0697885965c9f4b87d34ecc7639 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 23 Oct 2024 19:26:34 +0800 Subject: [PATCH 05/12] fix: `_sfc` --- packages/language-service/lib/plugins/css.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index 275b74d2d6..e2423bc6d3 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -6,7 +6,7 @@ import * as css from 'vscode-css-languageservice'; import { URI } from 'vscode-uri'; const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#[{])/gi; -const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w+))\s*\)/gi; +const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi; export function create(): LanguageServicePlugin { const base = baseCreate({ scssDocumentSelector: ['scss', 'postcss'] }); @@ -41,7 +41,7 @@ export function create(): LanguageServicePlugin { if (virtualCode?.id.startsWith('style_')) { const i = Number(virtualCode.id.slice('style_'.length)); if (sourceScript?.generated?.root instanceof VueVirtualCode) { - const style = sourceScript.generated.root.sfc.styles[i]; + const style = sourceScript.generated.root._sfc.styles[i]; const option = sourceScript.generated.root.vueCompilerOptions.experimentalResolveStyleCssClasses; if (option === 'always' || (option === 'scoped' && style.scoped) || style.module) { regexps.push(cssClassNameReg); From a92e8d22036acd395320db4366f888613030bb2c Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 23 Oct 2024 19:28:10 +0800 Subject: [PATCH 06/12] chore: deps --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af79130174..dc2c7443d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -242,7 +242,7 @@ importers: specifier: 0.0.62 version: 0.0.62(@volar/language-service@2.4.2) vscode-css-languageservice: - specifier: ^6.3.0 + specifier: ^6.3.1 version: 6.3.1 vscode-html-languageservice: specifier: ^5.2.0 From a283112051987f92054e42bcaf4ed5f953a4036a Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Dec 2024 17:52:39 +0800 Subject: [PATCH 07/12] chore: update lockfile --- pnpm-lock.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9369ee7bda..7018894e3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -238,6 +238,9 @@ importers: volar-service-typescript-twoslash-queries: specifier: 0.0.62 version: 0.0.62(@volar/language-service@2.4.11) + vscode-css-languageservice: + specifier: ^6.3.1 + version: 6.3.2 vscode-html-languageservice: specifier: ^5.2.0 version: 5.3.1 @@ -968,6 +971,7 @@ packages: resolution: {integrity: sha512-vPul4uodvWvLhRco2w0GcyZcdyBfpfDRgNKU+p35AWEbJ/HPs1tOUrkSueVbBS0RQHAf/A+nNtDpvw95PeVKOA==} cpu: [loong64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-powerpc64le-gnu@4.28.1': resolution: {integrity: sha512-pTnTdBuC2+pt1Rmm2SV7JWRqzhYpEILML4PKODqLz+C7Ou2apEV52h19CR7es+u04KlqplggmN9sqZlekg3R1A==} From ea394f13973fbf1edcb3975c214a32817b223d5b Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Dec 2024 18:48:12 +0800 Subject: [PATCH 08/12] refactor: determine based on the virtual code location and features --- packages/language-service/lib/plugins/css.ts | 77 +++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index f27f13d873..8b91d57ac3 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -1,13 +1,10 @@ -import type { LanguageServicePlugin } from '@volar/language-service'; +import type { LanguageServicePlugin, VirtualCode } from '@volar/language-service'; import { VueVirtualCode } from '@vue/language-core'; import { create as baseCreate, type Provide } from 'volar-service-css'; import * as css from 'vscode-css-languageservice'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import { URI } from 'vscode-uri'; -const cssClassNameReg = /(?=(\.[a-z_][-\w]*)[\s.,+~>:#[{])/gi; -const vBindCssVarReg = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([a-z_]\w*))\s*\)/gi; - export function create(): LanguageServicePlugin { const base = baseCreate({ scssDocumentSelector: ['scss', 'postcss'] }); return { @@ -31,48 +28,58 @@ export function create(): LanguageServicePlugin { return diagnostics; }, provideRenameRange(document, position) { + do { + const uri = URI.parse(document.uri); + const decoded = context.decodeEmbeddedDocumentUri(uri); + const sourceScript = decoded && context.language.scripts.get(decoded[0]); + const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); + if (!sourceScript?.generated || !virtualCode?.id.startsWith('style_')) { + break; + } - const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri)); - const sourceScript = decoded && context.language.scripts.get(decoded[0]); - const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); - - const regexps: RegExp[] = []; + const root = sourceScript.generated.root; + if (!(root instanceof VueVirtualCode)) { + break; + } - if (virtualCode?.id.startsWith('style_')) { - const i = Number(virtualCode.id.slice('style_'.length)); - if (sourceScript?.generated?.root instanceof VueVirtualCode) { - const style = sourceScript.generated.root._sfc.styles[i]; - const option = sourceScript.generated.root.vueCompilerOptions.experimentalResolveStyleCssClasses; - if (option === 'always' || (option === 'scoped' && style.scoped) || style.module) { - regexps.push(cssClassNameReg); + const block = root._sfc.styles.find((style) => style.name === decoded![1]); + if (!block) { + break; + } + + let script: VirtualCode | undefined; + for (const [key, value] of sourceScript.generated.embeddedCodes) { + if (key.startsWith('script_')) { + script = value; + break; } } - } - regexps.push(vBindCssVarReg); + if (!script) { + break; + } - return worker(document, (stylesheet, cssLs) => { - const text = document.getText(); - const offset = document.offsetAt(position); + const offset = document.offsetAt(position) + block.startTagEnd; + for (const { sourceOffsets, lengths, data } of script.mappings) { + if ( + !sourceOffsets.length + || !data.navigation + || typeof data.navigation === 'object' && !data.navigation.shouldRename + ) { + continue; + } + + const length = lengths.reduce((res, val) => res + val, 0); + const start = sourceOffsets[0]; + const end = sourceOffsets.at(-1)! + length; - for (const [start, end] of forEachRegExp()) { if (offset >= start && offset <= end) { return; } } - return cssLs.prepareRename(document, position, stylesheet); + } while (0); - function* forEachRegExp() { - for (const reg of regexps) { - for (const match of text.matchAll(reg)) { - const matchText = match.slice(1).find(t => t); - if (matchText) { - const start = match.index + text.slice(match.index).indexOf(matchText) - const end = start + matchText.length; - yield [start, end]; - } - } - } - } + return worker(document, (stylesheet, cssLs) => { + return cssLs.prepareRename(document, position, stylesheet); }); } }; From 580a096130ae08c6b2d08999d5c25d40bb7be4c7 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Dec 2024 18:49:06 +0800 Subject: [PATCH 09/12] revert: re-generate property access when referencing the scoped classes --- .../language-core/lib/codegen/script/template.ts | 2 +- .../lib/codegen/template/styleScopedClasses.ts | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 982e37a909..37ae7e1b07 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -162,7 +162,7 @@ function* generateStyleScopedClasses( ctx: TemplateCodegenContext ): Generator { const firstClasses = new Set(); - yield `type __VLS_StyleScopedClasses = {}`; + yield `let __VLS_styleScopedClasses!: {}`; for (let i = 0; i < options.sfc.styles.length; i++) { const style = options.sfc.styles[i]; const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses; diff --git a/packages/language-core/lib/codegen/template/styleScopedClasses.ts b/packages/language-core/lib/codegen/template/styleScopedClasses.ts index d7f8cb5bd8..d360c3a606 100644 --- a/packages/language-core/lib/codegen/template/styleScopedClasses.ts +++ b/packages/language-core/lib/codegen/template/styleScopedClasses.ts @@ -1,27 +1,23 @@ import type { Code } from '../../types'; -import { endOfLine } from '../utils'; +import { endOfLine, newLine } from '../utils'; import type { TemplateCodegenContext } from './context'; export function* generateStyleScopedClassReferences( ctx: TemplateCodegenContext, withDot = false ): Generator { - if (!ctx.emptyClassOffsets.length && !ctx.scopedClasses.length) { - return; - } - - yield `[`; for (const offset of ctx.emptyClassOffsets) { - yield `'`; + yield `__VLS_styleScopedClasses['`; yield [ '', 'template', offset, ctx.codeFeatures.additionalCompletion, ]; - yield `', `; + yield `']${endOfLine}`; } for (const { source, className, offset } of ctx.scopedClasses) { + yield `__VLS_styleScopedClasses[`; yield [ '', source, @@ -39,9 +35,9 @@ export function* generateStyleScopedClassReferences( offset + className.length, ctx.codeFeatures.navigationWithoutRename, ]; - yield `, `; + yield `]${endOfLine}`; } - yield `] as (keyof __VLS_StyleScopedClasses)[]${endOfLine}`; + yield newLine; function* escapeString(source: string, className: string, offset: number, escapeTargets: string[]): Generator { let count = 0; From 51b2219a51075aaf2cfca6d0fe93c383464ddd6d Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Dec 2024 18:51:09 +0800 Subject: [PATCH 10/12] test: revert --- test-workspace/tsc/passedFixtures/#3688/main.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-workspace/tsc/passedFixtures/#3688/main.vue b/test-workspace/tsc/passedFixtures/#3688/main.vue index a225186021..7fbf85ca0a 100644 --- a/test-workspace/tsc/passedFixtures/#3688/main.vue +++ b/test-workspace/tsc/passedFixtures/#3688/main.vue @@ -1,6 +1,6 @@ From 0dd7c15787d7ed58fb64738634c1e47e8ba8b557 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Dec 2024 18:55:15 +0800 Subject: [PATCH 11/12] chore: lint --- packages/language-service/lib/plugins/css.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index 8b91d57ac3..54fa1a0828 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -42,11 +42,11 @@ export function create(): LanguageServicePlugin { break; } - const block = root._sfc.styles.find((style) => style.name === decoded![1]); + const block = root._sfc.styles.find(style => style.name === decoded![1]); if (!block) { break; } - + let script: VirtualCode | undefined; for (const [key, value] of sourceScript.generated.embeddedCodes) { if (key.startsWith('script_')) { @@ -84,7 +84,7 @@ export function create(): LanguageServicePlugin { } }; - async function worker(document: TextDocument, callback: (stylesheet: css.Stylesheet, cssLs: css.LanguageService) => T) { + function worker(document: TextDocument, callback: (stylesheet: css.Stylesheet, cssLs: css.LanguageService) => T) { const cssLs = getCssLs(document); if (!cssLs) { return; From 7a14882e87cfbf5bbf2f8f8b2763ea7342453c1c Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Dec 2024 20:48:50 +0800 Subject: [PATCH 12/12] fix: end offset calculation --- packages/language-service/lib/plugins/css.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/language-service/lib/plugins/css.ts b/packages/language-service/lib/plugins/css.ts index 54fa1a0828..3ec617d2e0 100644 --- a/packages/language-service/lib/plugins/css.ts +++ b/packages/language-service/lib/plugins/css.ts @@ -68,9 +68,8 @@ export function create(): LanguageServicePlugin { continue; } - const length = lengths.reduce((res, val) => res + val, 0); const start = sourceOffsets[0]; - const end = sourceOffsets.at(-1)! + length; + const end = sourceOffsets.at(-1)! + lengths.at(-1)!; if (offset >= start && offset <= end) { return;