diff --git a/.gitignore b/.gitignore index b205bf3fb6..7e097c0158 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ crates/*/target generated_assists.adoc generated_features.adoc generated_diagnostic.adoc +.DS_Store diff --git a/crates/ide/.DS_Store b/crates/ide/.DS_Store new file mode 100644 index 0000000000..a566736aa9 Binary files /dev/null and b/crates/ide/.DS_Store differ diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 74a021dbf9..372180ab58 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -398,13 +398,10 @@ impl Config { } if let Some(code_action) = &doc_caps.code_action { - match (code_action.data_support, &code_action.resolve_support) { - (Some(true), Some(resolve_support)) => { - if resolve_support.properties.iter().any(|it| it == "edit") { - self.client_caps.code_action_resolve = true; - } + if let Some(resolve_support) = &code_action.resolve_support { + if resolve_support.properties.iter().any(|it| it == "edit") { + self.client_caps.code_action_resolve = true; } - _ => (), } } } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 95659b0db9..782797e85f 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -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> { + let _p = profile::span("handle_open_cargo_toml"); + let file_id = from_proto::file_id(&snap, ¶ms.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() diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index a7c3028e49..a5c65fa3e8 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -354,3 +354,17 @@ impl Request for ExternalDocs { type Result = Option; const METHOD: &'static str = "experimental/externalDocs"; } + +pub enum OpenCargoToml {} + +impl Request for OpenCargoToml { + type Params = OpenCargoTomlParams; + type Result = Option; + const METHOD: &'static str = "experimental/openCargoToml"; +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct OpenCargoTomlParams { + pub text_document: TextDocumentIdentifier, +} diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 6e6cac42e0..68a53bbcb9 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -438,6 +438,7 @@ impl GlobalState { .on::(handlers::handle_code_action_resolve) .on::(handlers::handle_hover) .on::(handlers::handle_open_docs) + .on::(handlers::handle_open_cargo_toml) .on::(handlers::handle_on_type_formatting) .on::(handlers::handle_document_symbol) .on::(handlers::handle_workspace_symbol) diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index 77d4e0ec99..db9727bee4 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -1,8 +1,8 @@