mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Encode edition within FileId in the hir layer
This commit is contained in:
parent
92268627a8
commit
5264f86242
160 changed files with 1117 additions and 824 deletions
|
@ -78,13 +78,13 @@ mod tests;
|
|||
use hir::{diagnostics::AnyDiagnostic, InFile, Semantics};
|
||||
use ide_db::{
|
||||
assists::{Assist, AssistId, AssistKind, AssistResolveStrategy},
|
||||
base_db::{FileId, FileRange, SourceDatabase},
|
||||
base_db::SourceDatabase,
|
||||
generated::lints::{LintGroup, CLIPPY_LINT_GROUPS, DEFAULT_LINT_GROUPS},
|
||||
imports::insert_use::InsertUseConfig,
|
||||
label::Label,
|
||||
source_change::SourceChange,
|
||||
syntax_helpers::node_ext::parse_tt_as_comma_sep_paths,
|
||||
FxHashMap, FxHashSet, RootDatabase, SnippetCap,
|
||||
EditionedFileId, FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, SnippetCap,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use stdx::never;
|
||||
|
@ -144,12 +144,16 @@ pub struct Diagnostic {
|
|||
}
|
||||
|
||||
impl Diagnostic {
|
||||
fn new(code: DiagnosticCode, message: impl Into<String>, range: FileRange) -> Diagnostic {
|
||||
fn new(
|
||||
code: DiagnosticCode,
|
||||
message: impl Into<String>,
|
||||
range: impl Into<FileRange>,
|
||||
) -> Diagnostic {
|
||||
let message = message.into();
|
||||
Diagnostic {
|
||||
code,
|
||||
message,
|
||||
range,
|
||||
range: range.into(),
|
||||
severity: match code {
|
||||
DiagnosticCode::RustcHardError(_) => Severity::Error,
|
||||
// FIXME: Rustc lints are not always warning, but the ones that are currently implemented are all warnings.
|
||||
|
@ -290,6 +294,7 @@ impl DiagnosticsContext<'_> {
|
|||
}
|
||||
})()
|
||||
.unwrap_or_else(|| sema.diagnostics_display_range(*node))
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,6 +308,9 @@ pub fn diagnostics(
|
|||
) -> Vec<Diagnostic> {
|
||||
let _p = tracing::info_span!("diagnostics").entered();
|
||||
let sema = Semantics::new(db);
|
||||
let file_id = sema
|
||||
.attach_first_edition(file_id)
|
||||
.unwrap_or_else(|| EditionedFileId::current_edition(file_id));
|
||||
let mut res = Vec::new();
|
||||
|
||||
// [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
|
||||
|
@ -310,7 +318,7 @@ pub fn diagnostics(
|
|||
Diagnostic::new(
|
||||
DiagnosticCode::RustcHardError("syntax-error"),
|
||||
format!("Syntax Error: {err}"),
|
||||
FileRange { file_id, range: err.range() },
|
||||
FileRange { file_id: file_id.into(), range: err.range() },
|
||||
)
|
||||
}));
|
||||
let parse_errors = res.len();
|
||||
|
@ -336,7 +344,7 @@ pub fn diagnostics(
|
|||
// file, so we skip semantic diagnostics so we can show these faster.
|
||||
Some(m) if parse_errors < 16 => m.diagnostics(db, &mut diags, config.style_lints),
|
||||
Some(_) => (),
|
||||
None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, file_id),
|
||||
None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, file_id.file_id()),
|
||||
}
|
||||
|
||||
for diag in diags {
|
||||
|
@ -627,4 +635,5 @@ fn adjusted_display_range<N: AstNode>(
|
|||
diag_ptr
|
||||
.with_value(adj(node).unwrap_or_else(|| diag_ptr.value.text_range()))
|
||||
.original_node_file_range_rooted(ctx.sema.db)
|
||||
.into()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue