From a14194b428efdb09cc45f9862ec34bef0038cd35 Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Tue, 1 Sep 2020 11:38:32 +1200 Subject: Changes from review --- crates/ide/src/doc_links.rs | 3 --- crates/ide/src/lib.rs | 2 +- crates/rust-analyzer/src/handlers.rs | 13 ++++++------- crates/rust-analyzer/src/lsp_ext.rs | 30 +++++------------------------- crates/rust-analyzer/src/main_loop.rs | 2 +- 5 files changed, 13 insertions(+), 37 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 1e102997f..7fe88577d 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -100,9 +100,6 @@ pub fn get_doc_link(db: &dyn HirDatabase, definition: &T) // BUG: For Option // Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some // Instead of https://doc.rust-lang.org/nightly/core/option/enum.Option.html -// -// BUG: For methods -// import_map.path_of(ns) fails, is not designed to resolve methods fn get_doc_link_impl(db: &dyn HirDatabase, moddef: &ModuleDef) -> Option { // Get the outermost definition for the moduledef. This is used to resolve the public path to the type, // then we can join the method, field, etc onto it if required. diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index b92e6d9ea..0580d2979 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -383,7 +383,7 @@ impl Analysis { } /// Return URL(s) for the documentation of the symbol under the cursor. - pub fn get_doc_url( + pub fn external_docs( &self, position: FilePosition, ) -> Cancelable> { diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index ec8c8fecd..ba73abcac 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -34,7 +34,7 @@ use crate::{ config::RustfmtConfig, from_json, from_proto, global_state::{GlobalState, GlobalStateSnapshot}, - lsp_ext::{self, DocumentationLink, InlayHint, InlayHintsParams, OpenDocsParams}, + lsp_ext::{self, InlayHint, InlayHintsParams}, to_proto, LspError, Result, }; @@ -1312,15 +1312,14 @@ pub(crate) fn handle_semantic_tokens_range( pub(crate) fn handle_open_docs( snap: GlobalStateSnapshot, - params: OpenDocsParams, -) -> Result { + params: lsp_types::TextDocumentPositionParams, +) -> Result> { let _p = profile::span("handle_open_docs"); - let position = from_proto::file_position(&snap, params.position)?; + let position = from_proto::file_position(&snap, params)?; - // FIXME: Propogate or ignore this error instead of panicking. - let remote = snap.analysis.get_doc_url(position)?.unwrap(); + let remote = snap.analysis.external_docs(position)?; - Ok(DocumentationLink { remote }) + Ok(remote.and_then(|remote| Url::parse(&remote).ok())) } fn implementation_title(count: usize) -> String { diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 83a20802f..f31f8d900 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -348,30 +348,10 @@ pub struct CommandLink { pub tooltip: Option, } -pub enum OpenDocs {} +pub enum ExternalDocs {} -impl Request for OpenDocs { - type Params = OpenDocsParams; - type Result = DocumentationLink; - const METHOD: &'static str = "rust-analyzer/openDocs"; -} - -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct OpenDocsParams { - // TODO: I don't know the difference between these two methods of passing position. - #[serde(flatten)] - pub position: lsp_types::TextDocumentPositionParams, - // pub textDocument: lsp_types::TextDocumentIdentifier, - // pub position: lsp_types::Position, -} - -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct DocumentationLink { - pub remote: String, // TODO: Better API? - // #[serde(skip_serializing_if = "Option::is_none")] - // pub remote: Option, - // #[serde(skip_serializing_if = "Option::is_none")] - // pub local: Option +impl Request for ExternalDocs { + type Params = lsp_types::TextDocumentPositionParams; + type Result = Option; + const METHOD: &'static str = "experimental/externalDocs"; } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 75f85011d..06b38d99c 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -384,7 +384,7 @@ impl GlobalState { .on::(handlers::handle_code_action)? .on::(handlers::handle_resolve_code_action)? .on::(handlers::handle_hover)? - .on::(handlers::handle_open_docs)? + .on::(handlers::handle_open_docs)? .on::(handlers::handle_on_type_formatting)? .on::(handlers::handle_document_symbol)? .on::(handlers::handle_workspace_symbol)? -- cgit v1.2.3