aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorZac Pullar-Strecker <[email protected]>2020-09-01 00:38:32 +0100
committerZac Pullar-Strecker <[email protected]>2020-10-08 03:01:30 +0100
commita14194b428efdb09cc45f9862ec34bef0038cd35 (patch)
treed069e22d7d162c719fd3a8eb388fc7052e0e7668 /crates
parent8c32bdea3662f4c65810e2d92569b0cb4e3872d9 (diff)
Changes from review
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/doc_links.rs3
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs13
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs30
-rw-r--r--crates/rust-analyzer/src/main_loop.rs2
5 files changed, 13 insertions, 37 deletions
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<T: Resolvable + Clone>(db: &dyn HirDatabase, definition: &T)
100// BUG: For Option 100// BUG: For Option
101// Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some 101// Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some
102// Instead of https://doc.rust-lang.org/nightly/core/option/enum.Option.html 102// Instead of https://doc.rust-lang.org/nightly/core/option/enum.Option.html
103//
104// BUG: For methods
105// import_map.path_of(ns) fails, is not designed to resolve methods
106fn get_doc_link_impl(db: &dyn HirDatabase, moddef: &ModuleDef) -> Option<String> { 103fn get_doc_link_impl(db: &dyn HirDatabase, moddef: &ModuleDef) -> Option<String> {
107 // Get the outermost definition for the moduledef. This is used to resolve the public path to the type, 104 // Get the outermost definition for the moduledef. This is used to resolve the public path to the type,
108 // then we can join the method, field, etc onto it if required. 105 // 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 {
383 } 383 }
384 384
385 /// Return URL(s) for the documentation of the symbol under the cursor. 385 /// Return URL(s) for the documentation of the symbol under the cursor.
386 pub fn get_doc_url( 386 pub fn external_docs(
387 &self, 387 &self,
388 position: FilePosition, 388 position: FilePosition,
389 ) -> Cancelable<Option<doc_links::DocumentationLink>> { 389 ) -> Cancelable<Option<doc_links::DocumentationLink>> {
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::{
34 config::RustfmtConfig, 34 config::RustfmtConfig,
35 from_json, from_proto, 35 from_json, from_proto,
36 global_state::{GlobalState, GlobalStateSnapshot}, 36 global_state::{GlobalState, GlobalStateSnapshot},
37 lsp_ext::{self, DocumentationLink, InlayHint, InlayHintsParams, OpenDocsParams}, 37 lsp_ext::{self, InlayHint, InlayHintsParams},
38 to_proto, LspError, Result, 38 to_proto, LspError, Result,
39}; 39};
40 40
@@ -1312,15 +1312,14 @@ pub(crate) fn handle_semantic_tokens_range(
1312 1312
1313pub(crate) fn handle_open_docs( 1313pub(crate) fn handle_open_docs(
1314 snap: GlobalStateSnapshot, 1314 snap: GlobalStateSnapshot,
1315 params: OpenDocsParams, 1315 params: lsp_types::TextDocumentPositionParams,
1316) -> Result<DocumentationLink> { 1316) -> Result<Option<lsp_types::Url>> {
1317 let _p = profile::span("handle_open_docs"); 1317 let _p = profile::span("handle_open_docs");
1318 let position = from_proto::file_position(&snap, params.position)?; 1318 let position = from_proto::file_position(&snap, params)?;
1319 1319
1320 // FIXME: Propogate or ignore this error instead of panicking. 1320 let remote = snap.analysis.external_docs(position)?;
1321 let remote = snap.analysis.get_doc_url(position)?.unwrap();
1322 1321
1323 Ok(DocumentationLink { remote }) 1322 Ok(remote.and_then(|remote| Url::parse(&remote).ok()))
1324} 1323}
1325 1324
1326fn implementation_title(count: usize) -> String { 1325fn 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 {
348 pub tooltip: Option<String>, 348 pub tooltip: Option<String>,
349} 349}
350 350
351pub enum OpenDocs {} 351pub enum ExternalDocs {}
352 352
353impl Request for OpenDocs { 353impl Request for ExternalDocs {
354 type Params = OpenDocsParams; 354 type Params = lsp_types::TextDocumentPositionParams;
355 type Result = DocumentationLink; 355 type Result = Option<lsp_types::Url>;
356 const METHOD: &'static str = "rust-analyzer/openDocs"; 356 const METHOD: &'static str = "experimental/externalDocs";
357}
358
359#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
360#[serde(rename_all = "camelCase")]
361pub struct OpenDocsParams {
362 // TODO: I don't know the difference between these two methods of passing position.
363 #[serde(flatten)]
364 pub position: lsp_types::TextDocumentPositionParams,
365 // pub textDocument: lsp_types::TextDocumentIdentifier,
366 // pub position: lsp_types::Position,
367}
368
369#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
370#[serde(rename_all = "camelCase")]
371pub struct DocumentationLink {
372 pub remote: String, // TODO: Better API?
373 // #[serde(skip_serializing_if = "Option::is_none")]
374 // pub remote: Option<String>,
375 // #[serde(skip_serializing_if = "Option::is_none")]
376 // pub local: Option<String>
377} 357}
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 {
384 .on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)? 384 .on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)?
385 .on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)? 385 .on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)?
386 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)? 386 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)?
387 .on::<lsp_ext::OpenDocs>(handlers::handle_open_docs)? 387 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)?
388 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)? 388 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
389 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)? 389 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
390 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)? 390 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?