Skip to content

Commit 25300f1

Browse files
committed
internal: remove UnindexedProject notification
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 651983d commit 25300f1

File tree

15 files changed

+26
-373
lines changed

15 files changed

+26
-373
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,6 @@ config_data! {
585585
/// Whether to show `can't find Cargo.toml` error message.
586586
notifications_cargoTomlNotFound: bool = true,
587587

588-
/// Whether to send an UnindexedProject notification to the client.
589-
notifications_unindexedProject: bool = false,
590-
591588
/// How many worker threads in the main loop. The default `null` means to pick automatically.
592589
numThreads: Option<NumThreads> = None,
593590

@@ -1118,7 +1115,6 @@ pub enum FilesWatcher {
11181115
#[derive(Debug, Clone)]
11191116
pub struct NotificationsConfig {
11201117
pub cargo_toml_not_found: bool,
1121-
pub unindexed_project: bool,
11221118
}
11231119

11241120
#[derive(Debug, Clone)]
@@ -1828,7 +1824,6 @@ impl Config {
18281824
pub fn notifications(&self) -> NotificationsConfig {
18291825
NotificationsConfig {
18301826
cargo_toml_not_found: self.notifications_cargoTomlNotFound().to_owned(),
1831-
unindexed_project: self.notifications_unindexedProject().to_owned(),
18321827
}
18331828
}
18341829

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ pub(crate) fn handle_did_open_text_document(
7373

7474
tracing::info!("New file content set {:?}", params.text_document.text);
7575
state.vfs.write().0.set_file_contents(path, Some(params.text_document.text.into_bytes()));
76-
if state.config.discover_command().is_some()
77-
|| state.config.notifications().unindexed_project
78-
{
76+
if state.config.discover_command().is_some() {
7977
tracing::debug!("queuing task");
8078
let _ = state
8179
.deferred_task_queue

crates/rust-analyzer/src/lsp/ext.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -856,16 +856,3 @@ pub struct CompletionImport {
856856
pub struct ClientCommandOptions {
857857
pub commands: Vec<String>,
858858
}
859-
860-
pub enum UnindexedProject {}
861-
862-
impl Notification for UnindexedProject {
863-
type Params = UnindexedProjectParams;
864-
const METHOD: &'static str = "rust-analyzer/unindexedProject";
865-
}
866-
867-
#[derive(Deserialize, Serialize, Debug)]
868-
#[serde(rename_all = "camelCase")]
869-
pub struct UnindexedProjectParams {
870-
pub text_documents: Vec<TextDocumentIdentifier>,
871-
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ pub(crate) enum QueuedTask {
9191
pub(crate) enum Task {
9292
Response(lsp_server::Response),
9393
DiscoverLinkedProjects(DiscoverProjectParam),
94-
ClientNotification(lsp_ext::UnindexedProjectParams),
9594
Retry(lsp_server::Request),
9695
Diagnostics(DiagnosticsGeneration, Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
9796
DiscoverTest(lsp_ext::DiscoverTestResults),
@@ -634,9 +633,6 @@ impl GlobalState {
634633
fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) {
635634
match task {
636635
Task::Response(response) => self.respond(response),
637-
Task::ClientNotification(params) => {
638-
self.send_notification::<lsp_ext::UnindexedProject>(params)
639-
}
640636
// Only retry requests that haven't been cancelled. Otherwise we do unnecessary work.
641637
Task::Retry(req) if !self.is_completed(&req) => self.on_request(req),
642638
Task::Retry(_) => (),
@@ -813,12 +809,7 @@ impl GlobalState {
813809
if snap.config.discover_command().is_some() {
814810
let arg = DiscoverProjectParam::Path(uri);
815811
sender.send(Task::DiscoverLinkedProjects(arg)).unwrap();
816-
} else if snap.config.notifications().unindexed_project {
817-
let params = lsp_ext::UnindexedProjectParams {
818-
text_documents: vec![lsp_types::TextDocumentIdentifier { uri }],
819-
};
820-
sender.send(Task::ClientNotification(params)).unwrap();
821-
};
812+
}
822813
} else {
823814
tracing::debug!(?uri, "is indexed");
824815
}

crates/rust-analyzer/tests/slow-tests/main.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ use lsp_types::{
3232
RenameFilesParams, TextDocumentItem, TextDocumentPositionParams, WorkDoneProgressParams,
3333
};
3434
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams};
35-
36-
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams, UnindexedProject};
3735
use serde_json::json;
3836
use stdx::format_to_acc;
3937

@@ -824,66 +822,6 @@ fn main() {{}}
824822
);
825823
}
826824

827-
#[test]
828-
fn test_opening_a_file_outside_of_indexed_workspace() {
829-
if skip_slow_tests() {
830-
return;
831-
}
832-
833-
let tmp_dir = TestDir::new();
834-
let path = tmp_dir.path();
835-
836-
let project = json!({
837-
"roots": [path],
838-
"crates": [ {
839-
"root_module": path.join("src/crate_one/lib.rs"),
840-
"deps": [],
841-
"edition": "2015",
842-
"cfg": [ "cfg_atom_1", "feature=\"cfg_1\""],
843-
} ]
844-
});
845-
846-
let code = format!(
847-
r#"
848-
//- /rust-project.json
849-
{project}
850-
851-
//- /src/crate_one/lib.rs
852-
mod bar;
853-
854-
fn main() {{}}
855-
"#,
856-
);
857-
858-
let server = Project::with_fixture(&code)
859-
.tmp_dir(tmp_dir)
860-
.with_config(serde_json::json!({
861-
"notifications": {
862-
"unindexedProject": true
863-
},
864-
}))
865-
.server()
866-
.wait_until_workspace_is_loaded();
867-
868-
let uri = server.doc_id("src/crate_two/lib.rs").uri;
869-
server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
870-
text_document: TextDocumentItem {
871-
uri: uri.clone(),
872-
language_id: "rust".to_owned(),
873-
version: 0,
874-
text: "/// Docs\nfn foo() {}".to_owned(),
875-
},
876-
});
877-
let expected = json!({
878-
"textDocuments": [
879-
{
880-
"uri": uri
881-
}
882-
]
883-
});
884-
server.expect_notification::<UnindexedProject>(expected);
885-
}
886-
887825
#[test]
888826
fn diagnostics_dont_block_typing() {
889827
if skip_slow_tests() {

crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -256,40 +256,6 @@ impl Server {
256256
self.send_notification(r)
257257
}
258258

259-
pub(crate) fn expect_notification<N>(&self, expected: Value)
260-
where
261-
N: lsp_types::notification::Notification,
262-
N::Params: Serialize,
263-
{
264-
while let Some(Message::Notification(actual)) =
265-
recv_timeout(&self.client.receiver).unwrap_or_else(|_| panic!("timed out"))
266-
{
267-
if actual.method == N::METHOD {
268-
let actual = actual
269-
.clone()
270-
.extract::<Value>(N::METHOD)
271-
.expect("was not able to extract notification");
272-
273-
tracing::debug!(?actual, "got notification");
274-
if let Some((expected_part, actual_part)) = find_mismatch(&expected, &actual) {
275-
panic!(
276-
"JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n",
277-
to_string_pretty(&expected).unwrap(),
278-
to_string_pretty(&actual).unwrap(),
279-
to_string_pretty(expected_part).unwrap(),
280-
to_string_pretty(actual_part).unwrap(),
281-
);
282-
} else {
283-
tracing::debug!("successfully matched notification");
284-
return;
285-
}
286-
} else {
287-
continue;
288-
}
289-
}
290-
panic!("never got expected notification");
291-
}
292-
293259
#[track_caller]
294260
pub(crate) fn request<R>(&self, params: R::Params, expected_resp: Value)
295261
where

docs/dev/lsp-extensions.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -592,25 +592,6 @@ Reloads project information (that is, re-executes `cargo metadata`).
592592

593593
Rebuilds build scripts and proc-macros, and runs the build scripts to reseed the build data.
594594

595-
## Unindexed Project
596-
597-
**Experimental Client Capability:** `{ "unindexedProject": boolean }`
598-
599-
**Method:** `rust-analyzer/unindexedProject`
600-
601-
**Notification:**
602-
603-
```typescript
604-
interface UnindexedProjectParams {
605-
/// A list of documents that rust-analyzer has determined are not indexed.
606-
textDocuments: lc.TextDocumentIdentifier[]
607-
}
608-
```
609-
610-
This notification is sent from the server to the client. The client is expected
611-
to determine the appropriate owners of `textDocuments` and update `linkedProjects`
612-
if an owner can be determined successfully.
613-
614595
## Server Status
615596

616597
**Experimental Client Capability:** `{ "serverStatusNotification": boolean }`

docs/user/generated_config.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,6 @@ Sets the LRU capacity of the specified queries.
811811
--
812812
Whether to show `can't find Cargo.toml` error message.
813813
--
814-
[[rust-analyzer.notifications.unindexedProject]]rust-analyzer.notifications.unindexedProject (default: `false`)::
815-
+
816-
--
817-
Whether to send an UnindexedProject notification to the client.
818-
--
819814
[[rust-analyzer.numThreads]]rust-analyzer.numThreads (default: `null`)::
820815
+
821816
--

editors/code/package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,16 +2224,6 @@
22242224
}
22252225
}
22262226
},
2227-
{
2228-
"title": "notifications",
2229-
"properties": {
2230-
"rust-analyzer.notifications.unindexedProject": {
2231-
"markdownDescription": "Whether to send an UnindexedProject notification to the client.",
2232-
"default": false,
2233-
"type": "boolean"
2234-
}
2235-
}
2236-
},
22372227
{
22382228
"title": "general",
22392229
"properties": {
@@ -2538,6 +2528,22 @@
25382528
}
25392529
}
25402530
},
2531+
{
2532+
"title": "workspace",
2533+
"properties": {
2534+
"rust-analyzer.workspace.discoverCommand": {
2535+
"markdownDescription": "Enables automatic discovery of projects using the discoverCommand.\n\nSetting this command will result in rust-analyzer starting indexing\nonly once a Rust file has been opened.",
2536+
"default": null,
2537+
"type": [
2538+
"null",
2539+
"array"
2540+
],
2541+
"items": {
2542+
"type": "string"
2543+
}
2544+
}
2545+
}
2546+
},
25412547
{
25422548
"title": "workspace",
25432549
"properties": {

editors/code/src/client.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,7 @@ export async function createClient(
102102
const resp = await next(params, token);
103103
if (resp && Array.isArray(resp)) {
104104
return resp.map((val) => {
105-
return prepareVSCodeConfig(val, (key, cfg) => {
106-
// we only want to set discovered workspaces on the right key
107-
// and if a workspace has been discovered.
108-
if (
109-
key === "linkedProjects" &&
110-
config.discoveredWorkspaces.length > 0
111-
) {
112-
cfg[key] = config.discoveredWorkspaces;
113-
}
114-
});
105+
return prepareVSCodeConfig(val);
115106
});
116107
} else {
117108
return resp;

editors/code/src/config.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as vscode from "vscode";
55
import type { Env } from "./client";
66
import { log } from "./util";
77
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
8-
import type { JsonProject } from "./rust_project";
98

109
export type RunnableEnvCfgItem = {
1110
mask?: string;
@@ -41,7 +40,6 @@ export class Config {
4140

4241
constructor(ctx: vscode.ExtensionContext) {
4342
this.globalStorageUri = ctx.globalStorageUri;
44-
this.discoveredWorkspaces = [];
4543
vscode.workspace.onDidChangeConfiguration(
4644
this.onDidChangeConfiguration,
4745
this,
@@ -63,8 +61,6 @@ export class Config {
6361
log.info("Using configuration", Object.fromEntries(cfg));
6462
}
6563

66-
public discoveredWorkspaces: JsonProject[];
67-
6864
private async onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
6965
this.refreshLogging();
7066

@@ -357,18 +353,7 @@ export class Config {
357353
}
358354
}
359355

360-
// the optional `cb?` parameter is meant to be used to add additional
361-
// key/value pairs to the VS Code configuration. This needed for, e.g.,
362-
// including a `rust-project.json` into the `linkedProjects` key as part
363-
// of the configuration/InitializationParams _without_ causing VS Code
364-
// configuration to be written out to workspace-level settings. This is
365-
// undesirable behavior because rust-project.json files can be tens of
366-
// thousands of lines of JSON, most of which is not meant for humans
367-
// to interact with.
368-
export function prepareVSCodeConfig<T>(
369-
resp: T,
370-
cb?: (key: Extract<keyof T, string>, res: { [key: string]: any }) => void,
371-
): T {
356+
export function prepareVSCodeConfig<T>(resp: T): T {
372357
if (Is.string(resp)) {
373358
return substituteVSCodeVariableInString(resp) as T;
374359
} else if (resp && Is.array<any>(resp)) {
@@ -380,9 +365,6 @@ export function prepareVSCodeConfig<T>(
380365
for (const key in resp) {
381366
const val = resp[key];
382367
res[key] = prepareVSCodeConfig(val);
383-
if (cb) {
384-
cb(key, res);
385-
}
386368
}
387369
return res as T;
388370
}

0 commit comments

Comments
 (0)