Skip to content

refactor(language-service): correct name and simplify logic of some plugins #5521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions packages/language-core/lib/plugins/vue-root-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,17 @@ const plugin: VueLanguagePlugin = () => {
embeddedFile.content.push([sfc.content, undefined, 0, allCodeFeatures]);
for (
const block of [
sfc.template,
sfc.script,
sfc.scriptSetup,
sfc.template,
...sfc.styles,
...sfc.customBlocks,
]
) {
if (!block) {
continue;
}
let content = block.content;
if (content.endsWith('\r\n')) {
content = content.slice(0, -2);
}
else if (content.endsWith('\n')) {
content = content.slice(0, -1);
}
const offset = content.lastIndexOf('\n') + 1;
const offset = block.content.lastIndexOf('\n', block.content.lastIndexOf('\n') - 1) + 1;
// fix folding range end position failed to mapping
replaceSourceRange(
embeddedFile.content,
Expand Down
10 changes: 6 additions & 4 deletions packages/language-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ import { create as createTypeScriptSyntacticPlugin } from 'volar-service-typescr
import { create as createCssPlugin } from './lib/plugins/css';
import { create as createTypescriptSemanticTokensPlugin } from './lib/plugins/typescript-semantic-tokens';
import { create as createVueAutoDotValuePlugin } from './lib/plugins/vue-autoinsert-dotvalue';
import { create as createVueAutoAddSpacePlugin } from './lib/plugins/vue-autoinsert-space';
import { create as createVueAutoSpacePlugin } from './lib/plugins/vue-autoinsert-space';
import { create as createVueCompilerDomErrorsPlugin } from './lib/plugins/vue-compiler-dom-errors';
import { create as createVueComponentSemanticTokensPlugin } from './lib/plugins/vue-component-semantic-tokens';
import { create as createVueDirectiveCommentsPlugin } from './lib/plugins/vue-directive-comments';
import { create as createVueDocumentDropPlugin } from './lib/plugins/vue-document-drop';
import { create as createVueDocumentHighlightsPlugin } from './lib/plugins/vue-document-highlights';
import { create as createVueDocumentLinksPlugin } from './lib/plugins/vue-document-links';
import { create as createVueExtractFilePlugin } from './lib/plugins/vue-extract-file';
import { create as createVueGlobalTypesErrorPlugin } from './lib/plugins/vue-global-types-error';
import { create as createVueInlayHintsPlugin } from './lib/plugins/vue-inlayhints';
import { create as createVueMissingPropsHintsPlugin } from './lib/plugins/vue-missing-props-hints';
import { create as createVueScopedClassLinksPlugin } from './lib/plugins/vue-scoped-class-links';
import { create as createVueSfcPlugin } from './lib/plugins/vue-sfc';
import { create as createVueSuggestDefineAssignmentPlugin } from './lib/plugins/vue-suggest-define-assignment';
import { create as createVueTemplatePlugin } from './lib/plugins/vue-template';
import { create as createVueTemplateRefLinksPlugin } from './lib/plugins/vue-template-ref-links';
import { create as createVueTwoslashQueriesPlugin } from './lib/plugins/vue-twoslash-queries';

declare module '@volar/language-service' {
Expand All @@ -55,21 +56,22 @@ export function createVueLanguageServicePlugins(
createTypeScriptDocCommentTemplatePlugin(ts),
createTypescriptSemanticTokensPlugin(getTsPluginClient),
createTypeScriptSyntacticPlugin(ts),
createVueAutoAddSpacePlugin(),
createVueAutoSpacePlugin(),
createVueAutoDotValuePlugin(ts, getTsPluginClient),
createVueCompilerDomErrorsPlugin(),
createVueComponentSemanticTokensPlugin(getTsPluginClient),
createVueDocumentDropPlugin(ts, getTsPluginClient),
createVueDocumentLinksPlugin(),
createVueDirectiveCommentsPlugin(),
createVueExtractFilePlugin(ts, getTsPluginClient),
createVueGlobalTypesErrorPlugin(),
createVueInlayHintsPlugin(ts),
createVueMissingPropsHintsPlugin(getTsPluginClient),
createVueScopedClassLinksPlugin(),
createVueSfcPlugin(),
createVueSuggestDefineAssignmentPlugin(),
createVueTemplatePlugin('html', getTsPluginClient),
createVueTemplatePlugin('pug', getTsPluginClient),
createVueTemplateRefLinksPlugin(),
createVueTwoslashQueriesPlugin(getTsPluginClient),
createEmmetPlugin({
mappedLanguages: {
Expand Down
16 changes: 7 additions & 9 deletions packages/language-service/lib/plugins/css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LanguageServicePlugin, TextDocument, VirtualCode } from '@volar/language-service';
import { VueVirtualCode } from '@vue/language-core';
import { isRenameEnabled, VueVirtualCode } from '@vue/language-core';
import { create as baseCreate, type Provide } from 'volar-service-css';
import type * as css from 'vscode-css-languageservice';
import { URI } from 'vscode-uri';
Expand All @@ -20,9 +20,11 @@ export function create(): LanguageServicePlugin {
async provideDiagnostics(document, token) {
let diagnostics = await baseInstance.provideDiagnostics?.(document, token) ?? [];
if (document.languageId === 'postcss') {
diagnostics = diagnostics.filter(diag => diag.code !== 'css-semicolonexpected');
diagnostics = diagnostics.filter(diag => diag.code !== 'css-ruleorselectorexpected');
diagnostics = diagnostics.filter(diag => diag.code !== 'unknownAtRules');
diagnostics = diagnostics.filter(diag =>
diag.code !== 'css-semicolonexpected'
&& diag.code !== 'css-ruleorselectorexpected'
&& diag.code !== 'unknownAtRules'
);
}
return diagnostics;
},
Expand Down Expand Up @@ -83,11 +85,7 @@ export function create(): LanguageServicePlugin {

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
) {
if (!sourceOffsets.length || !isRenameEnabled(data)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function create(
) => import('@vue/typescript-plugin/lib/requests').Requests | undefined,
): LanguageServicePlugin {
return {
name: 'typescript-highlights',
name: 'typescript-semantic-tokens',
capabilities: {
semanticTokensProvider: {
legend: {
Expand Down
25 changes: 10 additions & 15 deletions packages/language-service/lib/plugins/vue-autoinsert-dotvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function create(
create(context) {
const tsPluginClient = getTsPluginClient?.(context);
let currentReq = 0;

return {
async provideAutoInsertSnippet(document, selection, change) {
// selection must at end of change
Expand Down Expand Up @@ -67,32 +68,26 @@ export function create(
return;
}

let sourceCodeOffset = document.offsetAt(selection);
let mapped = false;
for (const [, map] of context.language.maps.forEach(virtualCode)) {
for (const [sourceOffset] of map.toSourceLocation(sourceCodeOffset)) {
sourceCodeOffset = sourceOffset;
mapped = true;
break;
}
if (mapped) {
break;
}
let sourceOffset: number | undefined;
const map = context.language.maps.get(virtualCode, sourceScript);
for (const [offset] of map.toSourceLocation(document.offsetAt(selection))) {
sourceOffset = offset;
break;
}
if (!mapped) {
if (sourceOffset === undefined) {
return;
}

for (const { ast, startTagEnd, endTagStart } of blocks) {
if (sourceCodeOffset < startTagEnd || sourceCodeOffset > endTagStart) {
if (sourceOffset < startTagEnd || sourceOffset > endTagStart) {
continue;
}
if (isBlacklistNode(ts, ast, sourceCodeOffset - startTagEnd, false)) {
if (isBlacklistNode(ts, ast, sourceOffset - startTagEnd, false)) {
return;
}
}

const props = await tsPluginClient?.getPropertiesAtLocation(root.fileName, sourceCodeOffset) ?? [];
const props = await tsPluginClient?.getPropertiesAtLocation(root.fileName, sourceOffset) ?? [];
if (props.some(prop => prop === 'value')) {
return '${1:.value}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export function create(): LanguageServicePlugin {
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 (!virtualCode) {
return;
}

const root = sourceScript?.generated?.root;
if (!(root instanceof VueVirtualCode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function create(
) => import('@vue/typescript-plugin/lib/requests').Requests | undefined,
): LanguageServicePlugin {
return {
name: 'vue-component-highlights',
name: 'vue-component-semantic-tokens',
capabilities: {
semanticTokensProvider: {
legend: {
Expand Down
131 changes: 0 additions & 131 deletions packages/language-service/lib/plugins/vue-document-links.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/language-service/lib/plugins/vue-extract-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function create(
const props = toExtract.filter(p => !p.model);
const models = toExtract.filter(p => p.model);
if (props.length) {
lines.push(`defineProps<{ \n\t${props.map(p => `${p.name}: ${p.type};`).join('\n\t')}\n}>()`);
lines.push(`defineProps<{\n\t${props.map(p => `${p.name}: ${p.type};`).join('\n\t')}\n}>()`);
}
for (const model of models) {
lines.push(`const ${model.name} = defineModel<${model.type}>('${model.name}', { required: true })`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { DiagnosticSeverity, LanguageServicePlugin } from '@volar/language-

export function create(): LanguageServicePlugin {
return {
name: 'vue-compiler-dom-errors',
name: 'vue-global-types-error',
capabilities: {
diagnosticProvider: {
interFileDependencies: false,
Expand Down
Loading
Loading