Skip to content

Commit

Permalink
internal: remove UnindexedProject notification
Browse files Browse the repository at this point in the history
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
  • Loading branch information
davidbarsky committed Jun 11, 2024
1 parent 651983d commit 25300f1
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 373 deletions.
5 changes: 0 additions & 5 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,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<NumThreads> = None,

Expand Down Expand Up @@ -1118,7 +1115,6 @@ pub enum FilesWatcher {
#[derive(Debug, Clone)]
pub struct NotificationsConfig {
pub cargo_toml_not_found: bool,
pub unindexed_project: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1828,7 +1824,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(),
}
}

Expand Down
4 changes: 1 addition & 3 deletions crates/rust-analyzer/src/handlers/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_command().is_some()
|| state.config.notifications().unindexed_project
{
if state.config.discover_command().is_some() {
tracing::debug!("queuing task");
let _ = state
.deferred_task_queue
Expand Down
13 changes: 0 additions & 13 deletions crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,16 +856,3 @@ pub struct CompletionImport {
pub struct ClientCommandOptions {
pub commands: Vec<String>,
}

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<TextDocumentIdentifier>,
}
11 changes: 1 addition & 10 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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<lsp_types::Diagnostic>)>),
DiscoverTest(lsp_ext::DiscoverTestResults),
Expand Down Expand Up @@ -634,9 +633,6 @@ impl GlobalState {
fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) {
match task {
Task::Response(response) => self.respond(response),
Task::ClientNotification(params) => {
self.send_notification::<lsp_ext::UnindexedProject>(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(_) => (),
Expand Down Expand Up @@ -813,12 +809,7 @@ impl GlobalState {
if snap.config.discover_command().is_some() {
let arg = DiscoverProjectParam::Path(uri);
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");
}
Expand Down
62 changes: 0 additions & 62 deletions crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ use lsp_types::{
RenameFilesParams, TextDocumentItem, TextDocumentPositionParams, WorkDoneProgressParams,
};
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams};

use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams, UnindexedProject};
use serde_json::json;
use stdx::format_to_acc;

Expand Down Expand Up @@ -824,66 +822,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::<DidOpenTextDocument>(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::<UnindexedProject>(expected);
}

#[test]
fn diagnostics_dont_block_typing() {
if skip_slow_tests() {
Expand Down
34 changes: 0 additions & 34 deletions crates/rust-analyzer/tests/slow-tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,40 +256,6 @@ impl Server {
self.send_notification(r)
}

pub(crate) fn expect_notification<N>(&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::<Value>(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<R>(&self, params: R::Params, expected_resp: Value)
where
Expand Down
19 changes: 0 additions & 19 deletions docs/dev/lsp-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,25 +592,6 @@ Reloads project information (that is, re-executes `cargo metadata`).

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

## Unindexed Project

**Experimental Client Capability:** `{ "unindexedProject": boolean }`

**Method:** `rust-analyzer/unindexedProject`

**Notification:**

```typescript
interface UnindexedProjectParams {
/// A list of documents that rust-analyzer has determined are not indexed.
textDocuments: lc.TextDocumentIdentifier[]
}
```

This notification is sent from the server to the client. The client is expected
to determine the appropriate owners of `textDocuments` and update `linkedProjects`
if an owner can be determined successfully.

## Server Status

**Experimental Client Capability:** `{ "serverStatusNotification": boolean }`
Expand Down
5 changes: 0 additions & 5 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,6 @@ Sets the LRU capacity of the specified queries.
--
Whether to show `can't find Cargo.toml` error message.
--
[[rust-analyzer.notifications.unindexedProject]]rust-analyzer.notifications.unindexedProject (default: `false`)::
+
--
Whether to send an UnindexedProject notification to the client.
--
[[rust-analyzer.numThreads]]rust-analyzer.numThreads (default: `null`)::
+
--
Expand Down
26 changes: 16 additions & 10 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2224,16 +2224,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": {
Expand Down Expand Up @@ -2538,6 +2528,22 @@
}
}
},
{
"title": "workspace",
"properties": {
"rust-analyzer.workspace.discoverCommand": {
"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.",
"default": null,
"type": [
"null",
"array"
],
"items": {
"type": "string"
}
}
}
},
{
"title": "workspace",
"properties": {
Expand Down
11 changes: 1 addition & 10 deletions editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,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;
Expand Down
20 changes: 1 addition & 19 deletions editors/code/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as vscode from "vscode";
import type { Env } from "./client";
import { log } from "./util";
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
import type { JsonProject } from "./rust_project";

export type RunnableEnvCfgItem = {
mask?: string;
Expand Down Expand Up @@ -41,7 +40,6 @@ export class Config {

constructor(ctx: vscode.ExtensionContext) {
this.globalStorageUri = ctx.globalStorageUri;
this.discoveredWorkspaces = [];
vscode.workspace.onDidChangeConfiguration(
this.onDidChangeConfiguration,
this,
Expand All @@ -63,8 +61,6 @@ export class Config {
log.info("Using configuration", Object.fromEntries(cfg));
}

public discoveredWorkspaces: JsonProject[];

private async onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
this.refreshLogging();

Expand Down Expand Up @@ -357,18 +353,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)) {
Expand All @@ -380,9 +365,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;
}
Expand Down
Loading

0 comments on commit 25300f1

Please sign in to comment.