Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
// "--user-data-dir=${workspaceFolder}/target/code",
Copy link
Contributor

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?

Copy link
Contributor Author

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

"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}/editors/code"
],
Expand Down
2 changes: 1 addition & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"default": "stable",
"markdownEnumDescriptions": [
"`\"stable\"` updates are shipped weekly, they don't contain cutting-edge features from VSCode proposed APIs but have less bugs in general",
"`\"nightly\"` updates are shipped daily, they contain cutting-edge features and latest bug fixes. These releases help us get your feedback very quickly and speed up rust-analyzer development **drastically**"
"`\"nightly\"` updates are shipped daily (extension updates automatically by downloading artifacts directly from GitHub), they contain cutting-edge features and latest bug fixes. These releases help us get your feedback very quickly and speed up rust-analyzer development **drastically**"
],
"markdownDescription": "Choose `\"nightly\"` updates to get the latest features and bug fixes every day. While `\"stable\"` releases occur weekly and don't contain cutting-edge features from VSCode proposed APIs"
},
Expand Down
16 changes: 3 additions & 13 deletions editors/code/src/commands/server_version.ts
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should still use getServer() thing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
};
}
103 changes: 7 additions & 96 deletions editors/code/src/config.ts
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;
Expand All @@ -25,10 +21,7 @@ export interface CargoFeatures {
loadOutDirsFromCheck: boolean;
}

export const enum UpdatesChannel {
Stable = "stable",
Nightly = "nightly"
}
export type UpdatesChannel = "stable" | "nightly";
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Expand All @@ -41,6 +34,7 @@ export class Config {
"cargo-watch",
"highlighting.semanticTokens",
"inlayHints",
"updates.channel",
]
.map(opt => `${this.rootSection}.${opt}`);

Expand Down Expand Up @@ -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; }
Expand Down
9 changes: 4 additions & 5 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import * as lc from 'vscode-languageclient';
import { Config } from './config';
import { createClient } from './client';
import { isRustEditor, RustEditor } from './util';
import { PersistentState } from './persistent_state';

export class Ctx {
private constructor(
readonly config: Config,
readonly state: PersistentState,
private readonly extCtx: vscode.ExtensionContext,
readonly client: lc.LanguageClient
readonly client: lc.LanguageClient,
readonly serverPath: string,
) {

}

static async create(config: Config, state: PersistentState, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> {
static async create(config: Config, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> {
const client = await createClient(config, serverPath);
const res = new Ctx(config, state, extCtx, client);
const res = new Ctx(config, extCtx, client, serverPath);
res.pushCleanup(client.start());
await client.onReady();
return res;
Expand Down
146 changes: 0 additions & 146 deletions editors/code/src/installation/extension.ts

This file was deleted.

Loading