@volar/vscode 2.2.0-alpha.9 → 2.2.0-patch.1

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.
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.activate = void 0;
4
4
  const vscode = require("vscode");
5
5
  const protocol_1 = require("@volar/language-server/protocol");
6
+ const fs = require("../fs");
6
7
  function activate(client) {
7
8
  const subscriptions = [];
8
- const textDecoder = new TextDecoder();
9
9
  const jobs = new Map();
10
10
  const progressAssets = new Set();
11
11
  let startProgress = false;
@@ -70,7 +70,7 @@ function activate(client) {
70
70
  return;
71
71
  }
72
72
  const uri2 = client.protocol2CodeConverter.asUri(uri);
73
- return await _stat(uri2);
73
+ return await fs.stat(uri2);
74
74
  }
75
75
  async function readFile(uri) {
76
76
  // return early
@@ -81,33 +81,13 @@ function activate(client) {
81
81
  if (!entries.some(entry => entry[0] === baseName && entry[1] === vscode.FileType.File)) {
82
82
  return;
83
83
  }
84
- return await _readFile(uri2);
84
+ return await fs.readFile(uri2);
85
85
  }
86
86
  async function readDirectory(uri) {
87
87
  const uri2 = client.protocol2CodeConverter.asUri(uri);
88
- return await (await _readDirectory(uri2))
88
+ return await (await fs.readDirectory(uri2))
89
89
  .filter(([name]) => !name.startsWith('.'));
90
90
  }
91
- async function _readFile(uri) {
92
- try {
93
- return textDecoder.decode(await vscode.workspace.fs.readFile(uri));
94
- }
95
- catch { }
96
- }
97
- async function _readDirectory(uri) {
98
- try {
99
- return await vscode.workspace.fs.readDirectory(uri);
100
- }
101
- catch {
102
- return [];
103
- }
104
- }
105
- async function _stat(uri) {
106
- try {
107
- return await vscode.workspace.fs.stat(uri);
108
- }
109
- catch { }
110
- }
111
91
  }
112
92
  }
113
93
  exports.activate = activate;
@@ -4,6 +4,7 @@ exports.getTsdk = exports.activate = void 0;
4
4
  const path = require("path-browserify");
5
5
  const vscode = require("vscode");
6
6
  const common_1 = require("../common");
7
+ const fs = require("../fs");
7
8
  const defaultTsdkPath = 'node_modules/typescript/lib';
8
9
  function activate(selector, cmd, context, client, resolveStatusText) {
9
10
  const subscriptions = [];
@@ -77,13 +78,16 @@ function activate(selector, cmd, context, client, resolveStatusText) {
77
78
  exports.activate = activate;
78
79
  async function getTsdk(context) {
79
80
  if (isUseWorkspaceTsdk(context)) {
80
- const resolvedTsdk = await resolveWorkspaceTsdk(getConfigTsdkPath() || defaultTsdkPath);
81
- if (resolvedTsdk) {
82
- return {
83
- tsdk: resolvedTsdk,
84
- version: await getTsVersion(resolvedTsdk),
85
- isWorkspacePath: true,
86
- };
81
+ const tsdkPath = getConfigTsdkPath();
82
+ if (tsdkPath) {
83
+ const resolvedTsdk = await resolveWorkspaceTsdk(tsdkPath);
84
+ if (resolvedTsdk) {
85
+ return {
86
+ tsdk: resolvedTsdk,
87
+ version: await getTsVersion(resolvedTsdk),
88
+ isWorkspacePath: true,
89
+ };
90
+ }
87
91
  }
88
92
  }
89
93
  const tsdk = await getVScodeTsdk();
@@ -97,8 +101,8 @@ exports.getTsdk = getTsdk;
97
101
  async function resolveWorkspaceTsdk(tsdk) {
98
102
  if (path.isAbsolute(tsdk)) {
99
103
  const libUri = vscode.Uri.joinPath(vscode.Uri.file(tsdk), 'typescript.js');
100
- const stat = await vscode.workspace.fs.stat(libUri);
101
- if (stat.type === vscode.FileType.File) {
104
+ const stat = await fs.stat(libUri);
105
+ if (stat?.type === vscode.FileType.File) {
102
106
  return tsdk;
103
107
  }
104
108
  }
@@ -106,8 +110,8 @@ async function resolveWorkspaceTsdk(tsdk) {
106
110
  for (const folder of vscode.workspace.workspaceFolders) {
107
111
  const tsdkPath = path.join(folder.uri.fsPath.replace(/\\/g, '/'), tsdk);
108
112
  const libUri = vscode.Uri.joinPath(vscode.Uri.file(tsdkPath), 'typescript.js');
109
- const stat = await vscode.workspace.fs.stat(libUri);
110
- if (stat.type === vscode.FileType.File) {
113
+ const stat = await fs.stat(libUri);
114
+ if (stat?.type === vscode.FileType.File) {
111
115
  return tsdkPath;
112
116
  }
113
117
  }
@@ -150,7 +154,7 @@ async function getTsVersion(libPath) {
150
154
  const p2 = p.slice(0, -1);
151
155
  const modulePath = p2.join('/');
152
156
  const filePath = modulePath + '/package.json';
153
- const contents = await readFile(filePath);
157
+ const contents = await fs.readFile(vscode.Uri.file(filePath));
154
158
  if (contents === undefined) {
155
159
  return;
156
160
  }
@@ -166,11 +170,4 @@ async function getTsVersion(libPath) {
166
170
  }
167
171
  return desc.version;
168
172
  }
169
- async function readFile(path) {
170
- try {
171
- const data = await vscode.workspace.fs.readFile(vscode.Uri.file(path));
172
- return new TextDecoder('utf8').decode(data);
173
- }
174
- catch { }
175
- }
176
173
  //# sourceMappingURL=tsVersion.js.map
package/lib/fs.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import * as vscode from 'vscode';
2
+ export declare function readFile(uri: vscode.Uri): Promise<string | undefined>;
3
+ export declare function readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]>;
4
+ export declare function stat(uri: vscode.Uri): Promise<vscode.FileStat | undefined>;
package/lib/fs.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stat = exports.readDirectory = exports.readFile = void 0;
4
+ const vscode = require("vscode");
5
+ const textDecoder = new TextDecoder('utf8');
6
+ async function readFile(uri) {
7
+ try {
8
+ return textDecoder.decode(await vscode.workspace.fs.readFile(uri));
9
+ }
10
+ catch { }
11
+ }
12
+ exports.readFile = readFile;
13
+ async function readDirectory(uri) {
14
+ try {
15
+ return await vscode.workspace.fs.readDirectory(uri);
16
+ }
17
+ catch {
18
+ return [];
19
+ }
20
+ }
21
+ exports.readDirectory = readDirectory;
22
+ async function stat(uri) {
23
+ try {
24
+ return await vscode.workspace.fs.stat(uri);
25
+ }
26
+ catch { }
27
+ }
28
+ exports.stat = stat;
29
+ //# sourceMappingURL=fs.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/vscode",
3
- "version": "2.2.0-alpha.9",
3
+ "version": "2.2.0-patch.1",
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.2.0-alpha.9",
15
+ "@volar/language-server": "2.2.0-patch.1",
16
16
  "path-browserify": "^1.0.1",
17
17
  "vscode-languageclient": "^9.0.1",
18
18
  "vscode-nls": "^5.2.0"
@@ -21,6 +21,5 @@
21
21
  "@types/node": "latest",
22
22
  "@types/path-browserify": "latest",
23
23
  "@types/vscode": "^1.82.0"
24
- },
25
- "gitHead": "7373fb794012e219aae3948c730c004827b03021"
24
+ }
26
25
  }