Tweak visibility

This commit is contained in:
Aleksey Kladov 2020-06-25 00:41:08 +02:00
parent 012a7e57b9
commit 10ee6eb733
6 changed files with 84 additions and 88 deletions

View file

@ -94,7 +94,7 @@ impl CargoTargetSpec {
global_state_snapshot: &GlobalStateSnapshot, global_state_snapshot: &GlobalStateSnapshot,
file_id: FileId, file_id: FileId,
) -> Result<Option<CargoTargetSpec>> { ) -> Result<Option<CargoTargetSpec>> {
let crate_id = match global_state_snapshot.analysis().crate_for(file_id)?.first() { let crate_id = match global_state_snapshot.analysis.crate_for(file_id)?.first() {
Some(crate_id) => *crate_id, Some(crate_id) => *crate_id,
None => return Ok(None), None => return Ok(None),
}; };

View file

@ -37,7 +37,7 @@ pub(crate) fn file_position(
tdpp: lsp_types::TextDocumentPositionParams, tdpp: lsp_types::TextDocumentPositionParams,
) -> Result<FilePosition> { ) -> Result<FilePosition> {
let file_id = file_id(world, &tdpp.text_document.uri)?; let file_id = file_id(world, &tdpp.text_document.uri)?;
let line_index = world.analysis().file_line_index(file_id)?; let line_index = world.analysis.file_line_index(file_id)?;
let offset = offset(&*line_index, tdpp.position); let offset = offset(&*line_index, tdpp.position);
Ok(FilePosition { file_id, offset }) Ok(FilePosition { file_id, offset })
} }
@ -48,7 +48,7 @@ pub(crate) fn file_range(
range: lsp_types::Range, range: lsp_types::Range,
) -> Result<FileRange> { ) -> Result<FileRange> {
let file_id = file_id(world, &text_document_identifier.uri)?; let file_id = file_id(world, &text_document_identifier.uri)?;
let line_index = world.analysis().file_line_index(file_id)?; let line_index = world.analysis.file_line_index(file_id)?;
let range = text_range(&line_index, range); let range = text_range(&line_index, range);
Ok(FileRange { file_id, range }) Ok(FileRange { file_id, range })
} }

View file

@ -60,7 +60,6 @@ impl Default for Status {
/// incremental salsa database. /// incremental salsa database.
pub(crate) struct GlobalState { pub(crate) struct GlobalState {
pub(crate) config: Config, pub(crate) config: Config,
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
pub(crate) analysis_host: AnalysisHost, pub(crate) analysis_host: AnalysisHost,
pub(crate) loader: Box<dyn vfs::loader::Handle>, pub(crate) loader: Box<dyn vfs::loader::Handle>,
pub(crate) task_receiver: Receiver<vfs::loader::Message>, pub(crate) task_receiver: Receiver<vfs::loader::Message>,
@ -70,19 +69,20 @@ pub(crate) struct GlobalState {
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
pub(crate) status: Status, pub(crate) status: Status,
pub(crate) req_queue: ReqQueue, pub(crate) req_queue: ReqQueue,
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, latest_requests: Arc<RwLock<LatestRequests>>,
source_root_config: SourceRootConfig, source_root_config: SourceRootConfig,
_proc_macro_client: ProcMacroClient, _proc_macro_client: ProcMacroClient,
workspaces: Arc<Vec<ProjectWorkspace>>,
} }
/// An immutable snapshot of the world's state at a point in time. /// An immutable snapshot of the world's state at a point in time.
pub(crate) struct GlobalStateSnapshot { pub(crate) struct GlobalStateSnapshot {
pub(crate) config: Config, pub(crate) config: Config,
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
pub(crate) analysis: Analysis, pub(crate) analysis: Analysis,
pub(crate) check_fixes: CheckFixes, pub(crate) check_fixes: CheckFixes,
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
workspaces: Arc<Vec<ProjectWorkspace>>,
} }
impl GlobalState { impl GlobalState {
@ -149,7 +149,6 @@ impl GlobalState {
analysis_host.apply_change(change); analysis_host.apply_change(change);
let mut res = GlobalState { let mut res = GlobalState {
config, config,
workspaces: Arc::new(workspaces),
analysis_host, analysis_host,
loader, loader,
task_receiver, task_receiver,
@ -162,6 +161,7 @@ impl GlobalState {
latest_requests: Default::default(), latest_requests: Default::default(),
source_root_config: project_folders.source_root_config, source_root_config: project_folders.source_root_config,
_proc_macro_client: proc_macro_client, _proc_macro_client: proc_macro_client,
workspaces: Arc::new(workspaces),
}; };
res.process_changes(); res.process_changes();
res res
@ -240,10 +240,6 @@ impl GlobalState {
} }
impl GlobalStateSnapshot { impl GlobalStateSnapshot {
pub(crate) fn analysis(&self) -> &Analysis {
&self.analysis
}
pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> { pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> {
let path = from_proto::abs_path(url)?; let path = from_proto::abs_path(url)?;
let path = path.into(); let path = path.into();
@ -272,7 +268,7 @@ impl GlobalStateSnapshot {
&self, &self,
crate_id: CrateId, crate_id: CrateId,
) -> Option<(&CargoWorkspace, Target)> { ) -> Option<(&CargoWorkspace, Target)> {
let file_id = self.analysis().crate_root(crate_id).ok()?; let file_id = self.analysis.crate_root(crate_id).ok()?;
let path = self.vfs.read().0.file_path(file_id); let path = self.vfs.read().0.file_path(file_id);
let path = path.as_path()?; let path = path.as_path()?;
self.workspaces.iter().find_map(|ws| match ws { self.workspaces.iter().find_map(|ws| match ws {

View file

@ -56,9 +56,9 @@ pub(crate) fn handle_syntax_tree(
) -> Result<String> { ) -> Result<String> {
let _p = profile("handle_syntax_tree"); let _p = profile("handle_syntax_tree");
let id = from_proto::file_id(&snap, &params.text_document.uri)?; let id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(id)?; let line_index = snap.analysis.file_line_index(id)?;
let text_range = params.range.map(|r| from_proto::text_range(&line_index, r)); let text_range = params.range.map(|r| from_proto::text_range(&line_index, r));
let res = snap.analysis().syntax_tree(id, text_range)?; let res = snap.analysis.syntax_tree(id, text_range)?;
Ok(res) Ok(res)
} }
@ -68,10 +68,10 @@ pub(crate) fn handle_expand_macro(
) -> Result<Option<lsp_ext::ExpandedMacro>> { ) -> Result<Option<lsp_ext::ExpandedMacro>> {
let _p = profile("handle_expand_macro"); let _p = profile("handle_expand_macro");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let offset = from_proto::offset(&line_index, params.position); let offset = from_proto::offset(&line_index, params.position);
let res = snap.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 })) Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
} }
@ -81,7 +81,7 @@ pub(crate) fn handle_selection_range(
) -> Result<Option<Vec<lsp_types::SelectionRange>>> { ) -> Result<Option<Vec<lsp_types::SelectionRange>>> {
let _p = profile("handle_selection_range"); let _p = profile("handle_selection_range");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let res: Result<Vec<lsp_types::SelectionRange>> = params let res: Result<Vec<lsp_types::SelectionRange>> = params
.positions .positions
.into_iter() .into_iter()
@ -93,7 +93,7 @@ pub(crate) fn handle_selection_range(
loop { loop {
ranges.push(range); ranges.push(range);
let frange = FileRange { file_id, range }; let frange = FileRange { file_id, range };
let next = snap.analysis().extend_selection(frange)?; let next = snap.analysis.extend_selection(frange)?;
if next == range { if next == range {
break; break;
} else { } else {
@ -124,13 +124,13 @@ pub(crate) fn handle_matching_brace(
) -> Result<Vec<Position>> { ) -> Result<Vec<Position>> {
let _p = profile("handle_matching_brace"); let _p = profile("handle_matching_brace");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let res = params let res = params
.positions .positions
.into_iter() .into_iter()
.map(|position| { .map(|position| {
let offset = from_proto::offset(&line_index, position); let offset = from_proto::offset(&line_index, position);
let offset = match snap.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, Ok(Some(matching_brace_offset)) => matching_brace_offset,
Err(_) | Ok(None) => offset, Err(_) | Ok(None) => offset,
}; };
@ -146,12 +146,12 @@ pub(crate) fn handle_join_lines(
) -> Result<Vec<lsp_types::TextEdit>> { ) -> Result<Vec<lsp_types::TextEdit>> {
let _p = profile("handle_join_lines"); let _p = profile("handle_join_lines");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let line_endings = snap.file_line_endings(file_id); let line_endings = snap.file_line_endings(file_id);
let mut res = TextEdit::default(); let mut res = TextEdit::default();
for range in params.ranges { for range in params.ranges {
let range = from_proto::text_range(&line_index, range); let range = from_proto::text_range(&line_index, range);
let edit = snap.analysis().join_lines(FileRange { file_id, range })?; let edit = snap.analysis.join_lines(FileRange { file_id, range })?;
match res.union(edit) { match res.union(edit) {
Ok(()) => (), Ok(()) => (),
Err(_edit) => { Err(_edit) => {
@ -169,11 +169,11 @@ pub(crate) fn handle_on_enter(
) -> Result<Option<Vec<lsp_ext::SnippetTextEdit>>> { ) -> Result<Option<Vec<lsp_ext::SnippetTextEdit>>> {
let _p = profile("handle_on_enter"); let _p = profile("handle_on_enter");
let position = from_proto::file_position(&snap, params)?; let position = from_proto::file_position(&snap, params)?;
let edit = match snap.analysis().on_enter(position)? { let edit = match snap.analysis.on_enter(position)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
let line_index = snap.analysis().file_line_index(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 line_endings = snap.file_line_endings(position.file_id);
let edit = to_proto::snippet_text_edit_vec(&line_index, line_endings, true, edit); let edit = to_proto::snippet_text_edit_vec(&line_index, line_endings, true, edit);
Ok(Some(edit)) Ok(Some(edit))
@ -186,7 +186,7 @@ pub(crate) fn handle_on_type_formatting(
) -> Result<Option<Vec<lsp_types::TextEdit>>> { ) -> Result<Option<Vec<lsp_types::TextEdit>>> {
let _p = profile("handle_on_type_formatting"); let _p = profile("handle_on_type_formatting");
let mut position = from_proto::file_position(&snap, params.text_document_position)?; 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_index = snap.analysis.file_line_index(position.file_id)?;
let line_endings = snap.file_line_endings(position.file_id); let line_endings = snap.file_line_endings(position.file_id);
// in `ra_ide`, the `on_type` invariant is that // in `ra_ide`, the `on_type` invariant is that
@ -194,7 +194,7 @@ pub(crate) fn handle_on_type_formatting(
position.offset -= TextSize::of('.'); position.offset -= TextSize::of('.');
let char_typed = params.ch.chars().next().unwrap_or('\0'); let char_typed = params.ch.chars().next().unwrap_or('\0');
assert!({ assert!({
let text = snap.analysis().file_text(position.file_id)?; let text = snap.analysis.file_text(position.file_id)?;
text[usize::from(position.offset)..].starts_with(char_typed) text[usize::from(position.offset)..].starts_with(char_typed)
}); });
@ -206,7 +206,7 @@ pub(crate) fn handle_on_type_formatting(
return Ok(None); return Ok(None);
} }
let edit = snap.analysis().on_char_typed(position, char_typed)?; let edit = snap.analysis.on_char_typed(position, char_typed)?;
let mut edit = match edit { let mut edit = match edit {
Some(it) => it, Some(it) => it,
None => return Ok(None), None => return Ok(None),
@ -225,11 +225,11 @@ pub(crate) fn handle_document_symbol(
) -> Result<Option<lsp_types::DocumentSymbolResponse>> { ) -> Result<Option<lsp_types::DocumentSymbolResponse>> {
let _p = profile("handle_document_symbol"); let _p = profile("handle_document_symbol");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let mut parents: Vec<(DocumentSymbol, Option<usize>)> = Vec::new(); let mut parents: Vec<(DocumentSymbol, Option<usize>)> = Vec::new();
for symbol in snap.analysis().file_structure(file_id)? { for symbol in snap.analysis.file_structure(file_id)? {
let doc_symbol = DocumentSymbol { let doc_symbol = DocumentSymbol {
name: symbol.label, name: symbol.label,
detail: symbol.detail, detail: symbol.detail,
@ -317,7 +317,7 @@ pub(crate) fn handle_workspace_symbol(
fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> { fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
let mut res = Vec::new(); let mut res = Vec::new();
for nav in snap.analysis().symbol_search(query)? { for nav in snap.analysis.symbol_search(query)? {
let info = SymbolInformation { let info = SymbolInformation {
name: nav.name().to_string(), name: nav.name().to_string(),
kind: to_proto::symbol_kind(nav.kind()), kind: to_proto::symbol_kind(nav.kind()),
@ -337,7 +337,7 @@ pub(crate) fn handle_goto_definition(
) -> Result<Option<lsp_types::GotoDefinitionResponse>> { ) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
let _p = profile("handle_goto_definition"); let _p = profile("handle_goto_definition");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let nav_info = match snap.analysis().goto_definition(position)? { let nav_info = match snap.analysis.goto_definition(position)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -352,7 +352,7 @@ pub(crate) fn handle_goto_implementation(
) -> Result<Option<lsp_types::request::GotoImplementationResponse>> { ) -> Result<Option<lsp_types::request::GotoImplementationResponse>> {
let _p = profile("handle_goto_implementation"); let _p = profile("handle_goto_implementation");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let nav_info = match snap.analysis().goto_implementation(position)? { let nav_info = match snap.analysis.goto_implementation(position)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -367,7 +367,7 @@ pub(crate) fn handle_goto_type_definition(
) -> Result<Option<lsp_types::request::GotoTypeDefinitionResponse>> { ) -> Result<Option<lsp_types::request::GotoTypeDefinitionResponse>> {
let _p = profile("handle_goto_type_definition"); let _p = profile("handle_goto_type_definition");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let nav_info = match snap.analysis().goto_type_definition(position)? { let nav_info = match snap.analysis.goto_type_definition(position)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -382,7 +382,7 @@ pub(crate) fn handle_parent_module(
) -> Result<Option<lsp_types::GotoDefinitionResponse>> { ) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
let _p = profile("handle_parent_module"); let _p = profile("handle_parent_module");
let position = from_proto::file_position(&snap, params)?; let position = from_proto::file_position(&snap, params)?;
let navs = snap.analysis().parent_module(position)?; let navs = snap.analysis.parent_module(position)?;
let res = to_proto::goto_definition_response(&snap, None, navs)?; let res = to_proto::goto_definition_response(&snap, None, navs)?;
Ok(Some(res)) Ok(Some(res))
} }
@ -393,11 +393,11 @@ pub(crate) fn handle_runnables(
) -> Result<Vec<lsp_ext::Runnable>> { ) -> Result<Vec<lsp_ext::Runnable>> {
let _p = profile("handle_runnables"); let _p = profile("handle_runnables");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let offset = params.position.map(|it| from_proto::offset(&line_index, it)); let offset = params.position.map(|it| from_proto::offset(&line_index, it));
let mut res = Vec::new(); let mut res = Vec::new();
let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?; let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
for runnable in snap.analysis().runnables(file_id)? { for runnable in snap.analysis.runnables(file_id)? {
if let Some(offset) = offset { if let Some(offset) = offset {
if !runnable.nav.full_range().contains_inclusive(offset) { if !runnable.nav.full_range().contains_inclusive(offset) {
continue; continue;
@ -456,7 +456,7 @@ pub(crate) fn handle_completion(
let mut res = false; let mut res = false;
if let Some(ctx) = params.context { if let Some(ctx) = params.context {
if ctx.trigger_character.unwrap_or_default() == ":" { if ctx.trigger_character.unwrap_or_default() == ":" {
let source_file = snap.analysis().parse(position.file_id)?; let source_file = snap.analysis.parse(position.file_id)?;
let syntax = source_file.syntax(); let syntax = source_file.syntax();
let text = syntax.text(); let text = syntax.text();
if let Some(next_char) = text.char_at(position.offset) { if let Some(next_char) = text.char_at(position.offset) {
@ -474,11 +474,11 @@ pub(crate) fn handle_completion(
return Ok(None); return Ok(None);
} }
let items = match snap.analysis().completions(&snap.config.completion, position)? { let items = match snap.analysis.completions(&snap.config.completion, position)? {
None => return Ok(None), None => return Ok(None),
Some(items) => items, Some(items) => items,
}; };
let line_index = snap.analysis().file_line_index(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 line_endings = snap.file_line_endings(position.file_id);
let items: Vec<CompletionItem> = items let items: Vec<CompletionItem> = items
.into_iter() .into_iter()
@ -494,9 +494,9 @@ pub(crate) fn handle_folding_range(
) -> Result<Option<Vec<FoldingRange>>> { ) -> Result<Option<Vec<FoldingRange>>> {
let _p = profile("handle_folding_range"); let _p = profile("handle_folding_range");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let folds = snap.analysis().folding_ranges(file_id)?; let folds = snap.analysis.folding_ranges(file_id)?;
let text = snap.analysis().file_text(file_id)?; let text = snap.analysis.file_text(file_id)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let line_folding_only = snap.config.client_caps.line_folding_only; let line_folding_only = snap.config.client_caps.line_folding_only;
let res = folds let res = folds
.into_iter() .into_iter()
@ -511,7 +511,7 @@ pub(crate) fn handle_signature_help(
) -> Result<Option<lsp_types::SignatureHelp>> { ) -> Result<Option<lsp_types::SignatureHelp>> {
let _p = profile("handle_signature_help"); let _p = profile("handle_signature_help");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let call_info = match snap.analysis().call_info(position)? { let call_info = match snap.analysis.call_info(position)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -535,7 +535,7 @@ pub(crate) fn handle_hover(
) -> Result<Option<lsp_ext::Hover>> { ) -> Result<Option<lsp_ext::Hover>> {
let _p = profile("handle_hover"); let _p = profile("handle_hover");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let info = match snap.analysis().hover(position)? { let info = match snap.analysis.hover(position)? {
None => return Ok(None), None => return Ok(None),
Some(info) => info, Some(info) => info,
}; };
@ -562,13 +562,13 @@ pub(crate) fn handle_prepare_rename(
let _p = profile("handle_prepare_rename"); let _p = profile("handle_prepare_rename");
let position = from_proto::file_position(&snap, params)?; let position = from_proto::file_position(&snap, params)?;
let optional_change = snap.analysis().rename(position, "dummy")?; let optional_change = snap.analysis.rename(position, "dummy")?;
let range = match optional_change { let range = match optional_change {
None => return Ok(None), None => return Ok(None),
Some(it) => it.range, Some(it) => it.range,
}; };
let line_index = snap.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); let range = to_proto::range(&line_index, range);
Ok(Some(PrepareRenameResponse::Range(range))) Ok(Some(PrepareRenameResponse::Range(range)))
} }
@ -588,7 +588,7 @@ pub(crate) fn handle_rename(
.into()); .into());
} }
let optional_change = snap.analysis().rename(position, &*params.new_name)?; let optional_change = snap.analysis.rename(position, &*params.new_name)?;
let source_change = match optional_change { let source_change = match optional_change {
None => return Ok(None), None => return Ok(None),
Some(it) => it.info, Some(it) => it.info,
@ -604,7 +604,7 @@ pub(crate) fn handle_references(
let _p = profile("handle_references"); let _p = profile("handle_references");
let position = from_proto::file_position(&snap, params.text_document_position)?; let position = from_proto::file_position(&snap, params.text_document_position)?;
let refs = match snap.analysis().find_all_refs(position, None)? { let refs = match snap.analysis.find_all_refs(position, None)? {
None => return Ok(None), None => return Ok(None),
Some(refs) => refs, Some(refs) => refs,
}; };
@ -630,10 +630,10 @@ pub(crate) fn handle_formatting(
) -> Result<Option<Vec<lsp_types::TextEdit>>> { ) -> Result<Option<Vec<lsp_types::TextEdit>>> {
let _p = profile("handle_formatting"); let _p = profile("handle_formatting");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let file = snap.analysis().file_text(file_id)?; let file = snap.analysis.file_text(file_id)?;
let crate_ids = snap.analysis().crate_for(file_id)?; let crate_ids = snap.analysis.crate_for(file_id)?;
let file_line_index = snap.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 end_position = to_proto::position(&file_line_index, TextSize::of(file.as_str()));
let mut rustfmt = match &snap.config.rustfmt { let mut rustfmt = match &snap.config.rustfmt {
@ -642,7 +642,7 @@ pub(crate) fn handle_formatting(
cmd.args(extra_args); cmd.args(extra_args);
if let Some(&crate_id) = crate_ids.first() { if let Some(&crate_id) = crate_ids.first() {
// Assume all crates are in the same edition // Assume all crates are in the same edition
let edition = snap.analysis().crate_edition(crate_id)?; let edition = snap.analysis.crate_edition(crate_id)?;
cmd.arg("--edition"); cmd.arg("--edition");
cmd.arg(edition.to_string()); cmd.arg(edition.to_string());
} }
@ -706,9 +706,9 @@ fn handle_fixes(
res: &mut Vec<lsp_ext::CodeAction>, res: &mut Vec<lsp_ext::CodeAction>,
) -> Result<()> { ) -> Result<()> {
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let range = from_proto::text_range(&line_index, params.range); let range = from_proto::text_range(&line_index, params.range);
let diagnostics = snap.analysis().diagnostics(file_id)?; let diagnostics = snap.analysis.diagnostics(file_id)?;
let fixes_from_diagnostics = diagnostics let fixes_from_diagnostics = diagnostics
.into_iter() .into_iter()
@ -752,7 +752,7 @@ pub(crate) fn handle_code_action(
} }
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let range = from_proto::text_range(&line_index, params.range); let range = from_proto::text_range(&line_index, params.range);
let frange = FileRange { file_id, range }; let frange = FileRange { file_id, range };
let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
@ -761,12 +761,12 @@ pub(crate) fn handle_code_action(
if snap.config.client_caps.resolve_code_action { if snap.config.client_caps.resolve_code_action {
for (index, assist) in for (index, assist) in
snap.analysis().unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate() snap.analysis.unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate()
{ {
res.push(to_proto::unresolved_code_action(&snap, assist, index)?); res.push(to_proto::unresolved_code_action(&snap, assist, index)?);
} }
} else { } else {
for assist in snap.analysis().resolved_assists(&snap.config.assist, frange)?.into_iter() { for assist in snap.analysis.resolved_assists(&snap.config.assist, frange)?.into_iter() {
res.push(to_proto::resolved_code_action(&snap, assist)?); res.push(to_proto::resolved_code_action(&snap, assist)?);
} }
} }
@ -780,11 +780,11 @@ pub(crate) fn handle_resolve_code_action(
) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> { ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> {
let _p = profile("handle_resolve_code_action"); let _p = profile("handle_resolve_code_action");
let file_id = from_proto::file_id(&snap, &params.code_action_params.text_document.uri)?; 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 line_index = snap.analysis.file_line_index(file_id)?;
let range = from_proto::text_range(&line_index, params.code_action_params.range); let range = from_proto::text_range(&line_index, params.code_action_params.range);
let frange = FileRange { file_id, range }; let frange = FileRange { file_id, range };
let assists = snap.analysis().resolved_assists(&snap.config.assist, frange)?; let assists = snap.analysis.resolved_assists(&snap.config.assist, frange)?;
let (id_string, index) = split_delim(&params.id, ':').unwrap(); let (id_string, index) = split_delim(&params.id, ':').unwrap();
let index = index.parse::<usize>().unwrap(); let index = index.parse::<usize>().unwrap();
let assist = &assists[index]; let assist = &assists[index];
@ -805,12 +805,12 @@ pub(crate) fn handle_code_lens(
} }
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?; let cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
if snap.config.lens.runnable() { if snap.config.lens.runnable() {
// Gather runnables // Gather runnables
for runnable in snap.analysis().runnables(file_id)? { for runnable in snap.analysis.runnables(file_id)? {
if should_skip_target(&runnable, cargo_spec.as_ref()) { if should_skip_target(&runnable, cargo_spec.as_ref()) {
continue; continue;
} }
@ -838,7 +838,7 @@ pub(crate) fn handle_code_lens(
if snap.config.lens.impementations { if snap.config.lens.impementations {
// Handle impls // Handle impls
lenses.extend( lenses.extend(
snap.analysis() snap.analysis
.file_structure(file_id)? .file_structure(file_id)?
.into_iter() .into_iter()
.filter(|it| match it.kind { .filter(|it| match it.kind {
@ -916,10 +916,10 @@ pub(crate) fn handle_document_highlight(
) -> Result<Option<Vec<DocumentHighlight>>> { ) -> Result<Option<Vec<DocumentHighlight>>> {
let _p = profile("handle_document_highlight"); let _p = profile("handle_document_highlight");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let line_index = snap.analysis().file_line_index(position.file_id)?; let line_index = snap.analysis.file_line_index(position.file_id)?;
let refs = match snap let refs = match snap
.analysis() .analysis
.find_all_refs(position, Some(SearchScope::single_file(position.file_id)))? .find_all_refs(position, Some(SearchScope::single_file(position.file_id)))?
{ {
None => return Ok(None), None => return Ok(None),
@ -943,7 +943,7 @@ pub(crate) fn handle_ssr(
) -> Result<lsp_types::WorkspaceEdit> { ) -> Result<lsp_types::WorkspaceEdit> {
let _p = profile("handle_ssr"); let _p = profile("handle_ssr");
let source_change = let source_change =
snap.analysis().structural_search_replace(&params.query, params.parse_only)??; snap.analysis.structural_search_replace(&params.query, params.parse_only)??;
to_proto::workspace_edit(&snap, source_change) to_proto::workspace_edit(&snap, source_change)
} }
@ -952,9 +952,9 @@ pub(crate) fn publish_diagnostics(
file_id: FileId, file_id: FileId,
) -> Result<DiagnosticTask> { ) -> Result<DiagnosticTask> {
let _p = profile("publish_diagnostics"); let _p = profile("publish_diagnostics");
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let diagnostics: Vec<Diagnostic> = snap let diagnostics: Vec<Diagnostic> = snap
.analysis() .analysis
.diagnostics(file_id)? .diagnostics(file_id)?
.into_iter() .into_iter()
.map(|d| Diagnostic { .map(|d| Diagnostic {
@ -976,9 +976,9 @@ pub(crate) fn handle_inlay_hints(
) -> Result<Vec<InlayHint>> { ) -> Result<Vec<InlayHint>> {
let _p = profile("handle_inlay_hints"); let _p = profile("handle_inlay_hints");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let analysis = snap.analysis(); let line_index = snap.analysis.file_line_index(file_id)?;
let line_index = analysis.file_line_index(file_id)?; Ok(snap
Ok(analysis .analysis
.inlay_hints(file_id, &snap.config.inlay_hints)? .inlay_hints(file_id, &snap.config.inlay_hints)?
.into_iter() .into_iter()
.map(|it| to_proto::inlay_int(&line_index, it)) .map(|it| to_proto::inlay_int(&line_index, it))
@ -992,7 +992,7 @@ pub(crate) fn handle_call_hierarchy_prepare(
let _p = profile("handle_call_hierarchy_prepare"); let _p = profile("handle_call_hierarchy_prepare");
let position = from_proto::file_position(&snap, params.text_document_position_params)?; let position = from_proto::file_position(&snap, params.text_document_position_params)?;
let nav_info = match snap.analysis().call_hierarchy(position)? { let nav_info = match snap.analysis.call_hierarchy(position)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -1018,7 +1018,7 @@ pub(crate) fn handle_call_hierarchy_incoming(
let frange = from_proto::file_range(&snap, 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 fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
let call_items = match snap.analysis().incoming_calls(fpos)? { let call_items = match snap.analysis.incoming_calls(fpos)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -1027,7 +1027,7 @@ pub(crate) fn handle_call_hierarchy_incoming(
for call_item in call_items.into_iter() { for call_item in call_items.into_iter() {
let file_id = call_item.target.file_id(); let file_id = call_item.target.file_id();
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let item = to_proto::call_hierarchy_item(&snap, call_item.target)?; let item = to_proto::call_hierarchy_item(&snap, call_item.target)?;
res.push(CallHierarchyIncomingCall { res.push(CallHierarchyIncomingCall {
from: item, from: item,
@ -1053,7 +1053,7 @@ pub(crate) fn handle_call_hierarchy_outgoing(
let frange = from_proto::file_range(&snap, 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 fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
let call_items = match snap.analysis().outgoing_calls(fpos)? { let call_items = match snap.analysis.outgoing_calls(fpos)? {
None => return Ok(None), None => return Ok(None),
Some(it) => it, Some(it) => it,
}; };
@ -1062,7 +1062,7 @@ pub(crate) fn handle_call_hierarchy_outgoing(
for call_item in call_items.into_iter() { for call_item in call_items.into_iter() {
let file_id = call_item.target.file_id(); let file_id = call_item.target.file_id();
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let item = to_proto::call_hierarchy_item(&snap, call_item.target)?; let item = to_proto::call_hierarchy_item(&snap, call_item.target)?;
res.push(CallHierarchyOutgoingCall { res.push(CallHierarchyOutgoingCall {
to: item, to: item,
@ -1084,10 +1084,10 @@ pub(crate) fn handle_semantic_tokens(
let _p = profile("handle_semantic_tokens"); let _p = profile("handle_semantic_tokens");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let text = snap.analysis().file_text(file_id)?; let text = snap.analysis.file_text(file_id)?;
let line_index = snap.analysis().file_line_index(file_id)?; let line_index = snap.analysis.file_line_index(file_id)?;
let highlights = snap.analysis().highlight(file_id)?; let highlights = snap.analysis.highlight(file_id)?;
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
Ok(Some(semantic_tokens.into())) Ok(Some(semantic_tokens.into()))
} }
@ -1099,10 +1099,10 @@ pub(crate) fn handle_semantic_tokens_range(
let _p = profile("handle_semantic_tokens_range"); let _p = profile("handle_semantic_tokens_range");
let frange = from_proto::file_range(&snap, params.text_document, params.range)?; let frange = from_proto::file_range(&snap, params.text_document, params.range)?;
let text = snap.analysis().file_text(frange.file_id)?; let text = snap.analysis.file_text(frange.file_id)?;
let line_index = snap.analysis().file_line_index(frange.file_id)?; let line_index = snap.analysis.file_line_index(frange.file_id)?;
let highlights = snap.analysis().highlight_range(frange)?; let highlights = snap.analysis.highlight_range(frange)?;
let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights);
Ok(Some(semantic_tokens.into())) Ok(Some(semantic_tokens.into()))
} }
@ -1178,9 +1178,9 @@ fn show_impl_command_link(
position: &FilePosition, position: &FilePosition,
) -> Option<lsp_ext::CommandLinkGroup> { ) -> Option<lsp_ext::CommandLinkGroup> {
if snap.config.hover.implementations { if snap.config.hover.implementations {
if let Some(nav_data) = snap.analysis().goto_implementation(*position).unwrap_or(None) { if let Some(nav_data) = snap.analysis.goto_implementation(*position).unwrap_or(None) {
let uri = to_proto::url(snap, position.file_id); let uri = to_proto::url(snap, position.file_id);
let line_index = snap.analysis().file_line_index(position.file_id).ok()?; let line_index = snap.analysis.file_line_index(position.file_id).ok()?;
let position = to_proto::position(&line_index, position.offset); let position = to_proto::position(&line_index, position.offset);
let locations: Vec<_> = nav_data let locations: Vec<_> = nav_data
.info .info

View file

@ -300,7 +300,7 @@ fn loop_turn(
pool.execute({ pool.execute({
let subs = subscriptions; let subs = subscriptions;
let snap = global_state.snapshot(); let snap = global_state.snapshot();
move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) move || snap.analysis.prime_caches(subs).unwrap_or_else(|_: Canceled| ())
}); });
} }

View file

@ -440,7 +440,7 @@ pub(crate) fn location(
frange: FileRange, frange: FileRange,
) -> Result<lsp_types::Location> { ) -> Result<lsp_types::Location> {
let url = url(snap, frange.file_id); let url = url(snap, frange.file_id);
let line_index = snap.analysis().file_line_index(frange.file_id)?; let line_index = snap.analysis.file_line_index(frange.file_id)?;
let range = range(&line_index, frange.range); let range = range(&line_index, frange.range);
let loc = lsp_types::Location::new(url, range); let loc = lsp_types::Location::new(url, range);
Ok(loc) Ok(loc)
@ -453,7 +453,7 @@ pub(crate) fn location_link(
) -> Result<lsp_types::LocationLink> { ) -> Result<lsp_types::LocationLink> {
let origin_selection_range = match src { let origin_selection_range = match src {
Some(src) => { Some(src) => {
let line_index = snap.analysis().file_line_index(src.file_id)?; let line_index = snap.analysis.file_line_index(src.file_id)?;
let range = range(&line_index, src.range); let range = range(&line_index, src.range);
Some(range) Some(range)
} }
@ -473,7 +473,7 @@ fn location_info(
snap: &GlobalStateSnapshot, snap: &GlobalStateSnapshot,
target: NavigationTarget, target: NavigationTarget,
) -> Result<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> { ) -> Result<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> {
let line_index = snap.analysis().file_line_index(target.file_id())?; let line_index = snap.analysis.file_line_index(target.file_id())?;
let target_uri = url(snap, target.file_id()); let target_uri = url(snap, target.file_id());
let target_range = range(&line_index, target.full_range()); let target_range = range(&line_index, target.full_range());
@ -516,7 +516,7 @@ pub(crate) fn snippet_text_document_edit(
source_file_edit: SourceFileEdit, source_file_edit: SourceFileEdit,
) -> Result<lsp_ext::SnippetTextDocumentEdit> { ) -> Result<lsp_ext::SnippetTextDocumentEdit> {
let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id, None); let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id, None);
let line_index = snap.analysis().file_line_index(source_file_edit.file_id)?; let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?;
let line_endings = snap.file_line_endings(source_file_edit.file_id); let line_endings = snap.file_line_endings(source_file_edit.file_id);
let edits = source_file_edit let edits = source_file_edit
.edit .edit