auto update old configurations to newer ones

This commit is contained in:
Lukas Wirth 2022-04-29 13:34:03 +02:00
parent 1f11b70c3b
commit d6dba1c97c
3 changed files with 87 additions and 9 deletions

View file

@ -5,6 +5,7 @@ import * as Is from 'vscode-languageclient/lib/common/utils/is';
import { assert } from './util';
import { WorkspaceEdit } from 'vscode';
import { Workspace } from './ctx';
import { updateConfig } from './config';
export interface Env {
[name: string]: string;
@ -24,7 +25,7 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
return result;
}
export function createClient(serverPath: string, workspace: Workspace, extraEnv: Env): lc.LanguageClient {
export async function createClient(serverPath: string, workspace: Workspace, extraEnv: Env): Promise<lc.LanguageClient> {
// '.' Is the fallback if no folder is open
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
// It might be a good idea to test if the uri points to a file.
@ -45,6 +46,10 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
);
let initializationOptions = vscode.workspace.getConfiguration("rust-analyzer");
// Update outdated user configs
await updateConfig(initializationOptions);
if (workspace.kind === "Detached Files") {
initializationOptions = { "detachedFiles": workspace.files.map(file => file.uri.fsPath), ...initializationOptions };
}