Skip to content

Commit a14194b

Browse files
committed
Changes from review
1 parent 8c32bde commit a14194b

File tree

6 files changed

+14
-47
lines changed

6 files changed

+14
-47
lines changed

crates/ide/src/doc_links.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ pub fn get_doc_link<T: Resolvable + Clone>(db: &dyn HirDatabase, definition: &T)
100100
// BUG: For Option
101101
// Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some
102102
// 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
106103
fn get_doc_link_impl(db: &dyn HirDatabase, moddef: &ModuleDef) -> Option<String> {
107104
// Get the outermost definition for the moduledef. This is used to resolve the public path to the type,
108105
// then we can join the method, field, etc onto it if required.

crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl Analysis {
383383
}
384384

385385
/// Return URL(s) for the documentation of the symbol under the cursor.
386-
pub fn get_doc_url(
386+
pub fn external_docs(
387387
&self,
388388
position: FilePosition,
389389
) -> Cancelable<Option<doc_links::DocumentationLink>> {

crates/rust-analyzer/src/handlers.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
config::RustfmtConfig,
3535
from_json, from_proto,
3636
global_state::{GlobalState, GlobalStateSnapshot},
37-
lsp_ext::{self, DocumentationLink, InlayHint, InlayHintsParams, OpenDocsParams},
37+
lsp_ext::{self, InlayHint, InlayHintsParams},
3838
to_proto, LspError, Result,
3939
};
4040

@@ -1312,15 +1312,14 @@ pub(crate) fn handle_semantic_tokens_range(
13121312

13131313
pub(crate) fn handle_open_docs(
13141314
snap: GlobalStateSnapshot,
1315-
params: OpenDocsParams,
1316-
) -> Result<DocumentationLink> {
1315+
params: lsp_types::TextDocumentPositionParams,
1316+
) -> Result<Option<lsp_types::Url>> {
13171317
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)?;
13191319

1320-
// FIXME: Propogate or ignore this error instead of panicking.
1321-
let remote = snap.analysis.get_doc_url(position)?.unwrap();
1320+
let remote = snap.analysis.external_docs(position)?;
13221321

1323-
Ok(DocumentationLink { remote })
1322+
Ok(remote.and_then(|remote| Url::parse(&remote).ok()))
13241323
}
13251324

13261325
fn implementation_title(count: usize) -> String {

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -348,30 +348,10 @@ pub struct CommandLink {
348348
pub tooltip: Option<String>,
349349
}
350350

351-
pub enum OpenDocs {}
351+
pub enum ExternalDocs {}
352352

353-
impl Request for OpenDocs {
354-
type Params = OpenDocsParams;
355-
type Result = DocumentationLink;
356-
const METHOD: &'static str = "rust-analyzer/openDocs";
357-
}
358-
359-
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
360-
#[serde(rename_all = "camelCase")]
361-
pub 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")]
371-
pub 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>
353+
impl Request for ExternalDocs {
354+
type Params = lsp_types::TextDocumentPositionParams;
355+
type Result = Option<lsp_types::Url>;
356+
const METHOD: &'static str = "experimental/externalDocs";
377357
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl GlobalState {
384384
.on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)?
385385
.on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)?
386386
.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)?
388388
.on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
389389
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
390390
.on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?

editors/code/src/lsp_ext.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,4 @@ export interface CommandLinkGroup {
119119
commands: CommandLink[];
120120
}
121121

122-
export interface DocumentationLink {
123-
remote: string;
124-
}
125-
126-
export interface OpenDocsParams {
127-
textDocument: lc.TextDocumentIdentifier;
128-
position: lc.Position;
129-
}
130-
131-
export const openDocs = new lc.RequestType<OpenDocsParams, DocumentationLink, void>('rust-analyzer/openDocs');
122+
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, String | void, void>('experimental/externalDocs');

0 commit comments

Comments
 (0)