aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-15 21:05:07 +0100
committerGitHub <[email protected]>2021-06-15 21:05:07 +0100
commitd0f2bc3b878d1c1d8eaf081e6f670ebb928b7a5f (patch)
treed704be44422c3fe3981a43055a336141a88922c9 /editors
parentdcea1c536c351a6063ba887813d54911a2b7eb39 (diff)
parenta6b0c056dedb17fa2056e5186bd73af66c5e84e3 (diff)
Merge #9292
9292: fix: Code: clean-up #8951 r=wxb1ank a=wxb1ank #8951 was a major change in the VS Code extension and caused quite a few problems. This PR is a catch-all for bugs and improvements in the new code. This should fix: - #9284 - [this unreported bug](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) - ...and one or two uncaught exceptions I just found The original lack of testing was my own fault, but this area of the VS Code API is also tricky for a couple reasons: - The [FileSystem](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) API does not list or warn about any exceptions, but [FileSystemProvider](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) (which `FileSystem` is a wrapper of, AFAICT) does. - At first glance, [Uri.path](https://github.com/rust-analyzer/rust-analyzer/pull/8951/files#r651570446) *looks* like it works for FS operations. It does not, at least, on Windows. You need to use `Uri.fsPath`. I only use Windows, so I need people on macOS, Linux, and (possibly) NixOS to test this. Co-authored-by: wxb1ank <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/main.ts14
-rw-r--r--editors/code/src/net.ts8
-rw-r--r--editors/code/src/toolchain.ts16
3 files changed, 23 insertions, 15 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index f58d26215..15f2151ad 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -158,7 +158,7 @@ export async function deactivate() {
158} 158}
159 159
160async function bootstrap(config: Config, state: PersistentState): Promise<string> { 160async function bootstrap(config: Config, state: PersistentState): Promise<string> {
161 await vscode.workspace.fs.createDirectory(config.globalStorageUri); 161 await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
162 162
163 if (!config.currentExtensionIsNightly) { 163 if (!config.currentExtensionIsNightly) {
164 await state.updateNightlyReleaseId(undefined); 164 await state.updateNightlyReleaseId(undefined);
@@ -277,11 +277,11 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
277 ''; 277 '';
278 } 278 }
279 `; 279 `;
280 const origFile = vscode.Uri.file(dest.path + "-orig"); 280 const origFile = vscode.Uri.file(dest.fsPath + "-orig");
281 await vscode.workspace.fs.rename(dest, origFile); 281 await vscode.workspace.fs.rename(dest, origFile);
282 progress.report({ message: "Patching executable", increment: 20 }); 282 progress.report({ message: "Patching executable", increment: 20 });
283 await new Promise((resolve, reject) => { 283 await new Promise((resolve, reject) => {
284 const handle = exec(`nix-build -E - --argstr srcStr '${origFile.path}' -o '${dest.path}'`, 284 const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`,
285 (err, stdout, stderr) => { 285 (err, stdout, stderr) => {
286 if (err != null) { 286 if (err != null) {
287 reject(Error(stderr)); 287 reject(Error(stderr));
@@ -338,14 +338,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string
338 await state.updateServerVersion(undefined); 338 await state.updateServerVersion(undefined);
339 } 339 }
340 340
341 if (state.serverVersion === config.package.version) return dest.path; 341 if (state.serverVersion === config.package.version) return dest.fsPath;
342 342
343 if (config.askBeforeDownload) { 343 if (config.askBeforeDownload) {
344 const userResponse = await vscode.window.showInformationMessage( 344 const userResponse = await vscode.window.showInformationMessage(
345 `Language server version ${config.package.version} for rust-analyzer is not installed.`, 345 `Language server version ${config.package.version} for rust-analyzer is not installed.`,
346 "Download now" 346 "Download now"
347 ); 347 );
348 if (userResponse !== "Download now") return dest.path; 348 if (userResponse !== "Download now") return dest.fsPath;
349 } 349 }
350 350
351 const releaseTag = config.package.releaseTag; 351 const releaseTag = config.package.releaseTag;
@@ -372,7 +372,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
372 } 372 }
373 373
374 await state.updateServerVersion(config.package.version); 374 await state.updateServerVersion(config.package.version);
375 return dest.path; 375 return dest.fsPath;
376} 376}
377 377
378function serverPath(config: Config): string | null { 378function serverPath(config: Config): string | null {
@@ -383,7 +383,7 @@ async function isNixOs(): Promise<boolean> {
383 try { 383 try {
384 const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString(); 384 const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString();
385 return contents.indexOf("ID=nixos") !== -1; 385 return contents.indexOf("ID=nixos") !== -1;
386 } catch (e) { 386 } catch {
387 return false; 387 return false;
388 } 388 }
389} 389}
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts
index 5c48c74e8..722dab756 100644
--- a/editors/code/src/net.ts
+++ b/editors/code/src/net.ts
@@ -91,7 +91,7 @@ export async function download(opts: DownloadOpts) {
91 // to prevent partially downloaded files when user kills vscode 91 // to prevent partially downloaded files when user kills vscode
92 // This also avoids overwriting running executables 92 // This also avoids overwriting running executables
93 const randomHex = crypto.randomBytes(5).toString("hex"); 93 const randomHex = crypto.randomBytes(5).toString("hex");
94 const rawDest = path.parse(opts.dest.path); 94 const rawDest = path.parse(opts.dest.fsPath);
95 const tempFilePath = vscode.Uri.joinPath(vscode.Uri.file(rawDest.dir), `${rawDest.name}${randomHex}`); 95 const tempFilePath = vscode.Uri.joinPath(vscode.Uri.file(rawDest.dir), `${rawDest.name}${randomHex}`);
96 96
97 await vscode.window.withProgress( 97 await vscode.window.withProgress(
@@ -116,7 +116,7 @@ export async function download(opts: DownloadOpts) {
116 } 116 }
117 ); 117 );
118 118
119 await vscode.workspace.fs.rename(tempFilePath, opts.dest); 119 await vscode.workspace.fs.rename(tempFilePath, opts.dest, { overwrite: true });
120} 120}
121 121
122async function downloadFile( 122async function downloadFile(
@@ -148,7 +148,7 @@ async function downloadFile(
148 const totalBytes = Number(res.headers.get('content-length')); 148 const totalBytes = Number(res.headers.get('content-length'));
149 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); 149 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol");
150 150
151 log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.path); 151 log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.fsPath);
152 152
153 let readBytes = 0; 153 let readBytes = 0;
154 res.body.on("data", (chunk: Buffer) => { 154 res.body.on("data", (chunk: Buffer) => {
@@ -156,7 +156,7 @@ async function downloadFile(
156 onProgress(readBytes, totalBytes); 156 onProgress(readBytes, totalBytes);
157 }); 157 });
158 158
159 const destFileStream = fs.createWriteStream(destFilePath.path, { mode }); 159 const destFileStream = fs.createWriteStream(destFilePath.fsPath, { mode });
160 const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; 160 const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body;
161 161
162 await pipeline(srcStream, destFileStream); 162 await pipeline(srcStream, destFileStream);
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index 902d0ddda..355dd76fe 100644
--- a/editors/code/src/toolchain.ts
+++ b/editors/code/src/toolchain.ts
@@ -159,7 +159,7 @@ export const getPathForExecutable = memoize(
159 // it is not mentioned in docs and cannot be infered by the type signature... 159 // it is not mentioned in docs and cannot be infered by the type signature...
160 const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); 160 const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName);
161 161
162 if (isFile(standardPath.path)) return standardPath.path; 162 if (isFileAtUri(standardPath)) return standardPath.fsPath;
163 } catch (err) { 163 } catch (err) {
164 log.error("Failed to read the fs info", err); 164 log.error("Failed to read the fs info", err);
165 } 165 }
@@ -177,9 +177,17 @@ function lookupInPath(exec: string): boolean {
177 : [candidate]; 177 : [candidate];
178 }); 178 });
179 179
180 return candidates.some(isFile); 180 return candidates.some(isFileAtPath);
181} 181}
182 182
183async function isFile(path: string): Promise<boolean> { 183async function isFileAtPath(path: string): Promise<boolean> {
184 return ((await vscode.workspace.fs.stat(vscode.Uri.file(path))).type & vscode.FileType.File) !== 0; 184 return isFileAtUri(vscode.Uri.file(path));
185}
186
187async function isFileAtUri(uri: vscode.Uri): Promise<boolean> {
188 try {
189 return ((await vscode.workspace.fs.stat(uri)).type & vscode.FileType.File) !== 0;
190 } catch {
191 return false;
192 }
185} 193}