Skip to content

Commit a500ccd

Browse files
committed
feat(language-server): add back typescript.tsdk initialization option
1 parent e9da626 commit a500ccd

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

extensions/vscode/index.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ export = defineExtension(() => {
9090
}
9191
});
9292

93-
// Setup typescript.js in production mode
94-
if (fs.existsSync(path.join(__dirname, 'language-server.js'))) {
95-
fs.writeFileSync(
96-
path.join(__dirname, 'typescript.js'),
97-
`module.exports = require("${
98-
vscode.env.appRoot.replace(/\\/g, '/')
99-
}/extensions/node_modules/typescript/lib/typescript.js");`,
100-
);
101-
}
102-
10393
if (config.server.path && !serverPath) {
10494
vscode.window.showErrorMessage('Cannot find @vue/language-server.');
10595
return;
@@ -152,6 +142,11 @@ function launch(serverPath: string) {
152142
},
153143
},
154144
{
145+
initializationOptions: {
146+
typescript: {
147+
tsdk: `${vscode.env.appRoot.replace(/\\/g, '/')}/extensions/node_modules/typescript/lib`,
148+
},
149+
},
155150
middleware: {
156151
...middleware,
157152
async resolveCodeAction(item, token, next) {

extensions/vscode/rolldown.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const config: RolldownOptions = {
6767
id: /^typescript$/,
6868
},
6969
handler() {
70-
return { id: './typescript.js', external: true };
70+
return { id: 'typescript', external: true };
7171
},
7272
},
7373
},

packages/language-server/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createVueLanguageServicePlugins,
1414
type LanguageService,
1515
} from '@vue/language-service';
16-
import * as ts from 'typescript';
16+
import type * as ts from 'typescript';
1717
import { URI } from 'vscode-uri';
1818

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

3232
connection.onInitialize(params => {
33+
let ts: typeof import('typescript');
34+
const tsdk = params.initializationOptions?.typescript?.tsdk;
35+
if (tsdk) {
36+
const tsPath = require.resolve('./typescript.js', { paths: [tsdk] });
37+
ts = require(tsPath);
38+
}
39+
else {
40+
ts = require('typescript');
41+
}
42+
3343
const tsconfigProjects = createUriMap<LanguageService>();
3444
const file2ProjectInfo = new Map<string, Promise<ts.server.protocol.ProjectInfo | null>>();
3545

0 commit comments

Comments
 (0)