Merge commit '457b966b17' into sync-from-ra

This commit is contained in:
Laurențiu Nicola 2023-12-11 11:16:01 +02:00
parent 5285df4f6c
commit f532576ac5
263 changed files with 9788 additions and 6258 deletions

View file

@ -43,11 +43,6 @@ triomphe.workspace = true
nohash-hasher.workspace = true
always-assert = "0.1.2"
# These 3 deps are not used by r-a directly, but we list them here to lock in their versions
# in our transitive deps to prevent them from pulling in windows-sys 0.45.0
mio = "=0.8.5"
parking_lot_core = "=0.9.6"
cfg.workspace = true
flycheck.workspace = true
hir-def.workspace = true

View file

@ -2,7 +2,7 @@
//!
//! Based on cli flags, either spawns an LSP server, or runs a batch analysis
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#![warn(rust_2018_idioms, unused_lifetimes)]
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
#[cfg(feature = "in-rust-tree")]
#[allow(unused_extern_crates)]

View file

@ -209,7 +209,7 @@ mod tests {
use super::*;
use cfg::CfgExpr;
use mbe::syntax_node_to_token_tree;
use mbe::{syntax_node_to_token_tree, DummyTestSpanMap};
use syntax::{
ast::{self, AstNode},
SmolStr,
@ -219,7 +219,7 @@ mod tests {
let cfg_expr = {
let source_file = ast::SourceFile::parse(cfg).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
let (tt, _) = syntax_node_to_token_tree(tt.syntax());
let tt = syntax_node_to_token_tree(tt.syntax(), &DummyTestSpanMap);
CfgExpr::parse(&tt)
};

View file

@ -8,7 +8,7 @@ use std::{
use hir::{
db::{DefDatabase, ExpandDatabase, HirDatabase},
Adt, AssocItem, Crate, DefWithBody, HasSource, HirDisplay, ModuleDef, Name,
Adt, AssocItem, Crate, DefWithBody, HasSource, HirDisplay, HirFileIdExt, ModuleDef, Name,
};
use hir_def::{
body::{BodySourceMap, SyntheticSyntax},

View file

@ -4,7 +4,7 @@
use project_model::{CargoConfig, RustLibSource};
use rustc_hash::FxHashSet;
use hir::{db::HirDatabase, Crate, Module};
use hir::{db::HirDatabase, Crate, HirFileIdExt, Module};
use ide::{AssistResolveStrategy, DiagnosticsConfig, Severity};
use ide_db::base_db::SourceDatabaseExt;
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};

View file

@ -5,6 +5,7 @@ use std::mem;
use ide::FileId;
use ide_db::FxHashMap;
use itertools::Itertools;
use nohash_hasher::{IntMap, IntSet};
use rustc_hash::FxHashSet;
use triomphe::Arc;
@ -129,8 +130,28 @@ pub(crate) fn fetch_native_diagnostics(
) -> Vec<(FileId, Vec<lsp_types::Diagnostic>)> {
let _p = profile::span("fetch_native_diagnostics");
let _ctx = stdx::panic_context::enter("fetch_native_diagnostics".to_owned());
subscriptions
.into_iter()
let convert_diagnostic =
|line_index: &crate::line_index::LineIndex, d: ide::Diagnostic| lsp_types::Diagnostic {
range: lsp::to_proto::range(&line_index, d.range.range),
severity: Some(lsp::to_proto::diagnostic_severity(d.severity)),
code: Some(lsp_types::NumberOrString::String(d.code.as_str().to_string())),
code_description: Some(lsp_types::CodeDescription {
href: lsp_types::Url::parse(&d.code.url()).unwrap(),
}),
source: Some("rust-analyzer".to_string()),
message: d.message,
related_information: None,
tags: d.unused.then(|| vec![lsp_types::DiagnosticTag::UNNECESSARY]),
data: None,
};
// the diagnostics produced may point to different files not requested by the concrete request,
// put those into here and filter later
let mut odd_ones = Vec::new();
let mut diagnostics = subscriptions
.iter()
.copied()
.filter_map(|file_id| {
let line_index = snapshot.file_line_index(file_id).ok()?;
let diagnostics = snapshot
@ -142,21 +163,39 @@ pub(crate) fn fetch_native_diagnostics(
)
.ok()?
.into_iter()
.map(move |d| lsp_types::Diagnostic {
range: lsp::to_proto::range(&line_index, d.range),
severity: Some(lsp::to_proto::diagnostic_severity(d.severity)),
code: Some(lsp_types::NumberOrString::String(d.code.as_str().to_string())),
code_description: Some(lsp_types::CodeDescription {
href: lsp_types::Url::parse(&d.code.url()).unwrap(),
}),
source: Some("rust-analyzer".to_string()),
message: d.message,
related_information: None,
tags: d.unused.then(|| vec![lsp_types::DiagnosticTag::UNNECESSARY]),
data: None,
.filter_map(|d| {
if d.range.file_id == file_id {
Some(convert_diagnostic(&line_index, d))
} else {
odd_ones.push(d);
None
}
})
.collect::<Vec<_>>();
Some((file_id, diagnostics))
})
.collect()
.collect::<Vec<_>>();
// Add back any diagnostics that point to files we are subscribed to
for (file_id, group) in odd_ones
.into_iter()
.sorted_by_key(|it| it.range.file_id)
.group_by(|it| it.range.file_id)
.into_iter()
{
if !subscriptions.contains(&file_id) {
continue;
}
let Some((_, diagnostics)) = diagnostics.iter_mut().find(|&&mut (id, _)| id == file_id)
else {
continue;
};
let Some(line_index) = snapshot.file_line_index(file_id).ok() else {
break;
};
for diagnostic in group {
diagnostics.push(convert_diagnostic(&line_index, diagnostic));
}
}
diagnostics
}

View file

@ -187,11 +187,9 @@ impl GlobalState {
config_errors: Default::default(),
proc_macro_changed: false,
// FIXME: use `Arc::from_iter` when it becomes available
proc_macro_clients: Arc::from(Vec::new()),
proc_macro_clients: Arc::from_iter([]),
// FIXME: use `Arc::from_iter` when it becomes available
flycheck: Arc::from(Vec::new()),
flycheck: Arc::from_iter([]),
flycheck_sender,
flycheck_receiver,
last_flycheck_error: None,
@ -202,7 +200,7 @@ impl GlobalState {
vfs_progress_n_total: 0,
vfs_progress_n_done: 0,
workspaces: Arc::new(Vec::new()),
workspaces: Arc::from(Vec::new()),
crate_graph_file_dependencies: FxHashSet::default(),
fetch_workspaces_queue: OpQueue::default(),
fetch_build_data_queue: OpQueue::default(),

View file

@ -51,8 +51,7 @@ use crate::{
};
pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
// FIXME: use `Arc::from_iter` when it becomes available
state.proc_macro_clients = Arc::from(Vec::new());
state.proc_macro_clients = Arc::from_iter([]);
state.proc_macro_changed = false;
state.fetch_workspaces_queue.request_op("reload workspace request".to_string(), false);
@ -60,8 +59,7 @@ pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> anyhow:
}
pub(crate) fn handle_proc_macros_rebuild(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
// FIXME: use `Arc::from_iter` when it becomes available
state.proc_macro_clients = Arc::from(Vec::new());
state.proc_macro_clients = Arc::from_iter([]);
state.proc_macro_changed = false;
state.fetch_build_data_queue.request_op("rebuild proc macros request".to_string(), ());
@ -1438,7 +1436,7 @@ pub(crate) fn handle_inlay_hints_resolve(
};
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
let file_id = FileId(resolve_data.file_id);
let file_id = FileId::from_raw(resolve_data.file_id);
anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");
let line_index = snap.file_line_index(file_id)?;

View file

@ -30,7 +30,7 @@ fn integrated_highlighting_benchmark() {
// Load rust-analyzer itself.
let workspace_to_load = project_root();
let file = "./crates/ide-db/src/apply_change.rs";
let file = "./crates/rust-analyzer/src/config.rs";
let cargo_config = CargoConfig::default();
let load_cargo_config = LoadCargoConfig {
@ -57,7 +57,6 @@ fn integrated_highlighting_benchmark() {
}
profile::init_from("*>100");
// let _s = profile::heartbeat_span();
{
let _it = stdx::timeit("change");

View file

@ -9,7 +9,7 @@
//! The `cli` submodule implements some batch-processing analysis, primarily as
//! a debugging aid.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#![warn(rust_2018_idioms, unused_lifetimes)]
pub mod cli;

View file

@ -457,7 +457,7 @@ pub(crate) fn inlay_hint(
inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it))
};
let data = if needs_resolve && something_to_resolve {
Some(to_value(lsp_ext::InlayHintResolveData { file_id: file_id.0 }).unwrap())
Some(to_value(lsp_ext::InlayHintResolveData { file_id: file_id.index() }).unwrap())
} else {
None
};

View file

@ -437,28 +437,22 @@ impl GlobalState {
if self.config.expand_proc_macros() {
tracing::info!("Spawning proc-macro servers");
// FIXME: use `Arc::from_iter` when it becomes available
self.proc_macro_clients = Arc::from(
self.workspaces
.iter()
.map(|ws| {
let path = match self.config.proc_macro_srv() {
Some(path) => path,
None => ws.find_sysroot_proc_macro_srv()?,
};
self.proc_macro_clients = Arc::from_iter(self.workspaces.iter().map(|ws| {
let path = match self.config.proc_macro_srv() {
Some(path) => path,
None => ws.find_sysroot_proc_macro_srv()?,
};
tracing::info!("Using proc-macro server at {path}");
ProcMacroServer::spawn(path.clone()).map_err(|err| {
tracing::error!(
"Failed to run proc-macro server from path {path}, error: {err:?}",
);
anyhow::format_err!(
"Failed to run proc-macro server from path {path}, error: {err:?}",
)
})
})
.collect::<Vec<_>>(),
)
tracing::info!("Using proc-macro server at {path}");
ProcMacroServer::spawn(path.clone()).map_err(|err| {
tracing::error!(
"Failed to run proc-macro server from path {path}, error: {err:?}",
);
anyhow::format_err!(
"Failed to run proc-macro server from path {path}, error: {err:?}",
)
})
}))
};
}

View file

@ -8,7 +8,7 @@
//! specific JSON shapes here -- there's little value in such tests, as we can't
//! be sure without a real client anyway.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#![warn(rust_2018_idioms, unused_lifetimes)]
#[cfg(not(feature = "in-rust-tree"))]
mod sourcegen;

View file

@ -250,6 +250,7 @@ fn check_dbg(path: &Path, text: &str) {
// We have .dbg postfix
"ide-completion/src/completions/postfix.rs",
"ide-completion/src/completions/keyword.rs",
"ide-completion/src/tests/expression.rs",
"ide-completion/src/tests/proc_macros.rs",
// The documentation in string literals may contain anything for its own purposes
"ide-completion/src/lib.rs",