aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorwxb1ank <[email protected]>2021-06-15 18:29:02 +0100
committerwxb1ank <[email protected]>2021-06-15 18:29:02 +0100
commit56e128a979082de4ea58b7739049405fbc43f394 (patch)
tree5f85baa3fc4c36162ff2ea3011b796bf6ff56bf2 /editors/code
parent7a8a72c38f5626aea6c8f3c2dacbb23ed166901e (diff)
fix: clean-up #8951
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/main.ts16
-rw-r--r--editors/code/src/net.ts8
-rw-r--r--editors/code/src/toolchain.ts16
3 files changed, 25 insertions, 15 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index f58d26215..049d6cb8e 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -158,7 +158,9 @@ 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 try {
162 await vscode.workspace.fs.createDirectory(config.globalStorageUri);
163 } catch {}
162 164
163 if (!config.currentExtensionIsNightly) { 165 if (!config.currentExtensionIsNightly) {
164 await state.updateNightlyReleaseId(undefined); 166 await state.updateNightlyReleaseId(undefined);
@@ -277,11 +279,11 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
277 ''; 279 '';
278 } 280 }
279 `; 281 `;
280 const origFile = vscode.Uri.file(dest.path + "-orig"); 282 const origFile = vscode.Uri.file(dest.fsPath + "-orig");
281 await vscode.workspace.fs.rename(dest, origFile); 283 await vscode.workspace.fs.rename(dest, origFile);
282 progress.report({ message: "Patching executable", increment: 20 }); 284 progress.report({ message: "Patching executable", increment: 20 });
283 await new Promise((resolve, reject) => { 285 await new Promise((resolve, reject) => {
284 const handle = exec(`nix-build -E - --argstr srcStr '${origFile.path}' -o '${dest.path}'`, 286 const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`,
285 (err, stdout, stderr) => { 287 (err, stdout, stderr) => {
286 if (err != null) { 288 if (err != null) {
287 reject(Error(stderr)); 289 reject(Error(stderr));
@@ -338,14 +340,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string
338 await state.updateServerVersion(undefined); 340 await state.updateServerVersion(undefined);
339 } 341 }
340 342
341 if (state.serverVersion === config.package.version) return dest.path; 343 if (state.serverVersion === config.package.version) return dest.fsPath;
342 344
343 if (config.askBeforeDownload) { 345 if (config.askBeforeDownload) {
344 const userResponse = await vscode.window.showInformationMessage( 346 const userResponse = await vscode.window.showInformationMessage(
345 `Language server version ${config.package.version} for rust-analyzer is not installed.`, 347 `Language server version ${config.package.version} for rust-analyzer is not installed.`,
346 "Download now" 348 "Download now"
347 ); 349 );
348 if (userResponse !== "Download now") return dest.path; 350 if (userResponse !== "Download now") return dest.fsPath;
349 } 351 }
350 352
351 const releaseTag = config.package.releaseTag; 353 const releaseTag = config.package.releaseTag;
@@ -372,7 +374,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
372 } 374 }
373 375
374 await state.updateServerVersion(config.package.version); 376 await state.updateServerVersion(config.package.version);
375 return dest.path; 377 return dest.fsPath;
376} 378}
377 379
378function serverPath(config: Config): string | null { 380function serverPath(config: Config): string | null {
@@ -383,7 +385,7 @@ async function isNixOs(): Promise<boolean> {
383 try { 385 try {
384 const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString(); 386 const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString();
385 return contents.indexOf("ID=nixos") !== -1; 387 return contents.indexOf("ID=nixos") !== -1;
386 } catch (e) { 388 } catch {
387 return false; 389 return false;
388 } 390 }
389} 391}
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}