mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Drop extensionUri copy
This commit is contained in:
parent
f63690c058
commit
e97569c998
3 changed files with 18 additions and 11 deletions
|
@ -30,11 +30,9 @@ export class Config {
|
||||||
} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
|
} = vscode.extensions.getExtension(this.extensionId)!.packageJSON;
|
||||||
|
|
||||||
readonly globalStorageUri: vscode.Uri;
|
readonly globalStorageUri: vscode.Uri;
|
||||||
readonly installUri: vscode.Uri;
|
|
||||||
|
|
||||||
constructor(ctx: vscode.ExtensionContext) {
|
constructor(ctx: vscode.ExtensionContext) {
|
||||||
this.globalStorageUri = ctx.globalStorageUri;
|
this.globalStorageUri = ctx.globalStorageUri;
|
||||||
this.installUri = ctx.extensionUri;
|
|
||||||
vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, ctx.subscriptions);
|
vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, ctx.subscriptions);
|
||||||
this.refreshLogging();
|
this.refreshLogging();
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,14 +156,10 @@ export async function deactivate() {
|
||||||
ctx = undefined;
|
ctx = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bootstrap(config: Config, state: PersistentState): Promise<string> {
|
async function bootstrap(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string> {
|
||||||
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
|
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
|
||||||
const path = await bootstrapServer(config, state);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bootstrapServer(config: Config, state: PersistentState): Promise<string> {
|
const path = await getServer(context, config, state);
|
||||||
const path = await getServer(config, state);
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Rust Analyzer Language Server is not available. " +
|
"Rust Analyzer Language Server is not available. " +
|
||||||
|
@ -228,7 +224,7 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getServer(config: Config, state: PersistentState): Promise<string | undefined> {
|
async function getServer(context: vscode.ExtensionContext, config: Config, state: PersistentState): Promise<string | undefined> {
|
||||||
const explicitPath = serverPath(config);
|
const explicitPath = serverPath(config);
|
||||||
if (explicitPath) {
|
if (explicitPath) {
|
||||||
if (explicitPath.startsWith("~/")) {
|
if (explicitPath.startsWith("~/")) {
|
||||||
|
@ -264,14 +260,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
||||||
}
|
}
|
||||||
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
|
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
|
||||||
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
|
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
|
||||||
const bundled = vscode.Uri.joinPath(config.installUri, "server", `rust-analyzer${ext}`);
|
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
|
||||||
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
|
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
|
||||||
const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
|
const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
|
||||||
if (bundledExists) {
|
if (bundledExists) {
|
||||||
if (!await isNixOs()) {
|
if (!await isNixOs()) {
|
||||||
return bundled.fsPath;
|
return bundled.fsPath;
|
||||||
}
|
}
|
||||||
if (!exists) {
|
if (!exists || config.package.version !== state.serverVersion) {
|
||||||
await vscode.workspace.fs.copy(bundled, dest);
|
await vscode.workspace.fs.copy(bundled, dest);
|
||||||
await patchelf(dest);
|
await patchelf(dest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,18 @@ import { log } from './util';
|
||||||
|
|
||||||
export class PersistentState {
|
export class PersistentState {
|
||||||
constructor(private readonly globalState: vscode.Memento) {
|
constructor(private readonly globalState: vscode.Memento) {
|
||||||
|
const { serverVersion } = this;
|
||||||
|
log.info("PersistentState:", { serverVersion });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version of the extension that installed the server.
|
||||||
|
* Used to check if we need to run patchelf again on NixOS.
|
||||||
|
*/
|
||||||
|
get serverVersion(): string | undefined {
|
||||||
|
return this.globalState.get("serverVersion");
|
||||||
|
}
|
||||||
|
async updateServerVersion(value: string | undefined) {
|
||||||
|
await this.globalState.update("serverVersion", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue