mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Merge branch 'master' into add-disable-diagnostics
This commit is contained in:
commit
b50bb800a5
134 changed files with 1907 additions and 1282 deletions
|
@ -72,7 +72,7 @@ impl AnalysisStatsCmd {
|
|||
shuffle(&mut rng, &mut krates);
|
||||
}
|
||||
for krate in krates {
|
||||
let module = krate.root_module(db).expect("crate without root module");
|
||||
let module = krate.root_module(db);
|
||||
let file_id = module.definition_source(db).file_id;
|
||||
let file_id = file_id.original_file(db);
|
||||
let source_root = db.file_source_root(file_id);
|
||||
|
|
|
@ -28,7 +28,7 @@ pub fn diagnostics(
|
|||
let mut work = Vec::new();
|
||||
let krates = Crate::all(db);
|
||||
for krate in krates {
|
||||
let module = krate.root_module(db).expect("crate without root module");
|
||||
let module = krate.root_module(db);
|
||||
let file_id = module.definition_source(db).file_id;
|
||||
let file_id = file_id.original_file(db);
|
||||
let source_root = db.file_source_root(file_id);
|
||||
|
|
|
@ -73,6 +73,7 @@ pub(crate) struct GlobalState {
|
|||
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
|
||||
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||
pub(crate) shutdown_requested: bool,
|
||||
pub(crate) status: Status,
|
||||
pub(crate) source_root_config: SourceRootConfig,
|
||||
pub(crate) proc_macro_client: ProcMacroClient,
|
||||
|
@ -124,6 +125,7 @@ impl GlobalState {
|
|||
mem_docs: FxHashMap::default(),
|
||||
semantic_tokens_cache: Arc::new(Default::default()),
|
||||
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
|
||||
shutdown_requested: false,
|
||||
status: Status::default(),
|
||||
source_root_config: SourceRootConfig::default(),
|
||||
proc_macro_client: ProcMacroClient::dummy(),
|
||||
|
|
|
@ -773,12 +773,11 @@ fn handle_fixes(
|
|||
|
||||
let diagnostics = snap.analysis.diagnostics(file_id, snap.config.experimental_diagnostics)?;
|
||||
|
||||
let fixes_from_diagnostics = diagnostics
|
||||
for fix in diagnostics
|
||||
.into_iter()
|
||||
.filter_map(|d| Some((d.range, d.fix?)))
|
||||
.filter(|(diag_range, _fix)| diag_range.intersect(range).is_some())
|
||||
.map(|(_range, fix)| fix);
|
||||
for fix in fixes_from_diagnostics {
|
||||
.filter_map(|d| d.fix)
|
||||
.filter(|fix| fix.fix_trigger_range.intersect(range).is_some())
|
||||
{
|
||||
let title = fix.label;
|
||||
let edit = to_proto::snippet_workspace_edit(&snap, fix.source_change)?;
|
||||
let action = lsp_ext::CodeAction {
|
||||
|
@ -864,7 +863,7 @@ pub(crate) fn handle_resolve_code_action(
|
|||
let (id_string, index) = split_once(¶ms.id, ':').unwrap();
|
||||
let index = index.parse::<usize>().unwrap();
|
||||
let assist = &assists[index];
|
||||
assert!(assist.assist.id.0 == id_string);
|
||||
assert!(assist.assist.id().0 == id_string);
|
||||
Ok(to_proto::resolved_code_action(&snap, assist.clone())?.edit)
|
||||
}
|
||||
|
||||
|
@ -892,7 +891,7 @@ pub(crate) fn handle_code_lens(
|
|||
}
|
||||
|
||||
let action = runnable.action();
|
||||
let range = to_proto::range(&line_index, runnable.nav.focus_or_full_range());
|
||||
let range = to_proto::range(&line_index, runnable.nav.full_range);
|
||||
let r = to_proto::runnable(&snap, file_id, runnable)?;
|
||||
if snap.config.lens.run {
|
||||
let lens = CodeLens {
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
|
|||
SetThreadPriority(thread, thread_priority_above_normal);
|
||||
}
|
||||
|
||||
GlobalState::new(connection.sender.clone(), config).run(connection.receiver)
|
||||
GlobalState::new(connection.sender, config).run(connection.receiver)
|
||||
}
|
||||
|
||||
enum Event {
|
||||
|
@ -337,11 +337,34 @@ impl GlobalState {
|
|||
fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
|
||||
self.register_request(&req, request_received);
|
||||
|
||||
if self.shutdown_requested {
|
||||
self.respond(Response::new_err(
|
||||
req.id,
|
||||
lsp_server::ErrorCode::InvalidRequest as i32,
|
||||
"Shutdown already requested.".to_owned(),
|
||||
));
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.status == Status::Loading && req.method != "shutdown" {
|
||||
self.respond(lsp_server::Response::new_err(
|
||||
req.id,
|
||||
// FIXME: i32 should impl From<ErrorCode> (from() guarantees lossless conversion)
|
||||
lsp_server::ErrorCode::ContentModified as i32,
|
||||
"Rust Analyzer is still loading...".to_owned(),
|
||||
));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
RequestDispatcher { req: Some(req), global_state: self }
|
||||
.on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
|
||||
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
|
||||
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
|
||||
.on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?
|
||||
.on_sync::<lsp_types::request::Shutdown>(|s, ()| {
|
||||
s.shutdown_requested = true;
|
||||
Ok(())
|
||||
})?
|
||||
.on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
|
||||
handlers::handle_selection_range(s.snapshot(), p)
|
||||
})?
|
||||
|
|
|
@ -704,10 +704,10 @@ pub(crate) fn unresolved_code_action(
|
|||
index: usize,
|
||||
) -> Result<lsp_ext::CodeAction> {
|
||||
let res = lsp_ext::CodeAction {
|
||||
title: assist.label,
|
||||
id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
|
||||
group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
|
||||
kind: Some(code_action_kind(assist.id.1)),
|
||||
title: assist.label(),
|
||||
id: Some(format!("{}:{}", assist.id().0.to_owned(), index.to_string())),
|
||||
group: assist.group().filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
|
||||
kind: Some(code_action_kind(assist.id().1)),
|
||||
edit: None,
|
||||
is_preferred: None,
|
||||
};
|
||||
|
@ -755,7 +755,8 @@ pub(crate) fn runnable(
|
|||
}
|
||||
|
||||
pub(crate) fn markup_content(markup: Markup) -> lsp_types::MarkupContent {
|
||||
lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value: markup.into() }
|
||||
let value = crate::markdown::format_docs(markup.as_str());
|
||||
lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue