Auto merge of #15863 - davidbarsky:davidbarsky/start-of-monorepo-mode, r=Veykril

feature: Create `UnindexedProject` notification to be sent to the client

(Note that this branch contains commits from https://github.com/rust-lang/rust-analyzer/pull/15830, which I'll rebase atop of as needed.)

Based on the discussion in https://github.com/rust-lang/rust-analyzer/issues/15837, I've added a notification and off-by-default toggle to send that notification from `handle_did_open_text_document`. I'm happy to rename/tweak this as needed.

I've been using this for a little bit, and it does seem to cause a little bit more indexing/work in rust-analyzer, but it's something that I'll profile as needed, I think.
This commit is contained in:
bors 2024-02-08 19:36:09 +00:00
commit 13707845f7
13 changed files with 261 additions and 7 deletions

View file

@ -1473,6 +1473,11 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.notifications.unindexedProject": {
"markdownDescription": "Whether to send an UnindexedProject notification to the client.",
"default": false,
"type": "boolean"
},
"rust-analyzer.numThreads": {
"markdownDescription": "How many worker threads in the main loop. The default `null` means to pick automatically.",
"default": null,

View file

@ -234,6 +234,23 @@ 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;
}

View file

@ -220,3 +220,9 @@ export type RecursiveMemoryLayoutNode = {
export type RecursiveMemoryLayout = {
nodes: RecursiveMemoryLayoutNode[];
};
export const unindexedProject = new lc.NotificationType<UnindexedProjectParams>(
"rust-analyzer/unindexedProject",
);
export type UnindexedProjectParams = { textDocuments: lc.TextDocumentIdentifier[] };