diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 1e102997f2..7fe88577db 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 b92e6d9ea8..0580d2979e 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 ec8c8fecdd..ba73abcacd 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 83a20802f6..f31f8d9001 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 75f85011d9..06b38d99c8 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)? diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 569e747bd4..5628047150 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -119,13 +119,4 @@ export interface CommandLinkGroup { commands: CommandLink[]; } -export interface DocumentationLink { - remote: string; -} - -export interface OpenDocsParams { - textDocument: lc.TextDocumentIdentifier; - position: lc.Position; -} - -export const openDocs = new lc.RequestType('rust-analyzer/openDocs'); +export const openDocs = new lc.RequestType('experimental/externalDocs');