-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Alternative aproach to plugin auto update #3629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,10 @@ | ||
| import * as vscode from 'vscode'; | ||
| import { ensureServerBinary } from '../installation/server'; | ||
| import * as vscode from "vscode"; | ||
| import { spawnSync } from "child_process"; | ||
| import { Ctx, Cmd } from '../ctx'; | ||
| import { spawnSync } from 'child_process'; | ||
|
|
||
| export function serverVersion(ctx: Ctx): Cmd { | ||
| return async () => { | ||
| const binaryPath = await ensureServerBinary(ctx.config, ctx.state); | ||
|
|
||
| if (binaryPath == null) { | ||
| throw new Error( | ||
| "Rust Analyzer Language Server is not available. " + | ||
| "Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation)." | ||
| ); | ||
| } | ||
|
|
||
| const version = spawnSync(binaryPath, ["--version"], { encoding: "utf8" }).stdout; | ||
| const version = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" }).stdout; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should still use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will require adding persistentState to ctx, which I’d rather avoid. |
||
| vscode.window.showInformationMessage('rust-analyzer version : ' + version); | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,5 @@ | ||
| import * as os from "os"; | ||
| import * as vscode from 'vscode'; | ||
| import { ArtifactSource } from "./installation/interfaces"; | ||
| import { log, vscodeReloadWindow } from "./util"; | ||
|
|
||
| const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | ||
| import { log } from "./util"; | ||
|
|
||
| export interface InlayHintOptions { | ||
| typeHints: boolean; | ||
|
|
@@ -25,10 +21,7 @@ export interface CargoFeatures { | |
| loadOutDirsFromCheck: boolean; | ||
| } | ||
|
|
||
| export const enum UpdatesChannel { | ||
| Stable = "stable", | ||
| Nightly = "nightly" | ||
| } | ||
| export type UpdatesChannel = "stable" | "nightly"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good thing that TypeScript allows for stringly-typed apis, though I prefer enums, but no too strong arguments.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, makes sense, will update tomorrow |
||
|
|
||
| export const NIGHTLY_TAG = "nightly"; | ||
| export class Config { | ||
|
|
@@ -41,6 +34,7 @@ export class Config { | |
| "cargo-watch", | ||
| "highlighting.semanticTokens", | ||
| "inlayHints", | ||
| "updates.channel", | ||
| ] | ||
| .map(opt => `${this.rootSection}.${opt}`); | ||
|
|
||
|
|
@@ -94,100 +88,17 @@ export class Config { | |
| ); | ||
|
|
||
| if (userResponse === "Reload now") { | ||
| await vscodeReloadWindow(); | ||
| await vscode.commands.executeCommand("workbench.action.reloadWindow"); | ||
| } | ||
| } | ||
|
|
||
| private static replaceTildeWithHomeDir(path: string) { | ||
| if (path.startsWith("~/")) { | ||
| return os.homedir() + path.slice("~".length); | ||
| } | ||
| return path; | ||
| } | ||
|
|
||
| /** | ||
| * Name of the binary artifact for `rust-analyzer` that is published for | ||
| * `platform` on GitHub releases. (It is also stored under the same name when | ||
| * downloaded by the extension). | ||
| */ | ||
| get prebuiltServerFileName(): null | string { | ||
| // See possible `arch` values here: | ||
| // https://nodejs.org/api/process.html#process_process_arch | ||
|
|
||
| switch (process.platform) { | ||
|
|
||
| case "linux": { | ||
| switch (process.arch) { | ||
| case "arm": | ||
| case "arm64": return null; | ||
|
|
||
| default: return "rust-analyzer-linux"; | ||
| } | ||
| } | ||
|
|
||
| case "darwin": return "rust-analyzer-mac"; | ||
| case "win32": return "rust-analyzer-windows.exe"; | ||
|
|
||
| // Users on these platforms yet need to manually build from sources | ||
| case "aix": | ||
| case "android": | ||
| case "freebsd": | ||
| case "openbsd": | ||
| case "sunos": | ||
| case "cygwin": | ||
| case "netbsd": return null; | ||
| // The list of platforms is exhaustive (see `NodeJS.Platform` type definition) | ||
| } | ||
| } | ||
|
|
||
| get installedExtensionUpdateChannel(): UpdatesChannel { | ||
| return this.extensionReleaseTag === NIGHTLY_TAG | ||
| ? UpdatesChannel.Nightly | ||
| : UpdatesChannel.Stable; | ||
| } | ||
|
|
||
| get serverSource(): null | ArtifactSource { | ||
| const serverPath = RA_LSP_DEBUG ?? this.serverPath; | ||
|
|
||
| if (serverPath) { | ||
| return { | ||
| type: ArtifactSource.Type.ExplicitPath, | ||
| path: Config.replaceTildeWithHomeDir(serverPath) | ||
| }; | ||
| } | ||
|
|
||
| const prebuiltBinaryName = this.prebuiltServerFileName; | ||
|
|
||
| if (!prebuiltBinaryName) return null; | ||
|
|
||
| return this.createGithubReleaseSource( | ||
| prebuiltBinaryName, | ||
| this.extensionReleaseTag | ||
| ); | ||
| } | ||
|
|
||
| private createGithubReleaseSource(file: string, tag: string): ArtifactSource.GithubRelease { | ||
| return { | ||
| type: ArtifactSource.Type.GithubRelease, | ||
| file, | ||
| tag, | ||
| dir: this.ctx.globalStoragePath, | ||
| repo: { | ||
| name: "rust-analyzer", | ||
| owner: "rust-analyzer", | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| get nightlyVsixSource(): ArtifactSource.GithubRelease { | ||
| return this.createGithubReleaseSource("rust-analyzer.vsix", NIGHTLY_TAG); | ||
| } | ||
| get globalStoragePath(): string { return this.ctx.globalStoragePath; } | ||
|
|
||
| // We don't do runtime config validation here for simplicity. More on stackoverflow: | ||
| // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension | ||
|
|
||
| private get serverPath() { return this.cfg.get("serverPath") as null | string; } | ||
| get updatesChannel() { return this.cfg.get("updates.channel") as UpdatesChannel; } | ||
| get serverPath() { return this.cfg.get("serverPath") as null | string; } | ||
| get channel() { return this.cfg.get<"stable" | "nightly">("updates.channel")!; } | ||
| get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } | ||
| get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } | ||
| get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this option for? Does this overwrite the
globalStoragePath?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this overrides storage path, extensions and settings, and it makes it easier to look inside the store. It’s deliberately commented out, so that it can be easily restored when needed