diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands.ts | 5 | ||||
-rw-r--r-- | editors/code/src/config.ts | 8 | ||||
-rw-r--r-- | editors/code/src/main.ts | 6 | ||||
-rw-r--r-- | editors/code/src/net.ts | 25 |
4 files changed, 36 insertions, 8 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index d43db7307..694f445bc 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -254,11 +254,10 @@ export function ssr(ctx: Ctx): Cmd { | |||
254 | export function serverVersion(ctx: Ctx): Cmd { | 254 | export function serverVersion(ctx: Ctx): Cmd { |
255 | return async () => { | 255 | return async () => { |
256 | const { stdout } = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" }); | 256 | const { stdout } = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" }); |
257 | const commitHash = stdout.slice(`rust-analyzer `.length).trim(); | 257 | const versionString = stdout.slice(`rust-analyzer `.length).trim(); |
258 | const { releaseTag } = ctx.config.package; | ||
259 | 258 | ||
260 | void vscode.window.showInformationMessage( | 259 | void vscode.window.showInformationMessage( |
261 | `rust-analyzer version: ${releaseTag ?? "unreleased"} (${commitHash})` | 260 | `rust-analyzer version: ${versionString}` |
262 | ); | 261 | ); |
263 | }; | 262 | }; |
264 | } | 263 | } |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index ddb5cfbd3..82f0a0566 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -100,6 +100,14 @@ export class Config { | |||
100 | get channel() { return this.get<UpdatesChannel>("updates.channel"); } | 100 | get channel() { return this.get<UpdatesChannel>("updates.channel"); } |
101 | get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); } | 101 | get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); } |
102 | get traceExtension() { return this.get<boolean>("trace.extension"); } | 102 | get traceExtension() { return this.get<boolean>("trace.extension"); } |
103 | get httpProxy() { | ||
104 | const httpProxy = vscode | ||
105 | .workspace | ||
106 | .getConfiguration('http') | ||
107 | .get<null | string>("proxy")!; | ||
108 | |||
109 | return httpProxy || process.env["https_proxy"] || process.env["HTTPS_PROXY"]; | ||
110 | } | ||
103 | 111 | ||
104 | get inlayHints() { | 112 | get inlayHints() { |
105 | return { | 113 | return { |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index f1a2020aa..925103f56 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -184,7 +184,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
184 | } | 184 | } |
185 | 185 | ||
186 | const release = await downloadWithRetryDialog(state, async () => { | 186 | const release = await downloadWithRetryDialog(state, async () => { |
187 | return await fetchRelease("nightly", state.githubToken); | 187 | return await fetchRelease("nightly", state.githubToken, config.httpProxy); |
188 | }).catch(async (e) => { | 188 | }).catch(async (e) => { |
189 | log.error(e); | 189 | log.error(e); |
190 | if (state.releaseId === undefined) { // Show error only for the initial download | 190 | if (state.releaseId === undefined) { // Show error only for the initial download |
@@ -210,6 +210,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
210 | url: artifact.browser_download_url, | 210 | url: artifact.browser_download_url, |
211 | dest, | 211 | dest, |
212 | progressTitle: "Downloading rust-analyzer extension", | 212 | progressTitle: "Downloading rust-analyzer extension", |
213 | httpProxy: config.httpProxy, | ||
213 | }); | 214 | }); |
214 | }); | 215 | }); |
215 | 216 | ||
@@ -332,7 +333,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
332 | 333 | ||
333 | const releaseTag = config.package.releaseTag; | 334 | const releaseTag = config.package.releaseTag; |
334 | const release = await downloadWithRetryDialog(state, async () => { | 335 | const release = await downloadWithRetryDialog(state, async () => { |
335 | return await fetchRelease(releaseTag, state.githubToken); | 336 | return await fetchRelease(releaseTag, state.githubToken, config.httpProxy); |
336 | }); | 337 | }); |
337 | const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); | 338 | const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); |
338 | assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); | 339 | assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); |
@@ -344,6 +345,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
344 | progressTitle: "Downloading rust-analyzer server", | 345 | progressTitle: "Downloading rust-analyzer server", |
345 | gunzip: true, | 346 | gunzip: true, |
346 | mode: 0o755, | 347 | mode: 0o755, |
348 | httpProxy: config.httpProxy, | ||
347 | }); | 349 | }); |
348 | }); | 350 | }); |
349 | 351 | ||
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index d39dc1baf..07ebc615c 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts | |||
@@ -1,4 +1,6 @@ | |||
1 | import fetch from "node-fetch"; | 1 | import fetch from "node-fetch"; |
2 | var HttpsProxyAgent = require('https-proxy-agent'); | ||
3 | |||
2 | import * as vscode from "vscode"; | 4 | import * as vscode from "vscode"; |
3 | import * as stream from "stream"; | 5 | import * as stream from "stream"; |
4 | import * as crypto from "crypto"; | 6 | import * as crypto from "crypto"; |
@@ -17,6 +19,7 @@ const REPO = "rust-analyzer"; | |||
17 | export async function fetchRelease( | 19 | export async function fetchRelease( |
18 | releaseTag: string, | 20 | releaseTag: string, |
19 | githubToken: string | null | undefined, | 21 | githubToken: string | null | undefined, |
22 | httpProxy: string | null | undefined, | ||
20 | ): Promise<GithubRelease> { | 23 | ): Promise<GithubRelease> { |
21 | 24 | ||
22 | const apiEndpointPath = `/repos/${OWNER}/${REPO}/releases/tags/${releaseTag}`; | 25 | const apiEndpointPath = `/repos/${OWNER}/${REPO}/releases/tags/${releaseTag}`; |
@@ -30,7 +33,14 @@ export async function fetchRelease( | |||
30 | headers.Authorization = "token " + githubToken; | 33 | headers.Authorization = "token " + githubToken; |
31 | } | 34 | } |
32 | 35 | ||
33 | const response = await fetch(requestUrl, { headers: headers }); | 36 | const response = await (() => { |
37 | if (httpProxy) { | ||
38 | log.debug(`Fetching release metadata via proxy: ${httpProxy}`); | ||
39 | return fetch(requestUrl, { headers: headers, agent: new HttpsProxyAgent(httpProxy) }); | ||
40 | } | ||
41 | |||
42 | return fetch(requestUrl, { headers: headers }); | ||
43 | })(); | ||
34 | 44 | ||
35 | if (!response.ok) { | 45 | if (!response.ok) { |
36 | log.error("Error fetching artifact release info", { | 46 | log.error("Error fetching artifact release info", { |
@@ -73,6 +83,7 @@ interface DownloadOpts { | |||
73 | dest: string; | 83 | dest: string; |
74 | mode?: number; | 84 | mode?: number; |
75 | gunzip?: boolean; | 85 | gunzip?: boolean; |
86 | httpProxy?: string; | ||
76 | } | 87 | } |
77 | 88 | ||
78 | export async function download(opts: DownloadOpts) { | 89 | export async function download(opts: DownloadOpts) { |
@@ -91,7 +102,7 @@ export async function download(opts: DownloadOpts) { | |||
91 | }, | 102 | }, |
92 | async (progress, _cancellationToken) => { | 103 | async (progress, _cancellationToken) => { |
93 | let lastPercentage = 0; | 104 | let lastPercentage = 0; |
94 | await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => { | 105 | await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, opts.httpProxy, (readBytes, totalBytes) => { |
95 | const newPercentage = Math.round((readBytes / totalBytes) * 100); | 106 | const newPercentage = Math.round((readBytes / totalBytes) * 100); |
96 | if (newPercentage !== lastPercentage) { | 107 | if (newPercentage !== lastPercentage) { |
97 | progress.report({ | 108 | progress.report({ |
@@ -113,9 +124,17 @@ async function downloadFile( | |||
113 | destFilePath: fs.PathLike, | 124 | destFilePath: fs.PathLike, |
114 | mode: number | undefined, | 125 | mode: number | undefined, |
115 | gunzip: boolean, | 126 | gunzip: boolean, |
127 | httpProxy: string | null | undefined, | ||
116 | onProgress: (readBytes: number, totalBytes: number) => void | 128 | onProgress: (readBytes: number, totalBytes: number) => void |
117 | ): Promise<void> { | 129 | ): Promise<void> { |
118 | const res = await fetch(url); | 130 | const res = await (() => { |
131 | if (httpProxy) { | ||
132 | log.debug(`Downloading ${url} via proxy: ${httpProxy}`); | ||
133 | return fetch(url, { agent: new HttpsProxyAgent(httpProxy) }); | ||
134 | } | ||
135 | |||
136 | return fetch(url); | ||
137 | })(); | ||
119 | 138 | ||
120 | if (!res.ok) { | 139 | if (!res.ok) { |
121 | log.error("Error", res.status, "while downloading file from", url); | 140 | log.error("Error", res.status, "while downloading file from", url); |