Skip to content
Draft
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
15 changes: 5 additions & 10 deletions extensions/vscode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,6 @@ export = defineExtension(() => {
}
});

// Setup typescript.js in production mode
if (fs.existsSync(path.join(__dirname, 'language-server.js'))) {
fs.writeFileSync(
path.join(__dirname, 'typescript.js'),
`module.exports = require("${
vscode.env.appRoot.replace(/\\/g, '/')
}/extensions/node_modules/typescript/lib/typescript.js");`,
);
}

if (config.server.path && !serverPath) {
vscode.window.showErrorMessage('Cannot find @vue/language-server.');
return;
Expand Down Expand Up @@ -152,6 +142,11 @@ function launch(serverPath: string) {
},
},
{
initializationOptions: {
typescript: {
tsdk: `${vscode.env.appRoot.replace(/\\/g, '/')}/extensions/node_modules/typescript/lib`,
},
},
middleware: {
...middleware,
async resolveCodeAction(item, token, next) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/rolldown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const config: RolldownOptions = {
id: /^typescript$/,
},
handler() {
return { id: './typescript.js', external: true };
return { id: 'typescript', external: true };
},
},
},
Expand Down
12 changes: 11 additions & 1 deletion packages/language-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createVueLanguageServicePlugins,
type LanguageService,
} from '@vue/language-service';
import * as ts from 'typescript';
import type * as ts from 'typescript';
import { URI } from 'vscode-uri';

const connection = createConnection();
Expand All @@ -30,6 +30,16 @@ connection.onNotification('tsserver/response', ([id, res]) => {
});

connection.onInitialize(params => {
let ts: typeof import('typescript');
const tsdk = params.initializationOptions?.typescript?.tsdk;
if (tsdk) {
const tsPath = require.resolve('./typescript.js', { paths: [tsdk] });
ts = require(tsPath);
}
else {
ts = require('typescript');
}

const tsconfigProjects = createUriMap<LanguageService>();
const file2ProjectInfo = new Map<string, Promise<ts.server.protocol.ProjectInfo | null>>();

Expand Down
Loading