mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Propagating sysroot
down + Refactoring
This commit is contained in:
parent
67e58c5ba6
commit
4ac39f0c98
4 changed files with 66 additions and 35 deletions
|
@ -1534,20 +1534,26 @@ pub(crate) fn handle_semantic_tokens_range(
|
|||
|
||||
pub(crate) fn handle_open_docs(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_types::TextDocumentPositionParams,
|
||||
) -> Result<(Option<lsp_types::Url>, Option<lsp_types::Url>)> {
|
||||
params: lsp_types::TextDocumentPositionParams,
|
||||
) -> Result<(Option<lsp_types::Url>, Option<lsp_types::Url>)> {
|
||||
let _p = profile::span("handle_open_docs");
|
||||
let file_uri = ¶ms.text_document.uri;
|
||||
let file_id = from_proto::file_id(&snap, file_uri)?;
|
||||
let position = from_proto::file_position(&snap, params)?;
|
||||
|
||||
let cargo = match &*snap.analysis.crates_for(file_id)? {
|
||||
&[crate_id, ..] => snap.cargo_target_for_crate_root(crate_id).map(|(it, _)| it),
|
||||
_ => None,
|
||||
};
|
||||
let ws_and_sysroot = snap.workspaces.iter().find_map(|ws| match ws {
|
||||
ProjectWorkspace::Cargo { cargo, sysroot, .. } => Some((cargo, sysroot.as_ref().ok())),
|
||||
ProjectWorkspace::Json { .. } => None,
|
||||
ProjectWorkspace::DetachedFiles { .. } => None,
|
||||
});
|
||||
|
||||
let (cargo, sysroot) = match ws_and_sysroot {
|
||||
Some((ws, Some(sysroot))) => (Some(ws), Some(sysroot)),
|
||||
_ => (None, None),
|
||||
};
|
||||
|
||||
let sysroot = sysroot.map(|p| p.root().as_os_str());
|
||||
let target_dir = cargo.map(|cargo| cargo.target_directory()).map(|p| p.as_os_str());
|
||||
let Ok(remote_urls) = snap.analysis.external_docs(position, target_dir) else { return Ok((None, None)); };
|
||||
|
||||
let Ok(remote_urls) = snap.analysis.external_docs(position, target_dir, sysroot) else { return Ok((None, None)); };
|
||||
|
||||
let web_url = remote_urls.web_url.and_then(|it| Url::parse(&it).ok());
|
||||
let local_url = remote_urls.local_url.and_then(|it| Url::parse(&it).ok());
|
||||
|
@ -1555,6 +1561,7 @@ pub(crate) fn handle_open_docs(
|
|||
Ok((web_url, local_url))
|
||||
}
|
||||
|
||||
|
||||
pub(crate) fn handle_open_cargo_toml(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::OpenCargoTomlParams,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue