Skip to content

Commit

Permalink
chore(language-server): only require for tsdk or tsdkUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 30, 2023
1 parent a9dbc9a commit 42bed97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/language-server/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export function startLanguageServer(connection: vscode.Connection, ...plugins: L
},
},
async loadTypeScript(options) {
const tsdkUri = options.typescript?.tsdkUrl;
const tsdkUri = options.typescript && 'tsdkUrl' in options.typescript
? options.typescript.tsdkUrl
: undefined;
if (!tsdkUri) {
return;
}
Expand All @@ -41,7 +43,9 @@ export function startLanguageServer(connection: vscode.Connection, ...plugins: L
return ts as typeof import('typescript/lib/tsserverlibrary');
},
async loadTypeScriptLocalized(options, locale) {
const tsdkUri = options.typescript?.tsdkUrl;
const tsdkUri = options.typescript && 'tsdkUrl' in options.typescript
? options.typescript.tsdkUrl
: undefined;
if (!tsdkUri) {
return;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/language-server/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export function startLanguageServer(connection: vscode.Connection, ...plugins: L
},
},
loadTypeScript(options) {
const tsdk = options.typescript?.tsdk;
const tsdk = options.typescript && 'tsdk' in options.typescript
? options.typescript.tsdk
: undefined;
if (!tsdk) {
return;
}
Expand All @@ -113,7 +115,9 @@ export function startLanguageServer(connection: vscode.Connection, ...plugins: L
throw new Error(`Can't find typescript.js or tsserverlibrary.js in ${tsdk}`);
},
async loadTypeScriptLocalized(options, locale) {
const tsdk = options.typescript?.tsdk;
const tsdk = options.typescript && 'tsdk' in options.typescript
? options.typescript.tsdk
: undefined;
if (!tsdk) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/language-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface InitializationOptions {
* Absolute path to node_modules/typescript/lib, available for node
*/
tsdk: string;
} | {
/**
* URI to node_modules/typescript/lib, available for web
* @example "https://cdn.jsdelivr.net/npm/typescript"
Expand Down

0 comments on commit 42bed97

Please sign in to comment.