Skip to content

Commit

Permalink
refactor(language-service): remove component coloring logic from vue-…
Browse files Browse the repository at this point in the history
…template plugin
  • Loading branch information
johnsoncodehk committed Mar 6, 2025
1 parent 266b165 commit 0b0dc46
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 68 deletions.
4 changes: 2 additions & 2 deletions packages/language-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ function getCommonLanguageServicePlugins(
createCssPlugin(),
createPugFormatPlugin(),
createJsonPlugin(),
createVueTemplatePlugin('html', ts, getTsPluginClient),
createVueTemplatePlugin('pug', ts, getTsPluginClient),
createVueTemplatePlugin('html', getTsPluginClient),
createVueTemplatePlugin('pug', getTsPluginClient),
createVueMissingPropsHintsPlugin(getTsPluginClient),
createVueSfcPlugin(),
createVueTwoslashQueriesPlugin(getTsPluginClient),
Expand Down
65 changes: 0 additions & 65 deletions packages/language-service/lib/plugins/vue-template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Disposable, LanguageServiceContext } from '@volar/language-service';
import { VueVirtualCode, hyphenateAttr, hyphenateTag, tsCodegen } from '@vue/language-core';
import { camelize, capitalize } from '@vue/shared';
import { getComponentSpans } from '@vue/typescript-plugin/lib/common';
import type { ComponentPropInfo } from '@vue/typescript-plugin/lib/requests/getComponentProps';
import { create as createHtmlService } from 'volar-service-html';
import { create as createPugService } from 'volar-service-pug';
Expand Down Expand Up @@ -38,7 +37,6 @@ let modelData: html.HTMLDataV1;

export function create(
mode: 'html' | 'pug',
ts: typeof import('typescript'),
getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined
): LanguageServicePlugin {
let customData: html.IHTMLDataProvider[] = [];
Expand Down Expand Up @@ -91,12 +89,6 @@ export function create(
interFileDependencies: false,
workspaceDiagnostics: false,
},
semanticTokensProvider: {
legend: {
tokenTypes: ['class'],
tokenModifiers: [],
},
}
},
create(context) {
const tsPluginClient = getTsPluginClient?.(context);
Expand Down Expand Up @@ -269,63 +261,6 @@ export function create(
...templateErrors,
];
},

provideDocumentSemanticTokens(document, range, legend) {

if (!isSupportedDocument(document)) {
return;
}

if (!context.project.vue) {
return;
}
const vueCompilerOptions = context.project.vue.compilerOptions;

const languageService = context.inject<(import('volar-service-typescript').Provide), 'typescript/languageService'>('typescript/languageService');
if (!languageService) {
return;
}

const uri = URI.parse(document.uri);
const decoded = context.decodeEmbeddedDocumentUri(uri);
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
const root = sourceScript?.generated?.root;
if (!(root instanceof VueVirtualCode)) {
return;
}

const { template } = root.sfc;
if (!template) {
return;
}

const spans = getComponentSpans.call(
{
files: context.language.scripts,
languageService,
typescript: ts,
vueOptions: vueCompilerOptions,
},
root,
template,
{
start: document.offsetAt(range.start),
length: document.offsetAt(range.end) - document.offsetAt(range.start),
}
);
const classTokenIndex = legend.tokenTypes.indexOf('class');

return spans.map(span => {
const start = document.positionAt(span.start);
return [
start.line,
start.character,
span.length,
classTokenIndex,
0,
];
});
},
};

async function provideHtmlData(sourceDocumentUri: URI, vueCode: VueVirtualCode) {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-plugin/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function getEncodedSemanticClassifications<T>(
};
}

export function getComponentSpans(
function getComponentSpans(
this: Pick<RequestContext, 'typescript' | 'languageService'>,
vueCode: VueVirtualCode,
template: NonNullable<VueVirtualCode['_sfc']['template']>,
Expand Down

0 comments on commit 0b0dc46

Please sign in to comment.