@volar/vscode 2.3.0-alpha.4 → 2.3.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,6 @@ import * as vscode from 'vscode';
2
2
  export declare function activate(selector: vscode.DocumentSelector, cmd: string, context: vscode.ExtensionContext, resolveStatusText: (text: string) => string, onRestart?: () => void): vscode.Disposable;
3
3
  export declare function getTsdk(context: vscode.ExtensionContext): Promise<{
4
4
  tsdk: string;
5
- version: string | undefined;
5
+ version: string;
6
6
  isWorkspacePath: boolean;
7
- }>;
7
+ } | undefined>;
@@ -6,6 +6,7 @@ const vscode = require("vscode");
6
6
  const common_1 = require("../common");
7
7
  const fs = require("../fs");
8
8
  const defaultTsdkPath = 'node_modules/typescript/lib';
9
+ const tsdkSetting = 'typescript.tsdk';
9
10
  function activate(selector, cmd, context, resolveStatusText, onRestart) {
10
11
  const subscriptions = [];
11
12
  const statusBar = vscode.languages.createLanguageStatusItem(cmd, selector);
@@ -22,21 +23,31 @@ function activate(selector, cmd, context, resolveStatusText, onRestart) {
22
23
  async function onCommand() {
23
24
  const tsdk = await getTsdk(context);
24
25
  const configTsdkPath = getConfigTsdkPath();
25
- const vscodeTsdk = await getVScodeTsdk();
26
+ const vscodeTsdk = await getVSCodeTsdk();
27
+ const useVSCodeTsdk = !!vscodeTsdk;
28
+ const useConfigWorkspaceTsdk = !!configTsdkPath && !vscodeTsdk?.isWeb;
29
+ const useDefaultWorkspaceTsdk = configTsdkPath !== defaultTsdkPath && !vscodeTsdk?.isWeb;
30
+ if (!useVSCodeTsdk && !useConfigWorkspaceTsdk && !useDefaultWorkspaceTsdk) { // found no usable TypeScript version
31
+ const messageResult = await vscode.window.showErrorMessage(`Could not find any TypeScript version. Please point your \`${tsdkSetting}\` setting to a valid TypeScript distribution.`, 'Open Settings');
32
+ if (messageResult === 'Open Settings') {
33
+ vscode.commands.executeCommand('workbench.action.openSettings', tsdkSetting);
34
+ }
35
+ return;
36
+ }
26
37
  const select = await (0, common_1.quickPick)([
27
38
  {
28
- useVSCodeTsdk: {
29
- label: (!tsdk.isWorkspacePath ? '• ' : '') + "Use VS Code's Version",
39
+ useVSCodeTsdk: useVSCodeTsdk ? {
40
+ label: (!tsdk?.isWorkspacePath ? '• ' : '') + "Use VS Code's Version",
30
41
  description: vscodeTsdk.version,
31
42
  detail: vscodeTsdk.isWeb ? vscodeTsdk.path : undefined,
32
- },
33
- useConfigWorkspaceTsdk: configTsdkPath && !vscodeTsdk.isWeb ? {
34
- label: (tsdk.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
43
+ } : undefined,
44
+ useConfigWorkspaceTsdk: useConfigWorkspaceTsdk ? {
45
+ label: (tsdk?.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
35
46
  description: await getTsVersion(await resolveWorkspaceTsdk(configTsdkPath) ?? '/') ?? 'Could not load the TypeScript version at this path',
36
47
  detail: configTsdkPath,
37
48
  } : undefined,
38
- useDefaultWorkspaceTsdk: configTsdkPath !== defaultTsdkPath && !vscodeTsdk.isWeb ? {
39
- label: (tsdk.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
49
+ useDefaultWorkspaceTsdk: useDefaultWorkspaceTsdk ? {
50
+ label: (tsdk?.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
40
51
  description: await getTsVersion(await resolveWorkspaceTsdk(defaultTsdkPath) ?? '/') ?? 'Could not load the TypeScript version at this path',
41
52
  detail: defaultTsdkPath,
42
53
  } : undefined,
@@ -56,12 +67,12 @@ function activate(selector, cmd, context, resolveStatusText, onRestart) {
56
67
  updateStatusBar();
57
68
  }
58
69
  function onDidChangeConfiguration(e) {
59
- if (e.affectsConfiguration('typescript.tsdk') && isUseWorkspaceTsdk(context)) {
70
+ if (e.affectsConfiguration(tsdkSetting) && isUseWorkspaceTsdk(context)) {
60
71
  onRestart?.();
61
72
  }
62
73
  }
63
74
  async function updateStatusBar() {
64
- const tsVersion = (await getTsdk(context)).version;
75
+ const tsVersion = (await getTsdk(context))?.version;
65
76
  statusBar.text = tsVersion ?? 'x.x.x';
66
77
  statusBar.text = resolveStatusText(statusBar.text);
67
78
  }
@@ -73,20 +84,23 @@ async function getTsdk(context) {
73
84
  if (tsdkPath) {
74
85
  const resolvedTsdk = await resolveWorkspaceTsdk(tsdkPath);
75
86
  if (resolvedTsdk) {
76
- return {
77
- tsdk: resolvedTsdk,
78
- version: await getTsVersion(resolvedTsdk),
79
- isWorkspacePath: true,
80
- };
87
+ const version = await getTsVersion(resolvedTsdk);
88
+ if (version !== undefined) {
89
+ return {
90
+ tsdk: resolvedTsdk,
91
+ version,
92
+ isWorkspacePath: true,
93
+ };
94
+ }
81
95
  }
82
96
  }
83
97
  }
84
- const tsdk = await getVScodeTsdk();
85
- return {
98
+ const tsdk = await getVSCodeTsdk();
99
+ return tsdk ? {
86
100
  tsdk: tsdk.path,
87
101
  version: tsdk.version,
88
102
  isWorkspacePath: false,
89
- };
103
+ } : undefined;
90
104
  }
91
105
  exports.getTsdk = getTsdk;
92
106
  async function resolveWorkspaceTsdk(tsdk) {
@@ -108,23 +122,25 @@ async function resolveWorkspaceTsdk(tsdk) {
108
122
  }
109
123
  }
110
124
  }
111
- async function getVScodeTsdk() {
125
+ async function getVSCodeTsdk() {
112
126
  const nightly = vscode.extensions.getExtension('ms-vscode.vscode-typescript-next');
113
127
  if (nightly) {
114
128
  const libPath = path.join(nightly.extensionPath.replace(/\\/g, '/'), 'node_modules/typescript/lib');
115
- return {
129
+ const version = await getTsVersion(libPath);
130
+ return version ? {
116
131
  path: libPath,
117
- version: await getTsVersion(libPath),
132
+ version: version,
118
133
  isWeb: false,
119
- };
134
+ } : undefined;
120
135
  }
121
136
  if (vscode.env.appRoot) {
122
137
  const libPath = path.join(vscode.env.appRoot.replace(/\\/g, '/'), 'extensions/node_modules/typescript/lib');
123
- return {
138
+ const version = await getTsVersion(libPath);
139
+ return version ? {
124
140
  path: libPath,
125
- version: await getTsVersion(libPath),
141
+ version: version,
126
142
  isWeb: false,
127
- };
143
+ } : undefined;
128
144
  }
129
145
  // web
130
146
  const version = require('typescript/package.json').version;
@@ -145,20 +161,19 @@ async function getTsVersion(libPath) {
145
161
  const p2 = p.slice(0, -1);
146
162
  const modulePath = p2.join('/');
147
163
  const filePath = modulePath + '/package.json';
148
- const contents = await fs.readFile(vscode.Uri.file(filePath));
149
- if (contents === undefined) {
150
- return;
151
- }
152
- let desc = null;
153
164
  try {
154
- desc = JSON.parse(contents);
155
- }
156
- catch (err) {
157
- return;
165
+ const contents = await fs.readFile(vscode.Uri.file(filePath));
166
+ if (contents === undefined) {
167
+ return;
168
+ }
169
+ const desc = JSON.parse(contents);
170
+ if (!desc || typeof desc.version !== 'string') {
171
+ return;
172
+ }
173
+ return desc.version;
158
174
  }
159
- if (!desc || !desc.version) {
175
+ catch {
160
176
  return;
161
177
  }
162
- return desc.version;
163
178
  }
164
179
  //# sourceMappingURL=tsVersion.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/vscode",
3
- "version": "2.3.0-alpha.4",
3
+ "version": "2.3.0-alpha.6",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/vscode"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-server": "2.3.0-alpha.4",
15
+ "@volar/language-server": "2.3.0-alpha.6",
16
16
  "path-browserify": "^1.0.1",
17
17
  "vscode-languageclient": "^9.0.1",
18
18
  "vscode-nls": "^5.2.0"
@@ -22,5 +22,5 @@
22
22
  "@types/path-browserify": "latest",
23
23
  "@types/vscode": "^1.82.0"
24
24
  },
25
- "gitHead": "8ab3ce02b06a410e9321eea3e9f23d36f97fedda"
25
+ "gitHead": "f3103e86be8d80cb36f66be4c054ef9a255c29b1"
26
26
  }