Skip to content

Commit eb5da56

Browse files
committed
Auto merge of #17395 - davidbarsky:david/remove-unindexed-project-notification, r=Veykril
chore: remove `UnindexinedProject` notification This PR is split out from #17246 (and contains its changes, which is a little annoying from a review perspective...). I'd like to land this change a week or so after #17246 lands in order to give any users of the unindexed project notification time to adopt migrate.
2 parents 7507695 + 2783aa7 commit eb5da56

File tree

15 files changed

+14
-366
lines changed

15 files changed

+14
-366
lines changed

Diff for: crates/rust-analyzer/src/config.rs

-5
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,6 @@ config_data! {
679679
/// Whether to show `can't find Cargo.toml` error message.
680680
notifications_cargoTomlNotFound: bool = true,
681681

682-
/// Whether to send an UnindexedProject notification to the client.
683-
notifications_unindexedProject: bool = false,
684-
685682
/// How many worker threads in the main loop. The default `null` means to pick automatically.
686683
numThreads: Option<NumThreads> = None,
687684

@@ -1236,7 +1233,6 @@ pub enum FilesWatcher {
12361233
#[derive(Debug, Clone)]
12371234
pub struct NotificationsConfig {
12381235
pub cargo_toml_not_found: bool,
1239-
pub unindexed_project: bool,
12401236
}
12411237

12421238
#[derive(Debug, Clone)]
@@ -1800,7 +1796,6 @@ impl Config {
18001796
pub fn notifications(&self) -> NotificationsConfig {
18011797
NotificationsConfig {
18021798
cargo_toml_not_found: self.notifications_cargoTomlNotFound().to_owned(),
1803-
unindexed_project: self.notifications_unindexedProject().to_owned(),
18041799
}
18051800
}
18061801

Diff for: crates/rust-analyzer/src/handlers/notification.rs

+1-3
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_workspace_config().is_some()
77-
|| state.config.notifications().unindexed_project
78-
{
76+
if state.config.discover_workspace_config().is_some() {
7977
tracing::debug!("queuing task");
8078
let _ = state
8179
.deferred_task_queue

Diff for: crates/rust-analyzer/src/lsp/ext.rs

-13
Original file line numberDiff line numberDiff line change
@@ -834,16 +834,3 @@ pub struct CompletionImport {
834834
pub struct ClientCommandOptions {
835835
pub commands: Vec<String>,
836836
}
837-
838-
pub enum UnindexedProject {}
839-
840-
impl Notification for UnindexedProject {
841-
type Params = UnindexedProjectParams;
842-
const METHOD: &'static str = "rust-analyzer/unindexedProject";
843-
}
844-
845-
#[derive(Deserialize, Serialize, Debug)]
846-
#[serde(rename_all = "camelCase")]
847-
pub struct UnindexedProjectParams {
848-
pub text_documents: Vec<TextDocumentIdentifier>,
849-
}

Diff for: crates/rust-analyzer/src/main_loop.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub(crate) enum QueuedTask {
9090
pub(crate) enum Task {
9191
Response(lsp_server::Response),
9292
DiscoverLinkedProjects(DiscoverProjectParam),
93-
ClientNotification(lsp_ext::UnindexedProjectParams),
9493
Retry(lsp_server::Request),
9594
Diagnostics(DiagnosticsGeneration, Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
9695
DiscoverTest(lsp_ext::DiscoverTestResults),
@@ -642,9 +641,6 @@ impl GlobalState {
642641
fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) {
643642
match task {
644643
Task::Response(response) => self.respond(response),
645-
Task::ClientNotification(params) => {
646-
self.send_notification::<lsp_ext::UnindexedProject>(params)
647-
}
648644
// Only retry requests that haven't been cancelled. Otherwise we do unnecessary work.
649645
Task::Retry(req) if !self.is_completed(&req) => self.on_request(req),
650646
Task::Retry(_) => (),
@@ -825,12 +821,7 @@ impl GlobalState {
825821
from_proto::abs_path(&uri).expect("Unable to get AbsPath");
826822
let arg = DiscoverProjectParam::Path(path);
827823
sender.send(Task::DiscoverLinkedProjects(arg)).unwrap();
828-
} else if snap.config.notifications().unindexed_project {
829-
let params = lsp_ext::UnindexedProjectParams {
830-
text_documents: vec![lsp_types::TextDocumentIdentifier { uri }],
831-
};
832-
sender.send(Task::ClientNotification(params)).unwrap();
833-
};
824+
}
834825
} else {
835826
tracing::debug!(?uri, "is indexed");
836827
}

Diff for: crates/rust-analyzer/tests/slow-tests/main.rs

+1-61
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use lsp_types::{
2727
InlayHint, InlayHintLabel, InlayHintParams, PartialResultParams, Position, Range,
2828
RenameFilesParams, TextDocumentItem, TextDocumentPositionParams, WorkDoneProgressParams,
2929
};
30-
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams, UnindexedProject};
30+
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams};
3131
use serde_json::json;
3232
use stdx::format_to_acc;
3333

@@ -811,66 +811,6 @@ fn main() {{}}
811811
);
812812
}
813813

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

Diff for: crates/rust-analyzer/tests/slow-tests/support.rs

-34
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

Diff for: docs/dev/lsp-extensions.md

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp/ext.rs hash: 278250dba58cd879
2+
lsp/ext.rs hash: f41950db4c7b3a5a
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:
@@ -616,25 +616,6 @@ Reloads project information (that is, re-executes `cargo metadata`).
616616

617617
Rebuilds build scripts and proc-macros, and runs the build scripts to reseed the build data.
618618

619-
## Unindexed Project
620-
621-
**Experimental Client Capability:** `{ "unindexedProject": boolean }`
622-
623-
**Method:** `rust-analyzer/unindexedProject`
624-
625-
**Notification:**
626-
627-
```typescript
628-
interface UnindexedProjectParams {
629-
/// A list of documents that rust-analyzer has determined are not indexed.
630-
textDocuments: lc.TextDocumentIdentifier[]
631-
}
632-
```
633-
634-
This notification is sent from the server to the client. The client is expected
635-
to determine the appropriate owners of `textDocuments` and update `linkedProjects`
636-
if an owner can be determined successfully.
637-
638619
## Server Status
639620

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

Diff for: docs/user/generated_config.adoc

-5
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,6 @@ Sets the LRU capacity of the specified queries.
830830
--
831831
Whether to show `can't find Cargo.toml` error message.
832832
--
833-
[[rust-analyzer.notifications.unindexedProject]]rust-analyzer.notifications.unindexedProject (default: `false`)::
834-
+
835-
--
836-
Whether to send an UnindexedProject notification to the client.
837-
--
838833
[[rust-analyzer.numThreads]]rust-analyzer.numThreads (default: `null`)::
839834
+
840835
--

Diff for: editors/code/package.json

-10
Original file line numberDiff line numberDiff line change
@@ -2267,16 +2267,6 @@
22672267
}
22682268
}
22692269
},
2270-
{
2271-
"title": "notifications",
2272-
"properties": {
2273-
"rust-analyzer.notifications.unindexedProject": {
2274-
"markdownDescription": "Whether to send an UnindexedProject notification to the client.",
2275-
"default": false,
2276-
"type": "boolean"
2277-
}
2278-
}
2279-
},
22802270
{
22812271
"title": "general",
22822272
"properties": {

Diff for: editors/code/src/client.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,7 @@ export async function createClient(
4242
const resp = await next(params, token);
4343
if (resp && Array.isArray(resp)) {
4444
return resp.map((val) => {
45-
return prepareVSCodeConfig(val, (key, cfg) => {
46-
// we only want to set discovered workspaces on the right key
47-
// and if a workspace has been discovered.
48-
if (
49-
key === "linkedProjects" &&
50-
config.discoveredWorkspaces.length > 0
51-
) {
52-
cfg[key] = config.discoveredWorkspaces;
53-
}
54-
});
45+
return prepareVSCodeConfig(val);
5546
});
5647
} else {
5748
return resp;

Diff for: editors/code/src/config.ts

+4-21
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as Is from "vscode-languageclient/lib/common/utils/is";
22
import * as os from "os";
33
import * as path from "path";
44
import * as vscode from "vscode";
5-
import { type Env, log, unwrapUndefinable, expectNotUndefined } from "./util";
6-
import type { JsonProject } from "./rust_project";
7-
import type { Disposable } from "./ctx";
5+
import { expectNotUndefined, log, unwrapUndefinable } from "./util";
6+
import type { Env } from "./util";
7+
import type { Disposable } from "vscode";
88

99
export type RunnableEnvCfgItem = {
1010
mask?: string;
@@ -31,7 +31,6 @@ export class Config {
3131
);
3232

3333
constructor(disposables: Disposable[]) {
34-
this.discoveredWorkspaces = [];
3534
vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, disposables);
3635
this.refreshLogging();
3736
this.configureLanguage();
@@ -52,8 +51,6 @@ export class Config {
5251
log.info("Using configuration", Object.fromEntries(cfg));
5352
}
5453

55-
public discoveredWorkspaces: JsonProject[];
56-
5754
private async onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
5855
this.refreshLogging();
5956

@@ -342,18 +339,7 @@ export class Config {
342339
}
343340
}
344341

345-
// the optional `cb?` parameter is meant to be used to add additional
346-
// key/value pairs to the VS Code configuration. This needed for, e.g.,
347-
// including a `rust-project.json` into the `linkedProjects` key as part
348-
// of the configuration/InitializationParams _without_ causing VS Code
349-
// configuration to be written out to workspace-level settings. This is
350-
// undesirable behavior because rust-project.json files can be tens of
351-
// thousands of lines of JSON, most of which is not meant for humans
352-
// to interact with.
353-
export function prepareVSCodeConfig<T>(
354-
resp: T,
355-
cb?: (key: Extract<keyof T, string>, res: { [key: string]: any }) => void,
356-
): T {
342+
export function prepareVSCodeConfig<T>(resp: T): T {
357343
if (Is.string(resp)) {
358344
return substituteVSCodeVariableInString(resp) as T;
359345
} else if (resp && Is.array<any>(resp)) {
@@ -365,9 +351,6 @@ export function prepareVSCodeConfig<T>(
365351
for (const key in resp) {
366352
const val = resp[key];
367353
res[key] = prepareVSCodeConfig(val);
368-
if (cb) {
369-
cb(key, res);
370-
}
371354
}
372355
return res as T;
373356
}

0 commit comments

Comments
 (0)