]> git.lizzy.rs Git - rust.git/blobdiff - crates/rust-analyzer/src/main_loop/handlers.rs
Merge branch 'master' into compute-lazy-assits
[rust.git] / crates / rust-analyzer / src / main_loop / handlers.rs
index fab82ff7ead03dc6d1f38405912730c0d02eb471..a3361d6dc5e9d3f7f655830a4fa9751a67886058 100644 (file)
     config::RustfmtConfig,
     diagnostics::DiagnosticTask,
     from_json, from_proto,
+    global_state::GlobalStateSnapshot,
     lsp_ext::{self, InlayHint, InlayHintsParams},
-    to_proto,
-    world::WorldSnapshot,
-    LspError, Result,
+    to_proto, LspError, Result,
 };
 
-pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
+pub fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> {
     let _p = profile("handle_analyzer_status");
-    let mut buf = world.status();
+    let mut buf = snap.status();
     format_to!(buf, "\n\nrequests:\n");
-    let requests = world.latest_requests.read();
+    let requests = snap.latest_requests.read();
     for (is_last, r) in requests.iter() {
         let mark = if is_last { "*" } else { " " };
         format_to!(buf, "{}{:4} {:<36}{}ms\n", mark, r.id, r.method, r.duration.as_millis());
@@ -51,37 +50,37 @@ pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
 }
 
 pub fn handle_syntax_tree(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::SyntaxTreeParams,
 ) -> Result<String> {
     let _p = profile("handle_syntax_tree");
-    let id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(id)?;
+    let id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(id)?;
     let text_range = params.range.map(|r| from_proto::text_range(&line_index, r));
-    let res = world.analysis().syntax_tree(id, text_range)?;
+    let res = snap.analysis().syntax_tree(id, text_range)?;
     Ok(res)
 }
 
 pub fn handle_expand_macro(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::ExpandMacroParams,
 ) -> Result<Option<lsp_ext::ExpandedMacro>> {
     let _p = profile("handle_expand_macro");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let offset = from_proto::offset(&line_index, params.position);
 
-    let res = world.analysis().expand_macro(FilePosition { file_id, offset })?;
+    let res = snap.analysis().expand_macro(FilePosition { file_id, offset })?;
     Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
 }
 
 pub fn handle_selection_range(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::SelectionRangeParams,
 ) -> Result<Option<Vec<lsp_types::SelectionRange>>> {
     let _p = profile("handle_selection_range");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let res: Result<Vec<lsp_types::SelectionRange>> = params
         .positions
         .into_iter()
@@ -93,7 +92,7 @@ pub fn handle_selection_range(
                 loop {
                     ranges.push(range);
                     let frange = FileRange { file_id, range };
-                    let next = world.analysis().extend_selection(frange)?;
+                    let next = snap.analysis().extend_selection(frange)?;
                     if next == range {
                         break;
                     } else {
@@ -119,18 +118,18 @@ pub fn handle_selection_range(
 }
 
 pub fn handle_matching_brace(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::MatchingBraceParams,
 ) -> Result<Vec<Position>> {
     let _p = profile("handle_matching_brace");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let res = params
         .positions
         .into_iter()
         .map(|position| {
             let offset = from_proto::offset(&line_index, position);
-            let offset = match world.analysis().matching_brace(FilePosition { file_id, offset }) {
+            let offset = match snap.analysis().matching_brace(FilePosition { file_id, offset }) {
                 Ok(Some(matching_brace_offset)) => matching_brace_offset,
                 Err(_) | Ok(None) => offset,
             };
@@ -141,17 +140,17 @@ pub fn handle_matching_brace(
 }
 
 pub fn handle_join_lines(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::JoinLinesParams,
 ) -> Result<Vec<lsp_types::TextEdit>> {
     let _p = profile("handle_join_lines");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
-    let line_endings = world.file_line_endings(file_id);
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
+    let line_endings = snap.file_line_endings(file_id);
     let mut res = TextEdit::default();
     for range in params.ranges {
         let range = from_proto::text_range(&line_index, range);
-        let edit = world.analysis().join_lines(FileRange { file_id, range })?;
+        let edit = snap.analysis().join_lines(FileRange { file_id, range })?;
         match res.union(edit) {
             Ok(()) => (),
             Err(_edit) => {
@@ -164,37 +163,37 @@ pub fn handle_join_lines(
 }
 
 pub fn handle_on_enter(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::TextDocumentPositionParams,
 ) -> Result<Option<Vec<lsp_ext::SnippetTextEdit>>> {
     let _p = profile("handle_on_enter");
-    let position = from_proto::file_position(&world, params)?;
-    let edit = match world.analysis().on_enter(position)? {
+    let position = from_proto::file_position(&snap, params)?;
+    let edit = match snap.analysis().on_enter(position)? {
         None => return Ok(None),
         Some(it) => it,
     };
-    let line_index = world.analysis().file_line_index(position.file_id)?;
-    let line_endings = world.file_line_endings(position.file_id);
+    let line_index = snap.analysis().file_line_index(position.file_id)?;
+    let line_endings = snap.file_line_endings(position.file_id);
     let edit = to_proto::snippet_text_edit_vec(&line_index, line_endings, true, edit);
     Ok(Some(edit))
 }
 
 // Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`.
 pub fn handle_on_type_formatting(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::DocumentOnTypeFormattingParams,
 ) -> Result<Option<Vec<lsp_types::TextEdit>>> {
     let _p = profile("handle_on_type_formatting");
-    let mut position = from_proto::file_position(&world, params.text_document_position)?;
-    let line_index = world.analysis().file_line_index(position.file_id)?;
-    let line_endings = world.file_line_endings(position.file_id);
+    let mut position = from_proto::file_position(&snap, params.text_document_position)?;
+    let line_index = snap.analysis().file_line_index(position.file_id)?;
+    let line_endings = snap.file_line_endings(position.file_id);
 
     // in `ra_ide`, the `on_type` invariant is that
     // `text.char_at(position) == typed_char`.
     position.offset -= TextSize::of('.');
     let char_typed = params.ch.chars().next().unwrap_or('\0');
     assert!({
-        let text = world.analysis().file_text(position.file_id)?;
+        let text = snap.analysis().file_text(position.file_id)?;
         text[usize::from(position.offset)..].starts_with(char_typed)
     });
 
@@ -206,7 +205,7 @@ pub fn handle_on_type_formatting(
         return Ok(None);
     }
 
-    let edit = world.analysis().on_char_typed(position, char_typed)?;
+    let edit = snap.analysis().on_char_typed(position, char_typed)?;
     let mut edit = match edit {
         Some(it) => it,
         None => return Ok(None),
@@ -220,16 +219,16 @@ pub fn handle_on_type_formatting(
 }
 
 pub fn handle_document_symbol(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::DocumentSymbolParams,
 ) -> Result<Option<lsp_types::DocumentSymbolResponse>> {
     let _p = profile("handle_document_symbol");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
 
     let mut parents: Vec<(DocumentSymbol, Option<usize>)> = Vec::new();
 
-    for symbol in world.analysis().file_structure(file_id)? {
+    for symbol in snap.analysis().file_structure(file_id)? {
         let doc_symbol = DocumentSymbol {
             name: symbol.label,
             detail: symbol.detail,
@@ -255,10 +254,10 @@ pub fn handle_document_symbol(
         }
     }
 
-    let res = if world.config.client_caps.hierarchical_symbols {
+    let res = if snap.config.client_caps.hierarchical_symbols {
         document_symbols.into()
     } else {
-        let url = to_proto::url(&world, file_id)?;
+        let url = to_proto::url(&snap, file_id)?;
         let mut symbol_information = Vec::<SymbolInformation>::new();
         for symbol in document_symbols {
             flatten_document_symbol(&symbol, None, &url, &mut symbol_information);
@@ -288,7 +287,7 @@ fn flatten_document_symbol(
 }
 
 pub fn handle_workspace_symbol(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::WorkspaceSymbolParams,
 ) -> Result<Option<Vec<SymbolInformation>>> {
     let _p = profile("handle_workspace_symbol");
@@ -306,22 +305,22 @@ pub fn handle_workspace_symbol(
         q.limit(128);
         q
     };
-    let mut res = exec_query(&world, query)?;
+    let mut res = exec_query(&snap, query)?;
     if res.is_empty() && !all_symbols {
         let mut query = Query::new(params.query);
         query.limit(128);
-        res = exec_query(&world, query)?;
+        res = exec_query(&snap, query)?;
     }
 
     return Ok(Some(res));
 
-    fn exec_query(world: &WorldSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
+    fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
         let mut res = Vec::new();
-        for nav in world.analysis().symbol_search(query)? {
+        for nav in snap.analysis().symbol_search(query)? {
             let info = SymbolInformation {
                 name: nav.name().to_string(),
                 kind: to_proto::symbol_kind(nav.kind()),
-                location: to_proto::location(world, nav.file_range())?,
+                location: to_proto::location(snap, nav.file_range())?,
                 container_name: nav.container_name().map(|v| v.to_string()),
                 deprecated: None,
             };
@@ -332,73 +331,73 @@ fn exec_query(world: &WorldSnapshot, query: Query) -> Result<Vec<SymbolInformati
 }
 
 pub fn handle_goto_definition(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::GotoDefinitionParams,
 ) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
     let _p = profile("handle_goto_definition");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
-    let nav_info = match world.analysis().goto_definition(position)? {
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
+    let nav_info = match snap.analysis().goto_definition(position)? {
         None => return Ok(None),
         Some(it) => it,
     };
     let src = FileRange { file_id: position.file_id, range: nav_info.range };
-    let res = to_proto::goto_definition_response(&world, Some(src), nav_info.info)?;
+    let res = to_proto::goto_definition_response(&snap, Some(src), nav_info.info)?;
     Ok(Some(res))
 }
 
 pub fn handle_goto_implementation(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::request::GotoImplementationParams,
 ) -> Result<Option<lsp_types::request::GotoImplementationResponse>> {
     let _p = profile("handle_goto_implementation");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
-    let nav_info = match world.analysis().goto_implementation(position)? {
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
+    let nav_info = match snap.analysis().goto_implementation(position)? {
         None => return Ok(None),
         Some(it) => it,
     };
     let src = FileRange { file_id: position.file_id, range: nav_info.range };
-    let res = to_proto::goto_definition_response(&world, Some(src), nav_info.info)?;
+    let res = to_proto::goto_definition_response(&snap, Some(src), nav_info.info)?;
     Ok(Some(res))
 }
 
 pub fn handle_goto_type_definition(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::request::GotoTypeDefinitionParams,
 ) -> Result<Option<lsp_types::request::GotoTypeDefinitionResponse>> {
     let _p = profile("handle_goto_type_definition");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
-    let nav_info = match world.analysis().goto_type_definition(position)? {
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
+    let nav_info = match snap.analysis().goto_type_definition(position)? {
         None => return Ok(None),
         Some(it) => it,
     };
     let src = FileRange { file_id: position.file_id, range: nav_info.range };
-    let res = to_proto::goto_definition_response(&world, Some(src), nav_info.info)?;
+    let res = to_proto::goto_definition_response(&snap, Some(src), nav_info.info)?;
     Ok(Some(res))
 }
 
 pub fn handle_parent_module(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::TextDocumentPositionParams,
 ) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
     let _p = profile("handle_parent_module");
-    let position = from_proto::file_position(&world, params)?;
-    let navs = world.analysis().parent_module(position)?;
-    let res = to_proto::goto_definition_response(&world, None, navs)?;
+    let position = from_proto::file_position(&snap, params)?;
+    let navs = snap.analysis().parent_module(position)?;
+    let res = to_proto::goto_definition_response(&snap, None, navs)?;
     Ok(Some(res))
 }
 
 pub fn handle_runnables(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::RunnablesParams,
 ) -> Result<Vec<lsp_ext::Runnable>> {
     let _p = profile("handle_runnables");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let offset = params.position.map(|it| from_proto::offset(&line_index, it));
     let mut res = Vec::new();
-    let workspace_root = world.workspace_root_for(file_id);
-    let cargo_spec = CargoTargetSpec::for_file(&world, file_id)?;
-    for runnable in world.analysis().runnables(file_id)? {
+    let workspace_root = snap.workspace_root_for(file_id);
+    let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
+    for runnable in snap.analysis().runnables(file_id)? {
         if let Some(offset) = offset {
             if !runnable.nav.full_range().contains_inclusive(offset) {
                 continue;
@@ -413,7 +412,7 @@ pub fn handle_runnables(
                 }
             }
         }
-        res.push(to_proto::runnable(&world, file_id, runnable)?);
+        res.push(to_proto::runnable(&snap, file_id, runnable)?);
     }
 
     // Add `cargo check` and `cargo test` for the whole package
@@ -453,16 +452,16 @@ pub fn handle_runnables(
 }
 
 pub fn handle_completion(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::CompletionParams,
 ) -> Result<Option<lsp_types::CompletionResponse>> {
     let _p = profile("handle_completion");
-    let position = from_proto::file_position(&world, params.text_document_position)?;
+    let position = from_proto::file_position(&snap, params.text_document_position)?;
     let completion_triggered_after_single_colon = {
         let mut res = false;
         if let Some(ctx) = params.context {
             if ctx.trigger_character.unwrap_or_default() == ":" {
-                let source_file = world.analysis().parse(position.file_id)?;
+                let source_file = snap.analysis().parse(position.file_id)?;
                 let syntax = source_file.syntax();
                 let text = syntax.text();
                 if let Some(next_char) = text.char_at(position.offset) {
@@ -480,12 +479,12 @@ pub fn handle_completion(
         return Ok(None);
     }
 
-    let items = match world.analysis().completions(&world.config.completion, position)? {
+    let items = match snap.analysis().completions(&snap.config.completion, position)? {
         None => return Ok(None),
         Some(items) => items,
     };
-    let line_index = world.analysis().file_line_index(position.file_id)?;
-    let line_endings = world.file_line_endings(position.file_id);
+    let line_index = snap.analysis().file_line_index(position.file_id)?;
+    let line_endings = snap.file_line_endings(position.file_id);
     let items: Vec<CompletionItem> = items
         .into_iter()
         .map(|item| to_proto::completion_item(&line_index, line_endings, item))
@@ -495,15 +494,15 @@ pub fn handle_completion(
 }
 
 pub fn handle_folding_range(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: FoldingRangeParams,
 ) -> Result<Option<Vec<FoldingRange>>> {
     let _p = profile("handle_folding_range");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let folds = world.analysis().folding_ranges(file_id)?;
-    let text = world.analysis().file_text(file_id)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
-    let line_folding_only = world.config.client_caps.line_folding_only;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let folds = snap.analysis().folding_ranges(file_id)?;
+    let text = snap.analysis().file_text(file_id)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
+    let line_folding_only = snap.config.client_caps.line_folding_only;
     let res = folds
         .into_iter()
         .map(|it| to_proto::folding_range(&*text, &line_index, line_folding_only, it))
@@ -512,16 +511,16 @@ pub fn handle_folding_range(
 }
 
 pub fn handle_signature_help(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::SignatureHelpParams,
 ) -> Result<Option<lsp_types::SignatureHelp>> {
     let _p = profile("handle_signature_help");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
-    let call_info = match world.analysis().call_info(position)? {
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
+    let call_info = match snap.analysis().call_info(position)? {
         None => return Ok(None),
         Some(it) => it,
     };
-    let concise = !world.config.call_info_full;
+    let concise = !snap.config.call_info_full;
     let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
     if concise && call_info.signature.has_self_param {
         active_parameter = active_parameter.map(|it| it.saturating_sub(1));
@@ -535,14 +534,17 @@ pub fn handle_signature_help(
     }))
 }
 
-pub fn handle_hover(world: WorldSnapshot, params: lsp_types::HoverParams) -> Result<Option<Hover>> {
+pub fn handle_hover(
+    snap: GlobalStateSnapshot,
+    params: lsp_types::HoverParams,
+) -> Result<Option<Hover>> {
     let _p = profile("handle_hover");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
-    let info = match world.analysis().hover(position)? {
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
+    let info = match snap.analysis().hover(position)? {
         None => return Ok(None),
         Some(info) => info,
     };
-    let line_index = world.analysis.file_line_index(position.file_id)?;
+    let line_index = snap.analysis.file_line_index(position.file_id)?;
     let range = to_proto::range(&line_index, info.range);
     let res = Hover {
         contents: HoverContents::Markup(MarkupContent {
@@ -555,26 +557,29 @@ pub fn handle_hover(world: WorldSnapshot, params: lsp_types::HoverParams) -> Res
 }
 
 pub fn handle_prepare_rename(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::TextDocumentPositionParams,
 ) -> Result<Option<PrepareRenameResponse>> {
     let _p = profile("handle_prepare_rename");
-    let position = from_proto::file_position(&world, params)?;
+    let position = from_proto::file_position(&snap, params)?;
 
-    let optional_change = world.analysis().rename(position, "dummy")?;
+    let optional_change = snap.analysis().rename(position, "dummy")?;
     let range = match optional_change {
         None => return Ok(None),
         Some(it) => it.range,
     };
 
-    let line_index = world.analysis().file_line_index(position.file_id)?;
+    let line_index = snap.analysis().file_line_index(position.file_id)?;
     let range = to_proto::range(&line_index, range);
     Ok(Some(PrepareRenameResponse::Range(range)))
 }
 
-pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Option<WorkspaceEdit>> {
+pub fn handle_rename(
+    snap: GlobalStateSnapshot,
+    params: RenameParams,
+) -> Result<Option<WorkspaceEdit>> {
     let _p = profile("handle_rename");
-    let position = from_proto::file_position(&world, params.text_document_position)?;
+    let position = from_proto::file_position(&snap, params.text_document_position)?;
 
     if params.new_name.is_empty() {
         return Err(LspError::new(
@@ -584,36 +589,36 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
         .into());
     }
 
-    let optional_change = world.analysis().rename(position, &*params.new_name)?;
+    let optional_change = snap.analysis().rename(position, &*params.new_name)?;
     let source_change = match optional_change {
         None => return Ok(None),
         Some(it) => it.info,
     };
-    let workspace_edit = to_proto::workspace_edit(&world, source_change)?;
+    let workspace_edit = to_proto::workspace_edit(&snap, source_change)?;
     Ok(Some(workspace_edit))
 }
 
 pub fn handle_references(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::ReferenceParams,
 ) -> Result<Option<Vec<Location>>> {
     let _p = profile("handle_references");
-    let position = from_proto::file_position(&world, params.text_document_position)?;
+    let position = from_proto::file_position(&snap, params.text_document_position)?;
 
-    let refs = match world.analysis().find_all_refs(position, None)? {
+    let refs = match snap.analysis().find_all_refs(position, None)? {
         None => return Ok(None),
         Some(refs) => refs,
     };
 
     let locations = if params.context.include_declaration {
         refs.into_iter()
-            .filter_map(|reference| to_proto::location(&world, reference.file_range).ok())
+            .filter_map(|reference| to_proto::location(&snap, reference.file_range).ok())
             .collect()
     } else {
         // Only iterate over the references if include_declaration was false
         refs.references()
             .iter()
-            .filter_map(|reference| to_proto::location(&world, reference.file_range).ok())
+            .filter_map(|reference| to_proto::location(&snap, reference.file_range).ok())
             .collect()
     };
 
@@ -621,24 +626,24 @@ pub fn handle_references(
 }
 
 pub fn handle_formatting(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: DocumentFormattingParams,
 ) -> Result<Option<Vec<lsp_types::TextEdit>>> {
     let _p = profile("handle_formatting");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let file = world.analysis().file_text(file_id)?;
-    let crate_ids = world.analysis().crate_for(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let file = snap.analysis().file_text(file_id)?;
+    let crate_ids = snap.analysis().crate_for(file_id)?;
 
-    let file_line_index = world.analysis().file_line_index(file_id)?;
+    let file_line_index = snap.analysis().file_line_index(file_id)?;
     let end_position = to_proto::position(&file_line_index, TextSize::of(file.as_str()));
 
-    let mut rustfmt = match &world.config.rustfmt {
+    let mut rustfmt = match &snap.config.rustfmt {
         RustfmtConfig::Rustfmt { extra_args } => {
             let mut cmd = process::Command::new("rustfmt");
             cmd.args(extra_args);
             if let Some(&crate_id) = crate_ids.first() {
                 // Assume all crates are in the same edition
-                let edition = world.analysis().crate_edition(crate_id)?;
+                let edition = snap.analysis().crate_edition(crate_id)?;
                 cmd.arg("--edition");
                 cmd.arg(edition.to_string());
             }
@@ -697,15 +702,14 @@ pub fn handle_formatting(
 }
 
 fn handle_fixes(
-    world: &WorldSnapshot,
+    snap: &GlobalStateSnapshot,
     params: &lsp_types::CodeActionParams,
     res: &mut Vec<lsp_ext::CodeAction>,
 ) -> Result<()> {
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let range = from_proto::text_range(&line_index, params.range);
-
-    let diagnostics = world.analysis().diagnostics(file_id)?;
+    let diagnostics = snap.analysis().diagnostics(file_id)?;
 
     let fixes_from_diagnostics = diagnostics
         .into_iter()
@@ -714,18 +718,19 @@ fn handle_fixes(
         .map(|(_range, fix)| fix);
     for fix in fixes_from_diagnostics {
         let title = fix.label;
-        let edit = to_proto::snippet_workspace_edit(&world, fix.source_change)?;
+        let edit = to_proto::snippet_workspace_edit(&snap, fix.source_change)?;
         let action = lsp_ext::CodeAction {
             title,
             id: None,
             group: None,
-            kind: None,
+            kind: Some(lsp_types::code_action_kind::QUICKFIX.into()),
             edit: Some(edit),
             command: None,
         };
         res.push(action);
     }
-    for fix in world.check_fixes.get(&file_id).into_iter().flatten() {
+
+    for fix in snap.check_fixes.get(&file_id).into_iter().flatten() {
         let fix_range = from_proto::text_range(&line_index, fix.range);
         if fix_range.intersect(range).is_none() {
             continue;
@@ -736,37 +741,34 @@ fn handle_fixes(
 }
 
 pub fn handle_code_action(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::CodeActionParams,
 ) -> Result<Option<Vec<lsp_ext::CodeAction>>> {
     let _p = profile("handle_code_action");
     // We intentionally don't support command-based actions, as those either
     // requires custom client-code anyway, or requires server-initiated edits.
     // Server initiated edits break causality, so we avoid those as well.
-    if !world.config.client_caps.code_action_literals {
+    if !snap.config.client_caps.code_action_literals {
         return Ok(None);
     }
 
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let range = from_proto::text_range(&line_index, params.range);
     let frange = FileRange { file_id, range };
     let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
 
-    handle_fixes(&world, &params, &mut res)?;
+    handle_fixes(&snap, &params, &mut res)?;
 
-    if world.config.client_caps.resolve_code_action {
-        for (index, assist) in world
-            .analysis()
-            .unresolved_assists(&world.config.assist, frange)?
-            .into_iter()
-            .enumerate()
+    if snap.config.client_caps.resolve_code_action {
+        for (index, assist) in
+            snap.analysis().unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate()
         {
-            res.push(to_proto::unresolved_code_action(&world, assist, index)?);
+            res.push(to_proto::unresolved_code_action(&snap, assist, index)?);
         }
     } else {
-        for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
-            res.push(to_proto::resolved_code_action(&world, assist)?);
+        for assist in snap.analysis().resolved_assists(&snap.config.assist, frange)?.into_iter() {
+            res.push(to_proto::resolved_code_action(&snap, assist)?);
         }
     }
 
@@ -774,43 +776,43 @@ pub fn handle_code_action(
 }
 
 pub fn handle_resolve_code_action(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::ResolveCodeActionParams,
 ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> {
     let _p = profile("handle_resolve_code_action");
-    let file_id = from_proto::file_id(&world, &params.code_action_params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.code_action_params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
     let range = from_proto::text_range(&line_index, params.code_action_params.range);
     let frange = FileRange { file_id, range };
 
-    let assists = world.analysis().resolved_assists(&world.config.assist, frange)?;
+    let assists = snap.analysis().resolved_assists(&snap.config.assist, frange)?;
     let id_components = params.id.split(":").collect::<Vec<&str>>();
     let index = id_components.last().unwrap().parse::<usize>().unwrap();
     let id_string = id_components.first().unwrap();
     let assist = &assists[index];
     assert!(assist.assist.id.0 == *id_string);
-    Ok(to_proto::resolved_code_action(&world, assist.clone())?.edit)
+    Ok(to_proto::resolved_code_action(&snap, assist.clone())?.edit)
 }
 
 pub fn handle_code_lens(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::CodeLensParams,
 ) -> Result<Option<Vec<CodeLens>>> {
     let _p = profile("handle_code_lens");
     let mut lenses: Vec<CodeLens> = Default::default();
 
-    if world.config.lens.none() {
+    if snap.config.lens.none() {
         // early return before any db query!
         return Ok(Some(lenses));
     }
 
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
-    let cargo_spec = CargoTargetSpec::for_file(&world, file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
+    let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
 
-    if world.config.lens.runnable() {
+    if snap.config.lens.runnable() {
         // Gather runnables
-        for runnable in world.analysis().runnables(file_id)? {
+        for runnable in snap.analysis().runnables(file_id)? {
             let (run_title, debugee) = match &runnable.kind {
                 RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => {
                     ("▶\u{fe0e} Run Test", true)
@@ -836,8 +838,8 @@ pub fn handle_code_lens(
             };
 
             let range = to_proto::range(&line_index, runnable.nav.range());
-            let r = to_proto::runnable(&world, file_id, runnable)?;
-            if world.config.lens.run {
+            let r = to_proto::runnable(&snap, file_id, runnable)?;
+            if snap.config.lens.run {
                 let lens = CodeLens {
                     range,
                     command: Some(Command {
@@ -850,7 +852,7 @@ pub fn handle_code_lens(
                 lenses.push(lens);
             }
 
-            if debugee && world.config.lens.debug {
+            if debugee && snap.config.lens.debug {
                 let debug_lens = CodeLens {
                     range,
                     command: Some(Command {
@@ -865,11 +867,10 @@ pub fn handle_code_lens(
         }
     }
 
-    if world.config.lens.impementations {
+    if snap.config.lens.impementations {
         // Handle impls
         lenses.extend(
-            world
-                .analysis()
+            snap.analysis()
                 .file_structure(file_id)?
                 .into_iter()
                 .filter(|it| match it.kind {
@@ -904,14 +905,17 @@ enum CodeLensResolveData {
     Impls(lsp_types::request::GotoImplementationParams),
 }
 
-pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> {
+pub fn handle_code_lens_resolve(
+    snap: GlobalStateSnapshot,
+    code_lens: CodeLens,
+) -> Result<CodeLens> {
     let _p = profile("handle_code_lens_resolve");
     let data = code_lens.data.unwrap();
     let resolve = from_json::<Option<CodeLensResolveData>>("CodeLensResolveData", data)?;
     match resolve {
         Some(CodeLensResolveData::Impls(lens_params)) => {
             let locations: Vec<Location> =
-                match handle_goto_implementation(world, lens_params.clone())? {
+                match handle_goto_implementation(snap, lens_params.clone())? {
                     Some(lsp_types::GotoDefinitionResponse::Scalar(loc)) => vec![loc],
                     Some(lsp_types::GotoDefinitionResponse::Array(locs)) => locs,
                     Some(lsp_types::GotoDefinitionResponse::Link(links)) => links
@@ -950,14 +954,14 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re
 }
 
 pub fn handle_document_highlight(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_types::DocumentHighlightParams,
 ) -> Result<Option<Vec<DocumentHighlight>>> {
     let _p = profile("handle_document_highlight");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
-    let line_index = world.analysis().file_line_index(position.file_id)?;
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
+    let line_index = snap.analysis().file_line_index(position.file_id)?;
 
-    let refs = match world
+    let refs = match snap
         .analysis()
         .find_all_refs(position, Some(SearchScope::single_file(position.file_id)))?
     {
@@ -977,19 +981,19 @@ pub fn handle_document_highlight(
 }
 
 pub fn handle_ssr(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: lsp_ext::SsrParams,
 ) -> Result<lsp_types::WorkspaceEdit> {
     let _p = profile("handle_ssr");
     let source_change =
-        world.analysis().structural_search_replace(&params.query, params.parse_only)??;
-    to_proto::workspace_edit(&world, source_change)
+        snap.analysis().structural_search_replace(&params.query, params.parse_only)??;
+    to_proto::workspace_edit(&snap, source_change)
 }
 
-pub fn publish_diagnostics(world: &WorldSnapshot, file_id: FileId) -> Result<DiagnosticTask> {
+pub fn publish_diagnostics(snap: &GlobalStateSnapshot, file_id: FileId) -> Result<DiagnosticTask> {
     let _p = profile("publish_diagnostics");
-    let line_index = world.analysis().file_line_index(file_id)?;
-    let diagnostics: Vec<Diagnostic> = world
+    let line_index = snap.analysis().file_line_index(file_id)?;
+    let diagnostics: Vec<Diagnostic> = snap
         .analysis()
         .diagnostics(file_id)?
         .into_iter()
@@ -1007,28 +1011,28 @@ pub fn publish_diagnostics(world: &WorldSnapshot, file_id: FileId) -> Result<Dia
 }
 
 pub fn handle_inlay_hints(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: InlayHintsParams,
 ) -> Result<Vec<InlayHint>> {
     let _p = profile("handle_inlay_hints");
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let analysis = world.analysis();
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let analysis = snap.analysis();
     let line_index = analysis.file_line_index(file_id)?;
     Ok(analysis
-        .inlay_hints(file_id, &world.config.inlay_hints)?
+        .inlay_hints(file_id, &snap.config.inlay_hints)?
         .into_iter()
         .map(|it| to_proto::inlay_int(&line_index, it))
         .collect())
 }
 
 pub fn handle_call_hierarchy_prepare(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: CallHierarchyPrepareParams,
 ) -> Result<Option<Vec<CallHierarchyItem>>> {
     let _p = profile("handle_call_hierarchy_prepare");
-    let position = from_proto::file_position(&world, params.text_document_position_params)?;
+    let position = from_proto::file_position(&snap, params.text_document_position_params)?;
 
-    let nav_info = match world.analysis().call_hierarchy(position)? {
+    let nav_info = match snap.analysis().call_hierarchy(position)? {
         None => return Ok(None),
         Some(it) => it,
     };
@@ -1037,24 +1041,24 @@ pub fn handle_call_hierarchy_prepare(
     let res = navs
         .into_iter()
         .filter(|it| it.kind() == SyntaxKind::FN_DEF)
-        .map(|it| to_proto::call_hierarchy_item(&world, it))
+        .map(|it| to_proto::call_hierarchy_item(&snap, it))
         .collect::<Result<Vec<_>>>()?;
 
     Ok(Some(res))
 }
 
 pub fn handle_call_hierarchy_incoming(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: CallHierarchyIncomingCallsParams,
 ) -> Result<Option<Vec<CallHierarchyIncomingCall>>> {
     let _p = profile("handle_call_hierarchy_incoming");
     let item = params.item;
 
     let doc = TextDocumentIdentifier::new(item.uri);
-    let frange = from_proto::file_range(&world, doc, item.range)?;
+    let frange = from_proto::file_range(&snap, doc, item.range)?;
     let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
 
-    let call_items = match world.analysis().incoming_calls(fpos)? {
+    let call_items = match snap.analysis().incoming_calls(fpos)? {
         None => return Ok(None),
         Some(it) => it,
     };
@@ -1063,8 +1067,8 @@ pub fn handle_call_hierarchy_incoming(
 
     for call_item in call_items.into_iter() {
         let file_id = call_item.target.file_id();
-        let line_index = world.analysis().file_line_index(file_id)?;
-        let item = to_proto::call_hierarchy_item(&world, call_item.target)?;
+        let line_index = snap.analysis().file_line_index(file_id)?;
+        let item = to_proto::call_hierarchy_item(&snap, call_item.target)?;
         res.push(CallHierarchyIncomingCall {
             from: item,
             from_ranges: call_item
@@ -1079,17 +1083,17 @@ pub fn handle_call_hierarchy_incoming(
 }
 
 pub fn handle_call_hierarchy_outgoing(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: CallHierarchyOutgoingCallsParams,
 ) -> Result<Option<Vec<CallHierarchyOutgoingCall>>> {
     let _p = profile("handle_call_hierarchy_outgoing");
     let item = params.item;
 
     let doc = TextDocumentIdentifier::new(item.uri);
-    let frange = from_proto::file_range(&world, doc, item.range)?;
+    let frange = from_proto::file_range(&snap, doc, item.range)?;
     let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
 
-    let call_items = match world.analysis().outgoing_calls(fpos)? {
+    let call_items = match snap.analysis().outgoing_calls(fpos)? {
         None => return Ok(None),
         Some(it) => it,
     };
@@ -1098,8 +1102,8 @@ pub fn handle_call_hierarchy_outgoing(
 
     for call_item in call_items.into_iter() {
         let file_id = call_item.target.file_id();
-        let line_index = world.analysis().file_line_index(file_id)?;
-        let item = to_proto::call_hierarchy_item(&world, call_item.target)?;
+        let line_index = snap.analysis().file_line_index(file_id)?;
+        let item = to_proto::call_hierarchy_item(&snap, call_item.target)?;
         res.push(CallHierarchyOutgoingCall {
             to: item,
             from_ranges: call_item
@@ -1114,31 +1118,31 @@ pub fn handle_call_hierarchy_outgoing(
 }
 
 pub fn handle_semantic_tokens(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: SemanticTokensParams,
 ) -> Result<Option<SemanticTokensResult>> {
     let _p = profile("handle_semantic_tokens");
 
-    let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
-    let text = world.analysis().file_text(file_id)?;
-    let line_index = world.analysis().file_line_index(file_id)?;
+    let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
+    let text = snap.analysis().file_text(file_id)?;
+    let line_index = snap.analysis().file_line_index(file_id)?;
 
-    let highlights = world.analysis().highlight(file_id)?;
+    let highlights = snap.analysis().highlight(file_id)?;
     let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
     Ok(Some(semantic_tokens.into()))
 }
 
 pub fn handle_semantic_tokens_range(
-    world: WorldSnapshot,
+    snap: GlobalStateSnapshot,
     params: SemanticTokensRangeParams,
 ) -> Result<Option<SemanticTokensRangeResult>> {
     let _p = profile("handle_semantic_tokens_range");
 
-    let frange = from_proto::file_range(&world, params.text_document, params.range)?;
-    let text = world.analysis().file_text(frange.file_id)?;
-    let line_index = world.analysis().file_line_index(frange.file_id)?;
+    let frange = from_proto::file_range(&snap, params.text_document, params.range)?;
+    let text = snap.analysis().file_text(frange.file_id)?;
+    let line_index = snap.analysis().file_line_index(frange.file_id)?;
 
-    let highlights = world.analysis().highlight_range(frange)?;
+    let highlights = snap.analysis().highlight_range(frange)?;
     let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
     Ok(Some(semantic_tokens.into()))
 }