about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/editors/code
diff options
context:
space:
mode:
authorDavid Barsky <me@davidbarsky.com>2024-07-23 13:34:03 -0400
committerDavid Barsky <me@davidbarsky.com>2024-07-23 13:34:04 -0400
commit06fe4e6b6e4aec29a21bcaa8a1a5582d6fb3eb78 (patch)
tree13bd9159d91c1b88b99576e6c428011d2278a1d6 /src/tools/rust-analyzer/editors/code
parentb8e83b78eb6bbe11815f296a7dd847c91ae43a84 (diff)
downloadrust-06fe4e6b6e4aec29a21bcaa8a1a5582d6fb3eb78.tar.gz
rust-06fe4e6b6e4aec29a21bcaa8a1a5582d6fb3eb78.zip
internal: remove UnindexedProject notification
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
Diffstat (limited to 'src/tools/rust-analyzer/editors/code')
-rw-r--r--src/tools/rust-analyzer/editors/code/package.json10
-rw-r--r--src/tools/rust-analyzer/editors/code/src/client.ts11
-rw-r--r--src/tools/rust-analyzer/editors/code/src/config.ts25
-rw-r--r--src/tools/rust-analyzer/editors/code/src/ctx.ts57
-rw-r--r--src/tools/rust-analyzer/editors/code/src/lsp_ext.ts6
-rw-r--r--src/tools/rust-analyzer/editors/code/src/main.ts6
-rw-r--r--src/tools/rust-analyzer/editors/code/src/rust_project.ts110
7 files changed, 10 insertions, 215 deletions
diff --git a/src/tools/rust-analyzer/editors/code/package.json b/src/tools/rust-analyzer/editors/code/package.json
index eee4fe3706d..49defa5deae 100644
--- a/src/tools/rust-analyzer/editors/code/package.json
+++ b/src/tools/rust-analyzer/editors/code/package.json
@@ -2268,16 +2268,6 @@
                 }
             },
             {
-                "title": "notifications",
-                "properties": {
-                    "rust-analyzer.notifications.unindexedProject": {
-                        "markdownDescription": "Whether to send an UnindexedProject notification to the client.",
-                        "default": false,
-                        "type": "boolean"
-                    }
-                }
-            },
-            {
                 "title": "general",
                 "properties": {
                     "rust-analyzer.numThreads": {
diff --git a/src/tools/rust-analyzer/editors/code/src/client.ts b/src/tools/rust-analyzer/editors/code/src/client.ts
index 916e266cfd4..357f131b93f 100644
--- a/src/tools/rust-analyzer/editors/code/src/client.ts
+++ b/src/tools/rust-analyzer/editors/code/src/client.ts
@@ -42,16 +42,7 @@ export async function createClient(
                     const resp = await next(params, token);
                     if (resp && Array.isArray(resp)) {
                         return resp.map((val) => {
-                            return prepareVSCodeConfig(val, (key, cfg) => {
-                                // we only want to set discovered workspaces on the right key
-                                // and if a workspace has been discovered.
-                                if (
-                                    key === "linkedProjects" &&
-                                    config.discoveredWorkspaces.length > 0
-                                ) {
-                                    cfg[key] = config.discoveredWorkspaces;
-                                }
-                            });
+                            return prepareVSCodeConfig(val);
                         });
                     } else {
                         return resp;
diff --git a/src/tools/rust-analyzer/editors/code/src/config.ts b/src/tools/rust-analyzer/editors/code/src/config.ts
index ca77215004d..75fbcdacae4 100644
--- a/src/tools/rust-analyzer/editors/code/src/config.ts
+++ b/src/tools/rust-analyzer/editors/code/src/config.ts
@@ -2,9 +2,9 @@ import * as Is from "vscode-languageclient/lib/common/utils/is";
 import * as os from "os";
 import * as path from "path";
 import * as vscode from "vscode";
-import { type Env, log, unwrapUndefinable, expectNotUndefined } from "./util";
-import type { JsonProject } from "./rust_project";
-import type { Disposable } from "./ctx";
+import { expectNotUndefined, log, unwrapUndefinable } from "./util";
+import type { Env } from "./util";
+import type { Disposable } from "vscode";
 
 export type RunnableEnvCfgItem = {
     mask?: string;
@@ -31,7 +31,6 @@ export class Config {
     );
 
     constructor(disposables: Disposable[]) {
-        this.discoveredWorkspaces = [];
         vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, disposables);
         this.refreshLogging();
         this.configureLanguage();
@@ -52,8 +51,6 @@ export class Config {
         log.info("Using configuration", Object.fromEntries(cfg));
     }
 
-    public discoveredWorkspaces: JsonProject[];
-
     private async onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
         this.refreshLogging();
 
@@ -342,18 +339,7 @@ export class Config {
     }
 }
 
-// the optional `cb?` parameter is meant to be used to add additional
-// key/value pairs to the VS Code configuration. This needed for, e.g.,
-// including a `rust-project.json` into the `linkedProjects` key as part
-// of the configuration/InitializationParams _without_ causing VS Code
-// configuration to be written out to workspace-level settings. This is
-// undesirable behavior because rust-project.json files can be tens of
-// thousands of lines of JSON, most of which is not meant for humans
-// to interact with.
-export function prepareVSCodeConfig<T>(
-    resp: T,
-    cb?: (key: Extract<keyof T, string>, res: { [key: string]: any }) => void,
-): T {
+export function prepareVSCodeConfig<T>(resp: T): T {
     if (Is.string(resp)) {
         return substituteVSCodeVariableInString(resp) as T;
     } else if (resp && Is.array<any>(resp)) {
@@ -365,9 +351,6 @@ export function prepareVSCodeConfig<T>(
         for (const key in resp) {
             const val = resp[key];
             res[key] = prepareVSCodeConfig(val);
-            if (cb) {
-                cb(key, res);
-            }
         }
         return res as T;
     }
diff --git a/src/tools/rust-analyzer/editors/code/src/ctx.ts b/src/tools/rust-analyzer/editors/code/src/ctx.ts
index 675bfda65ab..49e002627d8 100644
--- a/src/tools/rust-analyzer/editors/code/src/ctx.ts
+++ b/src/tools/rust-analyzer/editors/code/src/ctx.ts
@@ -1,5 +1,5 @@
 import * as vscode from "vscode";
-import * as lc from "vscode-languageclient/node";
+import type * as lc from "vscode-languageclient/node";
 import * as ra from "./lsp_ext";
 
 import { Config, prepareVSCodeConfig } from "./config";
@@ -22,11 +22,10 @@ import {
 import { execRevealDependency } from "./commands";
 import { PersistentState } from "./persistent_state";
 import { bootstrap } from "./bootstrap";
-import type { RustAnalyzerExtensionApi } from "./main";
-import type { JsonProject } from "./rust_project";
 import { prepareTestExplorer } from "./test_explorer";
 import { spawn } from "node:child_process";
 import { text } from "node:stream/consumers";
+import type { RustAnalyzerExtensionApi } from "./main";
 
 // We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
 // only those are in use. We use "Empty" to represent these scenarios
@@ -71,7 +70,7 @@ export type CtxInit = Ctx & {
 
 export class Ctx implements RustAnalyzerExtensionApi {
     readonly statusBar: vscode.StatusBarItem;
-    config: Config;
+    readonly config: Config;
     readonly workspace: Workspace;
     readonly version: string;
 
@@ -212,15 +211,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
             };
 
             let rawInitializationOptions = vscode.workspace.getConfiguration("rust-analyzer");
-            if (this.config.discoverProjectRunner) {
-                const command = `${this.config.discoverProjectRunner}.discoverWorkspaceCommand`;
-                log.info(`running command: ${command}`);
-                const uris = vscode.workspace.textDocuments
-                    .filter(isRustDocument)
-                    .map((document) => document.uri);
-                const projects: JsonProject[] = await vscode.commands.executeCommand(command, uris);
-                this.setWorkspaces(projects);
-            }
 
             if (this.workspace.kind === "Detached Files") {
                 rawInitializationOptions = {
@@ -229,16 +219,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
                 };
             }
 
-            const initializationOptions = prepareVSCodeConfig(
-                rawInitializationOptions,
-                (key, obj) => {
-                    // we only want to set discovered workspaces on the right key
-                    // and if a workspace has been discovered.
-                    if (key === "linkedProjects" && this.config.discoveredWorkspaces.length > 0) {
-                        obj["linkedProjects"] = this.config.discoveredWorkspaces;
-                    }
-                },
-            );
+            const initializationOptions = prepareVSCodeConfig(rawInitializationOptions);
 
             this._client = await createClient(
                 this.traceOutputChannel,
@@ -258,23 +239,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
                     this.outputChannel!.show();
                 }),
             );
-            this.pushClientCleanup(
-                this._client.onNotification(ra.unindexedProject, async (params) => {
-                    if (this.config.discoverProjectRunner) {
-                        const command = `${this.config.discoverProjectRunner}.discoverWorkspaceCommand`;
-                        log.info(`running command: ${command}`);
-                        const uris = params.textDocuments.map((doc) =>
-                            vscode.Uri.parse(doc.uri, true),
-                        );
-                        const projects: JsonProject[] = await vscode.commands.executeCommand(
-                            command,
-                            uris,
-                        );
-                        this.setWorkspaces(projects);
-                        await this.notifyRustAnalyzer();
-                    }
-                }),
-            );
         }
         return this._client;
     }
@@ -400,19 +364,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
         return this.extCtx.subscriptions;
     }
 
-    setWorkspaces(workspaces: JsonProject[]) {
-        this.config.discoveredWorkspaces = workspaces;
-    }
-
-    async notifyRustAnalyzer(): Promise<void> {
-        // this is a workaround to avoid needing writing the `rust-project.json` into
-        // a workspace-level VS Code-specific settings folder. We'd like to keep the
-        // `rust-project.json` entirely in-memory.
-        await this.client?.sendNotification(lc.DidChangeConfigurationNotification.type, {
-            settings: "",
-        });
-    }
-
     private updateCommands(forceDisable?: "disable") {
         this.commandDisposables.forEach((disposable) => disposable.dispose());
         this.commandDisposables = [];
diff --git a/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts b/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts
index e24893b2509..2a7b51eaa19 100644
--- a/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts
+++ b/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts
@@ -303,9 +303,3 @@ export type RecursiveMemoryLayoutNode = {
 export type RecursiveMemoryLayout = {
     nodes: RecursiveMemoryLayoutNode[];
 };
-
-export const unindexedProject = new lc.NotificationType<UnindexedProjectParams>(
-    "rust-analyzer/unindexedProject",
-);
-
-export type UnindexedProjectParams = { textDocuments: lc.TextDocumentIdentifier[] };
diff --git a/src/tools/rust-analyzer/editors/code/src/main.ts b/src/tools/rust-analyzer/editors/code/src/main.ts
index db1c377b46a..381c7b05711 100644
--- a/src/tools/rust-analyzer/editors/code/src/main.ts
+++ b/src/tools/rust-analyzer/editors/code/src/main.ts
@@ -6,16 +6,12 @@ import { type CommandFactory, Ctx, fetchWorkspace } from "./ctx";
 import * as diagnostics from "./diagnostics";
 import { activateTaskProvider } from "./tasks";
 import { setContextValue } from "./util";
-import type { JsonProject } from "./rust_project";
 
 const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
 
-// This API is not stable and may break in between minor releases.
 export interface RustAnalyzerExtensionApi {
+    // FIXME: this should be non-optional
     readonly client?: lc.LanguageClient;
-
-    setWorkspaces(workspaces: JsonProject[]): void;
-    notifyRustAnalyzer(): Promise<void>;
 }
 
 export async function deactivate() {
diff --git a/src/tools/rust-analyzer/editors/code/src/rust_project.ts b/src/tools/rust-analyzer/editors/code/src/rust_project.ts
deleted file mode 100644
index c983874fc00..00000000000
--- a/src/tools/rust-analyzer/editors/code/src/rust_project.ts
+++ /dev/null
@@ -1,110 +0,0 @@
-export interface JsonProject {
-    /// Path to the sysroot directory.
-    ///
-    /// The sysroot is where rustc looks for the
-    /// crates that are built-in to rust, such as
-    /// std.
-    ///
-    /// https://doc.rust-lang.org/rustc/command-line-arguments.html#--sysroot-override-the-system-root
-    ///
-    /// To see the current value of sysroot, you
-    /// can query rustc:
-    ///
-    /// ```
-    /// $ rustc --print sysroot
-    /// /Users/yourname/.rustup/toolchains/stable-x86_64-apple-darwin
-    /// ```
-    sysroot?: string;
-    /// Path to the directory with *source code* of
-    /// sysroot crates.
-    ///
-    /// By default, this is `lib/rustlib/src/rust/library`
-    /// relative to the sysroot.
-    ///
-    /// It should point to the directory where std,
-    /// core, and friends can be found:
-    ///
-    /// https://github.com/rust-lang/rust/tree/master/library.
-    ///
-    /// If provided, rust-analyzer automatically adds
-    /// dependencies on sysroot crates. Conversely,
-    /// if you omit this path, you can specify sysroot
-    /// dependencies yourself and, for example, have
-    /// several different "sysroots" in one graph of
-    /// crates.
-    sysroot_src?: string;
-    /// The set of crates comprising the current
-    /// project. Must include all transitive
-    /// dependencies as well as sysroot crate (libstd,
-    /// libcore and such).
-    crates: Crate[];
-}
-
-export interface Crate {
-    /// Optional crate name used for display purposes,
-    /// without affecting semantics. See the `deps`
-    /// key for semantically-significant crate names.
-    display_name?: string;
-    /// Path to the root module of the crate.
-    root_module: string;
-    /// Edition of the crate.
-    edition: "2015" | "2018" | "2021";
-    /// Dependencies
-    deps: Dep[];
-    /// Should this crate be treated as a member of
-    /// current "workspace".
-    ///
-    /// By default, inferred from the `root_module`
-    /// (members are the crates which reside inside
-    /// the directory opened in the editor).
-    ///
-    /// Set this to `false` for things like standard
-    /// library and 3rd party crates to enable
-    /// performance optimizations (rust-analyzer
-    /// assumes that non-member crates don't change).
-    is_workspace_member?: boolean;
-    /// Optionally specify the (super)set of `.rs`
-    /// files comprising this crate.
-    ///
-    /// By default, rust-analyzer assumes that only
-    /// files under `root_module.parent` can belong
-    /// to a crate. `include_dirs` are included
-    /// recursively, unless a subdirectory is in
-    /// `exclude_dirs`.
-    ///
-    /// Different crates can share the same `source`.
-    ///
-    /// If two crates share an `.rs` file in common,
-    /// they *must* have the same `source`.
-    /// rust-analyzer assumes that files from one
-    /// source can't refer to files in another source.
-    source?: {
-        include_dirs: string[];
-        exclude_dirs: string[];
-    };
-    /// The set of cfgs activated for a given crate, like
-    /// `["unix", "feature=\"foo\"", "feature=\"bar\""]`.
-    cfg: string[];
-    /// Target triple for this Crate.
-    ///
-    /// Used when running `rustc --print cfg`
-    /// to get target-specific cfgs.
-    target?: string;
-    /// Environment variables, used for
-    /// the `env!` macro
-    env: { [key: string]: string };
-
-    /// Whether the crate is a proc-macro crate.
-    is_proc_macro: boolean;
-    /// For proc-macro crates, path to compiled
-    /// proc-macro (.so file).
-    proc_macro_dylib_path?: string;
-}
-
-export interface Dep {
-    /// Index of a crate in the `crates` array.
-    crate: number;
-    /// Name as should appear in the (implicit)
-    /// `extern crate name` declaration.
-    name: string;
-}