Skip to content

Commit

Permalink
refactor: remove root path depend for vue.createLanguageModules
Browse files Browse the repository at this point in the history
plugin path already resolved by vue-language-core
  • Loading branch information
johnsoncodehk committed Dec 31, 2022
1 parent 82347c8 commit a219c7f
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 19 deletions.
1 change: 0 additions & 1 deletion examples/vue-and-svelte-language-server/package.json
Expand Up @@ -19,7 +19,6 @@
"@volar-examples/svelte-language-core": "1.0.19",
"@volar-plugins/typescript": "1.0.19",
"@volar/language-server": "1.0.19",
"@volar/shared": "1.0.19",
"@volar/vue-language-core": "1.0.19"
}
}
6 changes: 2 additions & 4 deletions examples/vue-and-svelte-language-server/src/index.ts
@@ -1,7 +1,6 @@
import { languageModule as svelteLanguageModule } from '@volar-examples/svelte-language-core';
import useTsPlugin from '@volar-plugins/typescript';
import { createLanguageServer, LanguageModule, LanguageServerInitializationOptions, LanguageServerPlugin } from '@volar/language-server/node';
import * as shared from '@volar/shared';
import * as vue from '@volar/vue-language-core';

const plugin: LanguageServerPlugin<LanguageServerInitializationOptions, vue.LanguageServiceHost> = () => {
Expand All @@ -24,7 +23,6 @@ const plugin: LanguageServerPlugin<LanguageServerInitializationOptions, vue.Lang
getLanguageModules(host) {
const vueLanguageModules = vue.createLanguageModules(
host.getTypeScriptModule(),
host.getCurrentDirectory(),
host.getCompilationSettings(),
host.getVueCompilationSettings(),
);
Expand All @@ -40,8 +38,8 @@ const plugin: LanguageServerPlugin<LanguageServerInitializationOptions, vue.Lang
},
},
syntacticService: {
getLanguageModules(ts, env) {
const vueLanguagePlugins = vue.getDefaultVueLanguagePlugins(ts, shared.getPathOfUri(env.rootUri.toString()), {}, {}, []);
getLanguageModules(ts) {
const vueLanguagePlugins = vue.getDefaultVueLanguagePlugins(ts, {}, {}, []);
const vueLanguageModule: LanguageModule = {
createFile(fileName, snapshot) {
if (fileName.endsWith('.vue')) {
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vue-language-tools/vue-component-meta/src/index.ts
Expand Up @@ -170,7 +170,6 @@ export function baseCreate(
}) as vue.LanguageServiceHost;
const vueLanguageModules = vue.createLanguageModules(
host.getTypeScriptModule(),
host.getCurrentDirectory(),
host.getCompilationSettings(),
host.getVueCompilationSettings(),
);
Expand Down
2 changes: 0 additions & 2 deletions vue-language-tools/vue-language-core/src/languageModule.ts
Expand Up @@ -9,7 +9,6 @@ import type * as ts from 'typescript/lib/tsserverlibrary';

export function createLanguageModules(
ts: typeof import('typescript/lib/tsserverlibrary'),
rootDir: string,
compilerOptions: ts.CompilerOptions,
_vueCompilerOptions: VueCompilerOptions,
extraPlugins: VueLanguagePlugin[] = [],
Expand All @@ -18,7 +17,6 @@ export function createLanguageModules(
const vueCompilerOptions = resolveVueCompilerOptions(_vueCompilerOptions);
const vueLanguagePlugin = getDefaultVueLanguagePlugins(
ts,
rootDir,
compilerOptions,
_vueCompilerOptions,
extraPlugins,
Expand Down
3 changes: 1 addition & 2 deletions vue-language-tools/vue-language-core/src/plugins.ts
Expand Up @@ -16,7 +16,6 @@ import * as CompilerVue2 from './utils/vue2TemplateCompiler';

export function getDefaultVueLanguagePlugins(
ts: typeof import('typescript/lib/tsserverlibrary'),
rootDir: string,
compilerOptions: ts.CompilerOptions,
_vueCompilerOptions: VueCompilerOptions,
extraPlugins: VueLanguagePlugin[] = [],
Expand All @@ -39,7 +38,7 @@ export function getDefaultVueLanguagePlugins(
if (typeof require?.resolve === 'function') {
for (const pluginPath of vueCompilerOptions.plugins) {
try {
const importPath = require.resolve(pluginPath, { paths: [rootDir] });
const importPath = require.resolve(pluginPath);
const plugin = require(importPath);
pluginPaths.set(_plugins.length, pluginPath);
_plugins.push(plugin);
Expand Down
Expand Up @@ -44,7 +44,6 @@ const plugin: LanguageServerPlugin<VueServerInitializationOptions, vue.LanguageS
getLanguageModules(host) {
const vueLanguageModules = vue2.createLanguageModules(
host.getTypeScriptModule(),
host.getCurrentDirectory(),
host.getCompilationSettings(),
host.getVueCompilationSettings(),
);
Expand Down Expand Up @@ -106,9 +105,9 @@ const plugin: LanguageServerPlugin<VueServerInitializationOptions, vue.LanguageS
},
},
syntacticService: {
getLanguageModules(ts, env) {
getLanguageModules(ts) {
const vueOptions: vue.VueCompilerOptions = { extensions: getVueExts(['.vue']) };
const vueLanguagePlugins = vue2.getDefaultVueLanguagePlugins(ts, shared.getPathOfUri(env.rootUri.toString()), {}, vueOptions, []);
const vueLanguagePlugins = vue2.getDefaultVueLanguagePlugins(ts, {}, vueOptions, []);
const vueLanguageModule: embedded.LanguageModule = {
createFile(fileName, snapshot) {
if (vueOptions.extensions?.some(ext => fileName.endsWith(ext))) {
Expand Down
Expand Up @@ -10,7 +10,6 @@ import useAutoWrapParenthesesPlugin from './plugins/vue-autoinsert-parentheses';
import useAutoAddSpacePlugin from './plugins/vue-autoinsert-space';
import * as embeddedLS from '@volar/language-service';
import * as vue from '@volar/vue-language-core';
import * as shared from '@volar/shared';

import type * as _1 from 'vscode-languageserver-protocol';
import type * as _2 from 'vscode-languageserver-textdocument';
Expand Down Expand Up @@ -57,7 +56,6 @@ export function createDocumentService(

const vueLanguageModules = vue.createLanguageModules(
ts,
shared.getPathOfUri(env.rootUri.toString()),
{},
{},
);
Expand Down
Expand Up @@ -239,7 +239,6 @@ export function createLanguageService(

const vueLanguageModules = vue.createLanguageModules(
host.getTypeScriptModule(),
host.getCurrentDirectory(),
host.getCompilationSettings(),
host.getVueCompilationSettings(),
);
Expand Down
1 change: 0 additions & 1 deletion vue-language-tools/vue-typescript/src/index.ts
Expand Up @@ -4,7 +4,6 @@ import * as vue from '@volar/vue-language-core';
export function createLanguageService(host: vue.LanguageServiceHost) {
return base.createLanguageService(host, vue.createLanguageModules(
host.getTypeScriptModule(),
host.getCurrentDirectory(),
host.getCompilationSettings(),
host.getVueCompilationSettings(),
));
Expand Down

0 comments on commit a219c7f

Please sign in to comment.