mirror of https://github.com/helix-editor/helix
feat: add new `hover_dump` command
parent
e9c16b7fc5
commit
1450ec8733
|
@ -496,6 +496,7 @@ impl MappableCommand {
|
||||||
remove_primary_selection, "Remove primary selection",
|
remove_primary_selection, "Remove primary selection",
|
||||||
completion, "Invoke completion popup",
|
completion, "Invoke completion popup",
|
||||||
hover, "Show docs for item under cursor",
|
hover, "Show docs for item under cursor",
|
||||||
|
hover_dump, "Show docs for item under cursor in a new buffer",
|
||||||
toggle_comments, "Comment/uncomment selections",
|
toggle_comments, "Comment/uncomment selections",
|
||||||
toggle_line_comments, "Line comment/uncomment selections",
|
toggle_line_comments, "Line comment/uncomment selections",
|
||||||
toggle_block_comments, "Block comment/uncomment selections",
|
toggle_block_comments, "Block comment/uncomment selections",
|
||||||
|
|
|
@ -14,7 +14,7 @@ use tui::{text::Span, widgets::Row};
|
||||||
use super::{align_view, push_jump, Align, Context, Editor};
|
use super::{align_view, push_jump, Align, Context, Editor};
|
||||||
|
|
||||||
use helix_core::{
|
use helix_core::{
|
||||||
syntax::LanguageServerFeature, text_annotations::InlineAnnotation, Selection, Uri,
|
syntax::LanguageServerFeature, text_annotations::InlineAnnotation, Rope, Selection, Uri,
|
||||||
};
|
};
|
||||||
use helix_stdx::path;
|
use helix_stdx::path;
|
||||||
use helix_view::{
|
use helix_view::{
|
||||||
|
@ -1036,9 +1036,16 @@ pub fn signature_help(cx: &mut Context) {
|
||||||
.trigger_signature_help(SignatureHelpInvoked::Manual, cx.editor)
|
.trigger_signature_help(SignatureHelpInvoked::Manual, cx.editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <<<<a<<< HEAD
|
||||||
pub fn hover(cx: &mut Context) {
|
pub fn hover(cx: &mut Context) {
|
||||||
use ui::lsp::hover::Hover;
|
use ui::lsp::hover::Hover;
|
||||||
|
|
||||||
|
// ===a====
|
||||||
|
// pub fn hover_impl<T>(cx: &mut Context, callback: T)
|
||||||
|
// where
|
||||||
|
// T: FnOnce(String, &mut Editor, &mut Compositor) + std::marker::Send + 'static,
|
||||||
|
// {
|
||||||
|
// >>>>a>>> 0e043a81 (feat: add new `hover_dump` command)
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
if doc
|
if doc
|
||||||
.language_servers_with_feature(LanguageServerFeature::Hover)
|
.language_servers_with_feature(LanguageServerFeature::Hover)
|
||||||
|
@ -1062,10 +1069,43 @@ pub fn hover(cx: &mut Context) {
|
||||||
.text_document_hover(doc.identifier(), pos, None)
|
.text_document_hover(doc.identifier(), pos, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// <<<<<<< HEAD
|
||||||
async move {
|
async move {
|
||||||
let json = request.await?;
|
let json = request.await?;
|
||||||
let response = serde_json::from_value::<Option<lsp::Hover>>(json)?;
|
let response = serde_json::from_value::<Option<lsp::Hover>>(json)?;
|
||||||
anyhow::Ok((server_name, response))
|
anyhow::Ok((server_name, response))
|
||||||
|
// =======
|
||||||
|
// cx.callback(
|
||||||
|
// future,
|
||||||
|
// move |editor, compositor, response: Option<lsp::Hover>| {
|
||||||
|
// if let Some(hover) = response {
|
||||||
|
// // hover.contents / .range <- used for visualizing
|
||||||
|
|
||||||
|
// fn marked_string_to_markdown(contents: lsp::MarkedString) -> String {
|
||||||
|
// match contents {
|
||||||
|
// lsp::MarkedString::String(contents) => contents,
|
||||||
|
// lsp::MarkedString::LanguageString(string) => {
|
||||||
|
// if string.language == "markdown" {
|
||||||
|
// string.value
|
||||||
|
// } else {
|
||||||
|
// format!("```{}\n{}\n```", string.language, string.value)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let contents = match hover.contents {
|
||||||
|
// lsp::HoverContents::Scalar(contents) => marked_string_to_markdown(contents),
|
||||||
|
// lsp::HoverContents::Array(contents) => contents
|
||||||
|
// .into_iter()
|
||||||
|
// .map(marked_string_to_markdown)
|
||||||
|
// .collect::<Vec<_>>()
|
||||||
|
// .join("\n\n"),
|
||||||
|
// lsp::HoverContents::Markup(contents) => contents.value,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// callback(contents, editor, compositor);
|
||||||
|
// >>>>>>> 0e043a81 (feat: add new `hover_dump` command)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -1094,6 +1134,25 @@ pub fn hover(cx: &mut Context) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hover_dump(cx: &mut Context) {
|
||||||
|
hover_impl(cx, |contents, editor, _compositor| {
|
||||||
|
editor.new_file_from_document(
|
||||||
|
Action::VerticalSplit,
|
||||||
|
Document::from(Rope::from(contents), None, editor.config.clone()),
|
||||||
|
);
|
||||||
|
let (_view, doc) = current!(editor);
|
||||||
|
if let Ok(_) = doc.set_language_by_language_id("markdown", editor.syn_loader.clone()) {};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hover(cx: &mut Context) {
|
||||||
|
hover_impl(cx, |contents, editor, compositor| {
|
||||||
|
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
|
||||||
|
let popup = Popup::new("hover", contents).auto_close(true);
|
||||||
|
compositor.replace_or_push("hover", popup);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rename_symbol(cx: &mut Context) {
|
pub fn rename_symbol(cx: &mut Context) {
|
||||||
fn get_prefill_from_word_boundary(editor: &Editor) -> String {
|
fn get_prefill_from_word_boundary(editor: &Editor) -> String {
|
||||||
let (view, doc) = current_ref!(editor);
|
let (view, doc) = current_ref!(editor);
|
||||||
|
|
|
@ -283,6 +283,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
|
||||||
"R" => replace_selections_with_clipboard,
|
"R" => replace_selections_with_clipboard,
|
||||||
"/" => global_search,
|
"/" => global_search,
|
||||||
"k" => hover,
|
"k" => hover,
|
||||||
|
"K" => hover_dump,
|
||||||
"r" => rename_symbol,
|
"r" => rename_symbol,
|
||||||
"h" => select_references_to_symbol_under_cursor,
|
"h" => select_references_to_symbol_under_cursor,
|
||||||
"c" => toggle_comments,
|
"c" => toggle_comments,
|
||||||
|
|
|
@ -1708,7 +1708,7 @@ impl Editor {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_file_from_document(&mut self, action: Action, doc: Document) -> DocumentId {
|
pub fn new_file_from_document(&mut self, action: Action, doc: Document) -> DocumentId {
|
||||||
let id = self.new_document(doc);
|
let id = self.new_document(doc);
|
||||||
self.switch(id, action);
|
self.switch(id, action);
|
||||||
id
|
id
|
||||||
|
|
Loading…
Reference in New Issue