mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Changes from review
This commit is contained in:
parent
8c32bdea36
commit
a14194b428
6 changed files with 14 additions and 47 deletions
|
@ -100,9 +100,6 @@ pub fn get_doc_link<T: Resolvable + Clone>(db: &dyn HirDatabase, definition: &T)
|
||||||
// BUG: For Option
|
// BUG: For Option
|
||||||
// Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some
|
// 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
|
// 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<String> {
|
fn get_doc_link_impl(db: &dyn HirDatabase, moddef: &ModuleDef) -> Option<String> {
|
||||||
// Get the outermost definition for the moduledef. This is used to resolve the public path to the type,
|
// 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.
|
// then we can join the method, field, etc onto it if required.
|
||||||
|
|
|
@ -383,7 +383,7 @@ impl Analysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return URL(s) for the documentation of the symbol under the cursor.
|
/// Return URL(s) for the documentation of the symbol under the cursor.
|
||||||
pub fn get_doc_url(
|
pub fn external_docs(
|
||||||
&self,
|
&self,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Option<doc_links::DocumentationLink>> {
|
) -> Cancelable<Option<doc_links::DocumentationLink>> {
|
||||||
|
|
|
@ -34,7 +34,7 @@ use crate::{
|
||||||
config::RustfmtConfig,
|
config::RustfmtConfig,
|
||||||
from_json, from_proto,
|
from_json, from_proto,
|
||||||
global_state::{GlobalState, GlobalStateSnapshot},
|
global_state::{GlobalState, GlobalStateSnapshot},
|
||||||
lsp_ext::{self, DocumentationLink, InlayHint, InlayHintsParams, OpenDocsParams},
|
lsp_ext::{self, InlayHint, InlayHintsParams},
|
||||||
to_proto, LspError, Result,
|
to_proto, LspError, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1312,15 +1312,14 @@ pub(crate) fn handle_semantic_tokens_range(
|
||||||
|
|
||||||
pub(crate) fn handle_open_docs(
|
pub(crate) fn handle_open_docs(
|
||||||
snap: GlobalStateSnapshot,
|
snap: GlobalStateSnapshot,
|
||||||
params: OpenDocsParams,
|
params: lsp_types::TextDocumentPositionParams,
|
||||||
) -> Result<DocumentationLink> {
|
) -> Result<Option<lsp_types::Url>> {
|
||||||
let _p = profile::span("handle_open_docs");
|
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.external_docs(position)?;
|
||||||
let remote = snap.analysis.get_doc_url(position)?.unwrap();
|
|
||||||
|
|
||||||
Ok(DocumentationLink { remote })
|
Ok(remote.and_then(|remote| Url::parse(&remote).ok()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn implementation_title(count: usize) -> String {
|
fn implementation_title(count: usize) -> String {
|
||||||
|
|
|
@ -348,30 +348,10 @@ pub struct CommandLink {
|
||||||
pub tooltip: Option<String>,
|
pub tooltip: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum OpenDocs {}
|
pub enum ExternalDocs {}
|
||||||
|
|
||||||
impl Request for OpenDocs {
|
impl Request for ExternalDocs {
|
||||||
type Params = OpenDocsParams;
|
type Params = lsp_types::TextDocumentPositionParams;
|
||||||
type Result = DocumentationLink;
|
type Result = Option<lsp_types::Url>;
|
||||||
const METHOD: &'static str = "rust-analyzer/openDocs";
|
const METHOD: &'static str = "experimental/externalDocs";
|
||||||
}
|
|
||||||
|
|
||||||
#[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<String>,
|
|
||||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
// pub local: Option<String>
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -384,7 +384,7 @@ impl GlobalState {
|
||||||
.on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)?
|
.on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)?
|
||||||
.on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)?
|
.on::<lsp_ext::ResolveCodeActionRequest>(handlers::handle_resolve_code_action)?
|
||||||
.on::<lsp_ext::HoverRequest>(handlers::handle_hover)?
|
.on::<lsp_ext::HoverRequest>(handlers::handle_hover)?
|
||||||
.on::<lsp_ext::OpenDocs>(handlers::handle_open_docs)?
|
.on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)?
|
||||||
.on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
|
.on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
|
||||||
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
|
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
|
||||||
.on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?
|
.on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?
|
||||||
|
|
|
@ -119,13 +119,4 @@ export interface CommandLinkGroup {
|
||||||
commands: CommandLink[];
|
commands: CommandLink[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DocumentationLink {
|
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, String | void, void>('experimental/externalDocs');
|
||||||
remote: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OpenDocsParams {
|
|
||||||
textDocument: lc.TextDocumentIdentifier;
|
|
||||||
position: lc.Position;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const openDocs = new lc.RequestType<OpenDocsParams, DocumentationLink, void>('rust-analyzer/openDocs');
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue