From 2783aa731215f0cc487202fb78a84513daab8993 Mon Sep 17 00:00:00 2001 From: David Barsky Date: Tue, 23 Jul 2024 13:34:03 -0400 Subject: [PATCH] internal: remove UnindexedProject notification Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- crates/rust-analyzer/src/config.rs | 5 - .../src/handlers/notification.rs | 4 +- crates/rust-analyzer/src/lsp/ext.rs | 13 --- crates/rust-analyzer/src/main_loop.rs | 11 +- crates/rust-analyzer/tests/slow-tests/main.rs | 62 +--------- .../rust-analyzer/tests/slow-tests/support.rs | 34 ------ docs/dev/lsp-extensions.md | 21 +--- docs/user/generated_config.adoc | 5 - editors/code/package.json | 10 -- editors/code/src/client.ts | 11 +- editors/code/src/config.ts | 25 +--- editors/code/src/ctx.ts | 57 +-------- editors/code/src/lsp_ext.ts | 6 - editors/code/src/main.ts | 6 +- editors/code/src/rust_project.ts | 110 ------------------ 15 files changed, 14 insertions(+), 366 deletions(-) delete mode 100644 editors/code/src/rust_project.ts diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 590513796789..c9c2c516bd6b 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -679,9 +679,6 @@ config_data! { /// Whether to show `can't find Cargo.toml` error message. notifications_cargoTomlNotFound: bool = true, - /// Whether to send an UnindexedProject notification to the client. - notifications_unindexedProject: bool = false, - /// How many worker threads in the main loop. The default `null` means to pick automatically. numThreads: Option = None, @@ -1215,7 +1212,6 @@ pub enum FilesWatcher { #[derive(Debug, Clone)] pub struct NotificationsConfig { pub cargo_toml_not_found: bool, - pub unindexed_project: bool, } #[derive(Debug, Clone)] @@ -1776,7 +1772,6 @@ impl Config { pub fn notifications(&self) -> NotificationsConfig { NotificationsConfig { cargo_toml_not_found: self.notifications_cargoTomlNotFound().to_owned(), - unindexed_project: self.notifications_unindexedProject().to_owned(), } } diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index 06e893f0f471..4b14dcfc3721 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -73,9 +73,7 @@ pub(crate) fn handle_did_open_text_document( tracing::info!("New file content set {:?}", params.text_document.text); state.vfs.write().0.set_file_contents(path, Some(params.text_document.text.into_bytes())); - if state.config.discover_workspace_config().is_some() - || state.config.notifications().unindexed_project - { + if state.config.discover_workspace_config().is_some() { tracing::debug!("queuing task"); let _ = state .deferred_task_queue diff --git a/crates/rust-analyzer/src/lsp/ext.rs b/crates/rust-analyzer/src/lsp/ext.rs index efa5d47fbaab..813e9fcd476a 100644 --- a/crates/rust-analyzer/src/lsp/ext.rs +++ b/crates/rust-analyzer/src/lsp/ext.rs @@ -834,16 +834,3 @@ pub struct CompletionImport { pub struct ClientCommandOptions { pub commands: Vec, } - -pub enum UnindexedProject {} - -impl Notification for UnindexedProject { - type Params = UnindexedProjectParams; - const METHOD: &'static str = "rust-analyzer/unindexedProject"; -} - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct UnindexedProjectParams { - pub text_documents: Vec, -} diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index db90d2d964c1..7d5c0e093aae 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -90,7 +90,6 @@ pub(crate) enum QueuedTask { pub(crate) enum Task { Response(lsp_server::Response), DiscoverLinkedProjects(DiscoverProjectParam), - ClientNotification(lsp_ext::UnindexedProjectParams), Retry(lsp_server::Request), Diagnostics(DiagnosticsGeneration, Vec<(FileId, Vec)>), DiscoverTest(lsp_ext::DiscoverTestResults), @@ -642,9 +641,6 @@ impl GlobalState { fn handle_task(&mut self, prime_caches_progress: &mut Vec, task: Task) { match task { Task::Response(response) => self.respond(response), - Task::ClientNotification(params) => { - self.send_notification::(params) - } // Only retry requests that haven't been cancelled. Otherwise we do unnecessary work. Task::Retry(req) if !self.is_completed(&req) => self.on_request(req), Task::Retry(_) => (), @@ -825,12 +821,7 @@ impl GlobalState { from_proto::abs_path(&uri).expect("Unable to get AbsPath"); let arg = DiscoverProjectParam::Path(path); sender.send(Task::DiscoverLinkedProjects(arg)).unwrap(); - } else if snap.config.notifications().unindexed_project { - let params = lsp_ext::UnindexedProjectParams { - text_documents: vec![lsp_types::TextDocumentIdentifier { uri }], - }; - sender.send(Task::ClientNotification(params)).unwrap(); - }; + } } else { tracing::debug!(?uri, "is indexed"); } diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 6bbf82a77547..b1ef48377178 100644 --- a/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs @@ -27,7 +27,7 @@ use lsp_types::{ InlayHint, InlayHintLabel, InlayHintParams, PartialResultParams, Position, Range, RenameFilesParams, TextDocumentItem, TextDocumentPositionParams, WorkDoneProgressParams, }; -use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams, UnindexedProject}; +use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams}; use serde_json::json; use stdx::format_to_acc; @@ -811,66 +811,6 @@ fn main() {{}} ); } -#[test] -fn test_opening_a_file_outside_of_indexed_workspace() { - if skip_slow_tests() { - return; - } - - let tmp_dir = TestDir::new(); - let path = tmp_dir.path(); - - let project = json!({ - "roots": [path], - "crates": [ { - "root_module": path.join("src/crate_one/lib.rs"), - "deps": [], - "edition": "2015", - "cfg": [ "cfg_atom_1", "feature=\"cfg_1\""], - } ] - }); - - let code = format!( - r#" -//- /rust-project.json -{project} - -//- /src/crate_one/lib.rs -mod bar; - -fn main() {{}} -"#, - ); - - let server = Project::with_fixture(&code) - .tmp_dir(tmp_dir) - .with_config(serde_json::json!({ - "notifications": { - "unindexedProject": true - }, - })) - .server() - .wait_until_workspace_is_loaded(); - - let uri = server.doc_id("src/crate_two/lib.rs").uri; - server.notification::(DidOpenTextDocumentParams { - text_document: TextDocumentItem { - uri: uri.clone(), - language_id: "rust".to_owned(), - version: 0, - text: "/// Docs\nfn foo() {}".to_owned(), - }, - }); - let expected = json!({ - "textDocuments": [ - { - "uri": uri - } - ] - }); - server.expect_notification::(expected); -} - #[test] fn diagnostics_dont_block_typing() { if skip_slow_tests() { diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index 66100971fbf3..081ee5fa3e4e 100644 --- a/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs @@ -256,40 +256,6 @@ impl Server { self.send_notification(r) } - pub(crate) fn expect_notification(&self, expected: Value) - where - N: lsp_types::notification::Notification, - N::Params: Serialize, - { - while let Some(Message::Notification(actual)) = - recv_timeout(&self.client.receiver).unwrap_or_else(|_| panic!("timed out")) - { - if actual.method == N::METHOD { - let actual = actual - .clone() - .extract::(N::METHOD) - .expect("was not able to extract notification"); - - tracing::debug!(?actual, "got notification"); - if let Some((expected_part, actual_part)) = find_mismatch(&expected, &actual) { - panic!( - "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", - to_string_pretty(&expected).unwrap(), - to_string_pretty(&actual).unwrap(), - to_string_pretty(expected_part).unwrap(), - to_string_pretty(actual_part).unwrap(), - ); - } else { - tracing::debug!("successfully matched notification"); - return; - } - } else { - continue; - } - } - panic!("never got expected notification"); - } - #[track_caller] pub(crate) fn request(&self, params: R::Params, expected_resp: Value) where diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index fbb4fc6113f9..a29b42a857c9 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -1,5 +1,5 @@