Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: let diagnostics.enable's scope be limited to DiagnosticsCode::Ra only #17146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/ide-diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ pub fn diagnostics(
}

res.retain(|d| {
!(ctx.config.disabled.contains(d.code.as_str())
!(matches!(d.code, DiagnosticCode::Ra(..)) && !ctx.config.enabled
|| ctx.config.disabled.contains(d.code.as_str())
|| ctx.config.disable_experimental && d.experimental)
});

Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ impl Analysis {
};

self.with_db(|db| {
let diagnostic_assists = if diagnostics_config.enabled && include_fixes {
let diagnostic_assists = if include_fixes {
ide_diagnostics::diagnostics(db, diagnostics_config, &resolve, frange.file_id)
.into_iter()
.flat_map(|it| it.fixes.unwrap_or_default())
Expand Down
91 changes: 89 additions & 2 deletions crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod support;
mod testdir;
mod tidy;

use std::{collections::HashMap, path::PathBuf, time::Instant};
use std::{collections::HashMap, path::PathBuf, str::FromStr, time::Instant};

use lsp_types::{
notification::DidOpenTextDocument,
Expand All @@ -28,7 +28,8 @@ use lsp_types::{
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
InlayHint, InlayHintLabel, InlayHintParams, PartialResultParams, Position, Range,
RenameFilesParams, TextDocumentItem, TextDocumentPositionParams, WorkDoneProgressParams,
RenameFilesParams, TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url,
WorkDoneProgressParams,
};
use rust_analyzer::lsp::ext::{OnEnter, Runnables, RunnablesParams, UnindexedProject};
use serde_json::json;
Expand Down Expand Up @@ -1374,3 +1375,89 @@ version = "0.0.0"

server.request::<WorkspaceSymbolRequest>(Default::default(), json!([]));
}

/// Issue #17048 reports that setting "rust-analyzer.diagnostics.enable" to false
/// causes "missing fields" diagnostics to not disappear. This test makes sure that
/// this is not the case anymore.
#[test]
fn test_fill_missing_fields_is_rustc_diagnostic() {
if skip_slow_tests() {
return;
}

let tmp_dir = TestDir::new();
let tmp_dir_path = tmp_dir.path().to_owned();
let tmp_dir_str = tmp_dir_path.as_str();

let server = Project::with_fixture(
r#"
//- /foo/Cargo.toml
[package]
name = "sandbox"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]


//- /foo/src/lib.rs
struct St {
a: u8,
b: u8,
}

fn abc() {
let a = St {};
}
"#,
)
.with_config(json!({
"hover": {
"documentation" : {
"keywords": {
"enable": false
}
}
},
"cargo" : {
"buildScripts" : {
"useRustcWrapper": false
}
},
"workspace" : {
"symbol" : {
"search" : {
"kind": "all_symbols"
}
}
},
"diagnostics" : {
"enable": false
},
"inlayHints" : {
"closureStyle" : "rust_analyzer"
},
"cargo" : {
"sysrootQueryMetadata": true
},
}))
.root("foo")
.tmp_dir(tmp_dir)
.server()
.wait_until_workspace_is_loaded();

let _ = server.send_request::<CodeActionRequest>(CodeActionParams {
text_document: TextDocumentIdentifier {
uri: Url::from_str(&format!("file://{tmp_dir_str}/foo/src/lib.rs")).unwrap(),
},
range: Range {
start: Position { line: 6, character: 16 },
end: Position { line: 6, character: 17 },
},
context: CodeActionContext::default(),
work_done_progress_params: WorkDoneProgressParams::default(),
partial_result_params: PartialResultParams::default(),
});
}