about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-04-29 13:34:03 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-05-01 19:57:09 +0200
commitd6dba1c97ca6c9a529e7dfbb17320e3e59713aef (patch)
treed2e084224baf6d1c7096b7b8035778c27d979380
parent1f11b70c3bcbdd1481d00344ccf4da9cdca2a572 (diff)
downloadrust-d6dba1c97ca6c9a529e7dfbb17320e3e59713aef.tar.gz
rust-d6dba1c97ca6c9a529e7dfbb17320e3e59713aef.zip
auto update old configurations to newer ones
-rw-r--r--editors/code/src/client.ts7
-rw-r--r--editors/code/src/config.ts87
-rw-r--r--editors/code/src/ctx.ts2
3 files changed, 87 insertions, 9 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index f7520f6c436..99b72635d18 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -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 };
     }
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 183521c10c5..5b650e1420a 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -18,7 +18,6 @@ export class Config {
         "cargo",
         "procMacro",
         "files",
-        "highlighting",
         "lens", // works as lens.*
     ]
         .map(opt => `${this.rootSection}.${opt}`);
@@ -79,7 +78,7 @@ export class Config {
      * const nullableNum = vscode
      *  .workspace
      *  .getConfiguration
-     *  .getConfiguration("rust-analyer")
+     *  .getConfiguration("rust-analyzer")
      *  .get<number | null>(path)!;
      *
      * // What happens is that type of `nullableNum` is `number` but not `null | number`:
@@ -124,11 +123,11 @@ export class Config {
     get hoverActions() {
         return {
             enable: this.get<boolean>("hoverActions.enable"),
-            implementations: this.get<boolean>("hoverActions.implementations"),
-            references: this.get<boolean>("hoverActions.references"),
-            run: this.get<boolean>("hoverActions.run"),
-            debug: this.get<boolean>("hoverActions.debug"),
-            gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),
+            implementations: this.get<boolean>("hoverActions.implementations.enable"),
+            references: this.get<boolean>("hoverActions.references.enable"),
+            run: this.get<boolean>("hoverActions.run.enable"),
+            debug: this.get<boolean>("hoverActions.debug.enable"),
+            gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef.enable"),
         };
     }
 
@@ -136,3 +135,77 @@ export class Config {
         return this.package.releaseTag === NIGHTLY_TAG;
     }
 }
+
+export async function updateConfig(config: vscode.WorkspaceConfiguration) {
+    const renames = [
+        ["assist.allowMergingIntoGlobImports", "imports.merge.glob",],
+        ["assist.exprFillDefault", "assist.expressionFillDefault",],
+        ["assist.importEnforceGranularity", "imports.granularity.enforce",],
+        ["assist.importGranularity", "imports.granularity.group",],
+        ["assist.importMergeBehavior", "imports.granularity.group",],
+        ["assist.importMergeBehaviour", "imports.granularity.group",],
+        ["assist.importGroup", "imports.group.enable",],
+        ["assist.importPrefix", "imports.prefix",],
+        ["cache.warmup", "primeCaches.enable",],
+        ["cargo.loadOutDirsFromCheck", "cargo.buildScripts.enable",],
+        ["cargo.runBuildScripts", "cargo.runBuildScripts.overrideCommand",],
+        ["cargo.runBuildScriptsCommand", "cargo.runBuildScripts.overrideCommand",],
+        ["cargo.useRustcWrapperForBuildScripts", "cargo.runBuildScripts.useRustcWrapper",],
+        ["completion.snippets", "completion.snippets.custom",],
+        ["diagnostics.enableExperimental", "diagnostics.experimental.enable",],
+        ["experimental.procAttrMacros", "procMacro.attributes.enable",],
+        ["highlighting.strings", "semanticHighlighting.strings.enable",],
+        ["highlightRelated.breakPoints", "highlightRelated.breakPoints.enable",],
+        ["highlightRelated.exitPoints", "highlightRelated.exitPoints.enable",],
+        ["highlightRelated.yieldPoints", "highlightRelated.yieldPoints.enable",],
+        ["highlightRelated.references", "highlightRelated.references.enable",],
+        ["hover.documentation", "hover.documentation.enable",],
+        ["hover.linksInHover", "hover.links.enable",],
+        ["hoverActions.linksInHover", "hover.links.enable",],
+        ["hoverActions.debug", "hoverActions.debug.enable",],
+        ["hoverActions.enable", "hoverActions.enable.enable",],
+        ["hoverActions.gotoTypeDef", "hoverActions.gotoTypeDef.enable",],
+        ["hoverActions.implementations", "hoverActions.implementations.enable",],
+        ["hoverActions.references", "hoverActions.references.enable",],
+        ["hoverActions.run", "hoverActions.run.enable",],
+        ["inlayHints.chainingHints", "inlayHints.chainingHints.enable",],
+        ["inlayHints.closureReturnTypeHints", "inlayHints.closureReturnTypeHints.enable",],
+        ["inlayHints.hideNamedConstructorHints", "inlayHints.typeHints.hideNamedConstructorHints",],
+        ["inlayHints.parameterHints", "inlayHints.parameterHints.enable",],
+        ["inlayHints.reborrowHints", "inlayHints.reborrowHints.enable",],
+        ["inlayHints.typeHints", "inlayHints.typeHints.enable",],
+        ["lruCapacity", "lru.capacity",],
+        ["runnables.cargoExtraArgs", "runnables.extraArgs",],
+        ["runnables.overrideCargo", "runnables.command",],
+        ["rustcSource", "rustc.source",],
+        ["rustfmt.enableRangeFormatting", "rustfmt.rangeFormatting.enable"]
+    ];
+
+    for (const [oldKey, newKey] of renames) {
+        const inspect = config.inspect(oldKey);
+        if (inspect !== undefined) {
+            const valMatrix = [
+                { val: inspect.globalValue, langVal: inspect.globalLanguageValue, target: vscode.ConfigurationTarget.Global },
+                { val: inspect.workspaceFolderValue, langVal: inspect.workspaceFolderLanguageValue, target: vscode.ConfigurationTarget.WorkspaceFolder },
+                { val: inspect.workspaceValue, langVal: inspect.workspaceLanguageValue, target: vscode.ConfigurationTarget.Workspace }
+            ];
+            for (const { val, langVal, target } of valMatrix) {
+                const pred = (val: unknown) => {
+                    // some of the updates we do only append "enable" or "custom"
+                    // that means on the next run we would find these again, but as objects with
+                    // these properties causing us to destroy the config
+                    // so filter those already updated ones out
+                    return val !== undefined && !(typeof val === "object" && val !== null && (val.hasOwnProperty("enable") || val.hasOwnProperty("custom")));
+                };
+                if (pred(val)) {
+                    await config.update(newKey, val, target, false);
+                    await config.update(oldKey, undefined, target, false);
+                }
+                if (pred(langVal)) {
+                    await config.update(newKey, langVal, target, true);
+                    await config.update(oldKey, undefined, target, true);
+                }
+            }
+        }
+    }
+}
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 666a4b6972b..0c3e6810e99 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -33,7 +33,7 @@ export class Ctx {
         serverPath: string,
         workspace: Workspace,
     ): Promise<Ctx> {
-        const client = createClient(serverPath, workspace, config.serverExtraEnv);
+        const client = await createClient(serverPath, workspace, config.serverExtraEnv);
 
         const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
         extCtx.subscriptions.push(statusBar);