Skip to content
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

refactor(language-core): remove experimentalAdditionalLanguageModules and deprecated APIs #3907

Merged
merged 2 commits into from
Feb 28, 2024
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
4 changes: 2 additions & 2 deletions packages/component-meta/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function baseCreate(
}
};

const vueLanguagePlugins = vue.createLanguages(
const vueLanguagePlugin = vue.createVueLanguagePlugin(
ts,
id => id,
host.getCompilationSettings(),
Expand All @@ -158,7 +158,7 @@ export function baseCreate(
const language = createLanguage(
ts,
ts.sys,
vueLanguagePlugins,
[vueLanguagePlugin],
configFileName,
host,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"experimentalComponentOptionsWrapperEnable": {
"deprecated": true
},
"experimentalAdditionalLanguageModules": {
"deprecated": true,
"type": "array",
"markdownDescription": "https://github.com/vuejs/language-tools/pull/2267"
},
Comment on lines +54 to +58
Copy link
Collaborator

@rchl rchl Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's removed then the property should be removed instead of marked as deprecated IMO.

If the idea is that the link provides some info about removal then it's a wrong link.

Copy link
Member Author

@johnsoncodehk johnsoncodehk Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of marking it as deprecated is to be able to prompt warnings. I would remove the description, but I agree it would be better to have a deprecated message.

image

Copy link
Collaborator

@rchl rchl Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've assumed that the schema uses "additionalProperties": false so that the removal would raise and error. But I see that it's not the case. I think that adding it would make sense so that this could be removed and also people would see issues if they mistype some option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get "additionalProperties": false to work, please feel free to open a PR if you get it to work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additionalProperties might not work if there are multiple schemas extending the same object but then my question is: do deprecated properties really need to be separated into its own file? If they wouldn't then it would be easy to use additionalProperties: false.

BTW. deprecated is not a meant to be used for functionality that is removed but only for that that is still supported but discouraged. With additionalProperties:false we could express both removed and deprecated properties.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm this works and implement by 777b0a1, thanks!

"bypassDefineComponentToExposePropsAndEmitsForJsScriptSetupComponents": {
"deprecated": true
},
Expand Down
4 changes: 0 additions & 4 deletions packages/language-core/schemas/vue-tsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@
},
"markdownDescription": "https://github.com/vuejs/language-tools/issues/1969"
},
"experimentalAdditionalLanguageModules": {
"type": "array",
"markdownDescription": "https://github.com/vuejs/language-tools/pull/2267"
},
"experimentalDefinePropProposal": {
"enum": [
"kevinEdition",
Expand Down
19 changes: 1 addition & 18 deletions packages/language-core/src/languageModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getFileRegistryKey(
return JSON.stringify(values);
}

export function createVueLanguage(
export function createVueLanguagePlugin(
ts: typeof import('typescript'),
getFileName: (fileId: string) => string,
compilerOptions: ts.CompilerOptions = {},
Expand Down Expand Up @@ -160,20 +160,3 @@ export function createVueLanguage(
},
};
}

/**
* @deprecated planed to remove in 2.0, please use createVueLanguage instead of
*/
export function createLanguages(
ts: typeof import('typescript'),
getFileName: (fileId: string) => string,
compilerOptions: ts.CompilerOptions = {},
vueCompilerOptions: Partial<VueCompilerOptions> = {},
codegenStack: boolean = false,
globalTypesHolder?: string
): LanguagePlugin[] {
return [
createVueLanguage(ts, getFileName, compilerOptions, vueCompilerOptions, codegenStack, globalTypesHolder),
...vueCompilerOptions.experimentalAdditionalLanguageModules?.map(module => require(module)) ?? [],
];
}
1 change: 0 additions & 1 deletion packages/language-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export interface VueCompilerOptions {
experimentalResolveStyleCssClasses: 'scoped' | 'always' | 'never';
experimentalModelPropName: Record<string, Record<string, boolean | Record<string, string> | Record<string, string>[]>>;
experimentalUseElementAccessInTemplate: boolean;
experimentalAdditionalLanguageModules: string[];
}

export type VueLanguagePlugin = (ctx: {
Expand Down
6 changes: 0 additions & 6 deletions packages/language-core/src/utils/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ function getPartialVueCompilerOptions(

result.plugins = plugins;
}
if (rawOptions.experimentalAdditionalLanguageModules) {
result.experimentalAdditionalLanguageModules = rawOptions.experimentalAdditionalLanguageModules
.map(resolvePath)
.filter((module): module is NonNullable<typeof module> => !!module);
}

return result;

Expand Down Expand Up @@ -266,7 +261,6 @@ export function resolveVueCompilerOptions(vueOptions: Partial<VueCompilerOptions

// experimental
experimentalDefinePropProposal: vueOptions.experimentalDefinePropProposal ?? false,
experimentalAdditionalLanguageModules: vueOptions.experimentalAdditionalLanguageModules ?? [],
experimentalResolveStyleCssClasses: vueOptions.experimentalResolveStyleCssClasses ?? 'scoped',
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L49-L51
// https://vuejs.org/guide/essentials/forms.html#form-input-bindings
Expand Down
40 changes: 18 additions & 22 deletions packages/language-server/src/nodeServer.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { createConnection, createServer, createSimpleProjectProviderFactory, createTypeScriptProjectProviderFactory, loadTsdkByPath } from '@volar/language-server/node';
import { ServerProject } from '@volar/language-server';
import * as vue2 from '@vue/language-core';
import { VueCompilerOptions } from '@vue/language-core';
import * as nameCasing from '@vue/language-service';
import * as vue from '@vue/language-service';
import * as componentMeta from 'vue-component-meta/out/base';
import { createConnection, createServer, createSimpleProjectProviderFactory, createTypeScriptProjectProviderFactory, loadTsdkByPath } from '@volar/language-server/node';
import { ParsedCommandLine, VueCompilerOptions, createParsedCommandLine, createVueLanguagePlugin, parse, resolveVueCompilerOptions } from '@vue/language-core';
import { ServiceEnvironment, convertAttrName, convertTagName, createVueServicePlugins, detect } from '@vue/language-service';
import { ComponentMetaChecker, baseCreate } from 'vue-component-meta/out/base';
import { DetectNameCasingRequest, GetComponentMeta, GetConvertAttrCasingEditsRequest, GetConvertTagCasingEditsRequest, ParseSFCRequest } from './protocol';
import { VueInitializationOptions } from './types';

const connection = createConnection();
const server = createServer(connection);
const checkers = new WeakMap<ServerProject, componentMeta.ComponentMetaChecker>();
const envToVueOptions = new WeakMap<vue.ServiceEnvironment, VueCompilerOptions>();
const checkers = new WeakMap<ServerProject, ComponentMetaChecker>();
const envToVueOptions = new WeakMap<ServiceEnvironment, VueCompilerOptions>();

let tsdk: ReturnType<typeof loadTsdkByPath>;

Expand Down Expand Up @@ -39,23 +37,21 @@ connection.onInitialize(params => {
{
watchFileExtensions: ['js', 'cjs', 'mjs', 'ts', 'cts', 'mts', 'jsx', 'tsx', 'json', ...vueFileExtensions],
getServicePlugins() {
const services = vue.resolveServices({}, tsdk.typescript, env => envToVueOptions.get(env)!);

return Object.values(services);
return createVueServicePlugins(tsdk.typescript, env => envToVueOptions.get(env)!);
},
async getLanguagePlugins(serviceEnv, projectContext) {
const [commandLine, vueOptions] = await parseCommandLine();
const resolvedVueOptions = vue.resolveVueCompilerOptions(vueOptions);
const languages = vue.resolveLanguages({}, tsdk.typescript, serviceEnv.typescript!.uriToFileName, commandLine?.options ?? {}, resolvedVueOptions, options.codegenStack);
const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
const vueLanguagePlugin = createVueLanguagePlugin(tsdk.typescript, serviceEnv.typescript!.uriToFileName, commandLine?.options ?? {}, resolvedVueOptions, options.codegenStack);

envToVueOptions.set(serviceEnv, resolvedVueOptions);

return Object.values(languages);
return [vueLanguagePlugin];

async function parseCommandLine() {

let commandLine: vue2.ParsedCommandLine | undefined;
let vueOptions: Partial<vue.VueCompilerOptions> = {};
let commandLine: ParsedCommandLine | undefined;
let vueOptions: Partial<VueCompilerOptions> = {};

if (projectContext.typescript) {

Expand All @@ -67,7 +63,7 @@ connection.onInitialize(params => {
while (sysVersion !== newSysVersion) {
sysVersion = newSysVersion;
if (projectContext.typescript.configFileName) {
commandLine = vue2.createParsedCommandLine(tsdk.typescript, sys, projectContext.typescript.configFileName);
commandLine = createParsedCommandLine(tsdk.typescript, sys, projectContext.typescript.configFileName);
}
newSysVersion = await sys.sync();
}
Expand Down Expand Up @@ -98,20 +94,20 @@ connection.onShutdown(() => {
});

connection.onRequest(ParseSFCRequest.type, params => {
return vue2.parse(params);
return parse(params);
});

connection.onRequest(DetectNameCasingRequest.type, async params => {
const languageService = await getService(params.textDocument.uri);
if (languageService) {
return nameCasing.detect(tsdk.typescript, languageService.context, params.textDocument.uri, envToVueOptions.get(languageService.context.env)!);
return detect(tsdk.typescript, languageService.context, params.textDocument.uri, envToVueOptions.get(languageService.context.env)!);
}
});

connection.onRequest(GetConvertTagCasingEditsRequest.type, async params => {
const languageService = await getService(params.textDocument.uri);
if (languageService) {
return nameCasing.convertTagName(tsdk.typescript, languageService.context, params.textDocument.uri, params.casing, envToVueOptions.get(languageService.context.env)!);
return convertTagName(tsdk.typescript, languageService.context, params.textDocument.uri, params.casing, envToVueOptions.get(languageService.context.env)!);
}
});

Expand All @@ -120,7 +116,7 @@ connection.onRequest(GetConvertAttrCasingEditsRequest.type, async params => {
if (languageService) {
const vueOptions = envToVueOptions.get(languageService.context.env);
if (vueOptions) {
return nameCasing.convertAttrName(tsdk.typescript, languageService.context, params.textDocument.uri, params.casing, envToVueOptions.get(languageService.context.env)!);
return convertAttrName(tsdk.typescript, languageService.context, params.textDocument.uri, params.casing, envToVueOptions.get(languageService.context.env)!);
}
}
});
Expand All @@ -132,7 +128,7 @@ connection.onRequest(GetComponentMeta.type, async params => {

let checker = checkers.get(project);
if (!checker) {
checker = componentMeta.baseCreate(
checker = baseCreate(
tsdk.typescript,
langaugeService.context.language.typescript!.configFileName,
langaugeService.context.language.typescript!.projectHost,
Expand Down
52 changes: 50 additions & 2 deletions packages/language-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
export * from '@volar/language-service';
export * from '@vue/language-core';
export * from './ideFeatures/nameCasing';
export * from './languageService';
export { TagNameCasing, AttrNameCasing } from './types';
export * from './types';

import type { ServiceEnvironment, ServicePlugin } from '@volar/language-service';
import type { VueCompilerOptions } from './types';

import { create as createEmmetServicePlugin } from 'volar-service-emmet';
import { create as createJsonServicePlugin } from 'volar-service-json';
import { create as createPugFormatServicePlugin } from 'volar-service-pug-beautify';
import { create as createTypeScriptTwoslashQueriesServicePlugin } from 'volar-service-typescript-twoslash-queries';
import { create as createCssServicePlugin } from './plugins/css';
import { create as createTypeScriptServicePlugin } from './plugins/typescript';
import { create as createVueAutoDotValueServicePlugin } from './plugins/vue-autoinsert-dotvalue';
import { create as createVueAutoWrapParenthesesServicePlugin } from './plugins/vue-autoinsert-parentheses';
import { create as createVueAutoAddSpaceServicePlugin } from './plugins/vue-autoinsert-space';
import { create as createVueReferencesCodeLensServicePlugin } from './plugins/vue-codelens-references';
import { create as createVueDirectiveCommentsServicePlugin } from './plugins/vue-directive-comments';
import { create as createVueDocumentDropServicePlugin } from './plugins/vue-document-drop';
import { create as createVueExtractFileServicePlugin } from './plugins/vue-extract-file';
import { create as createVueSfcServicePlugin } from './plugins/vue-sfc';
import { create as createVueTemplateServicePlugin } from './plugins/vue-template';
import { create as createVueToggleVBindServicePlugin } from './plugins/vue-toggle-v-bind-codeaction';
import { create as createVueTwoslashQueriesServicePlugin } from './plugins/vue-twoslash-queries';
import { create as createVueVisualizeHiddenCallbackParamServicePlugin } from './plugins/vue-visualize-hidden-callback-param';

export function createVueServicePlugins(
ts: typeof import('typescript'),
getVueOptions: (env: ServiceEnvironment) => VueCompilerOptions,
): ServicePlugin[] {
return [
createTypeScriptServicePlugin(ts, getVueOptions),
createTypeScriptTwoslashQueriesServicePlugin(),
createCssServicePlugin(),
createPugFormatServicePlugin(),
createJsonServicePlugin(),
createVueTemplateServicePlugin('html', ts, getVueOptions),
createVueTemplateServicePlugin('pug', ts, getVueOptions),
createVueSfcServicePlugin(),
createVueTwoslashQueriesServicePlugin(ts),
createVueReferencesCodeLensServicePlugin(),
createVueDocumentDropServicePlugin(ts),
createVueAutoDotValueServicePlugin(ts),
createVueAutoWrapParenthesesServicePlugin(ts),
createVueAutoAddSpaceServicePlugin(),
createVueVisualizeHiddenCallbackParamServicePlugin(),
createVueDirectiveCommentsServicePlugin(),
createVueExtractFileServicePlugin(ts),
createVueToggleVBindServicePlugin(ts),
createEmmetServicePlugin(),
];
}
24 changes: 24 additions & 0 deletions packages/language-service/src/plugins/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ServicePlugin, ServicePluginInstance } from '@volar/language-service';
import { create as baseCreate } from 'volar-service-css';

export function create(): ServicePlugin {
const base = baseCreate({ scssDocumentSelector: ['scss', 'postcss'] });
return {
...base,
create(context): ServicePluginInstance {
const baseInstance = base.create(context);
return {
...baseInstance,
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');
}
return diagnostics;
},
};
},
};
}
Loading
Loading