add open Cargo.toml action

This commit is contained in:
Anatol Liu
2020-11-12 17:48:07 -08:00
parent 111cc34c8f
commit b1b7727e04
15 changed files with 114 additions and 42 deletions

View File

@@ -1322,6 +1322,28 @@ pub(crate) fn handle_open_docs(
Ok(remote.and_then(|remote| Url::parse(&remote).ok()))
}
pub(crate) fn handle_open_cargo_toml(
snap: GlobalStateSnapshot,
params: lsp_ext::OpenCargoTomlParams,
) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
let _p = profile::span("handle_open_cargo_toml");
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let maybe_cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
if maybe_cargo_spec.is_none() {
return Ok(None);
}
let cargo_spec = maybe_cargo_spec.unwrap();
let cargo_toml_path = cargo_spec.workspace_root.join("Cargo.toml");
if !cargo_toml_path.exists() {
return Ok(None);
}
let cargo_toml_url = to_proto::url_from_abs_path(&cargo_toml_path);
let cargo_toml_location = Location::new(cargo_toml_url, Range::default());
let res = lsp_types::GotoDefinitionResponse::from(cargo_toml_location);
Ok(Some(res))
}
fn implementation_title(count: usize) -> String {
if count == 1 {
"1 implementation".into()