Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show onHover docs of multiple LSPs #8985

Open
tcoopman opened this issue Dec 4, 2023 Discussed in #8872 · 1 comment
Open

Show onHover docs of multiple LSPs #8985

tcoopman opened this issue Dec 4, 2023 Discussed in #8872 · 1 comment
Labels
A-helix-term Area: Helix term improvements A-language-server Area: Language server client C-enhancement Category: Improvements

Comments

@tcoopman
Copy link

tcoopman commented Dec 4, 2023

I couldn't find if this is an issue with the event system (#8021), and can't seem to find a similar issue.

onHover docs doesn't work well with multiple LSPs. For example, I've got both ["tailwind", "elixir"] configured.
If I hover on something from elixir, I don't get any docs. If I remove the tailwind lsp, I do get docs for elixir, but of course none for the tailwind classes.
If I reverse the order, hover on elixir works but not on tailwind.

So the issue is that hover should work for both configured lsps.

Discussed in #8872

@kirawi kirawi added C-enhancement Category: Improvements A-language-server Area: Language server client A-helix-term Area: Helix term improvements E-good-first-issue Call for participation: Issues suitable for new contributors and removed E-good-first-issue Call for participation: Issues suitable for new contributors labels Dec 8, 2023
@kirawi
Copy link
Member

kirawi commented Dec 10, 2023

pub fn hover(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
// TODO support multiple language servers (merge UI somehow)
let language_server =
language_server_with_feature!(cx.editor, doc, LanguageServerFeature::Hover);
// TODO: factor out a doc.position_identifier() that returns lsp::TextDocumentPositionIdentifier
let pos = doc.position(view.id, language_server.offset_encoding());
let future = language_server
.text_document_hover(doc.identifier(), pos, None)
.unwrap();
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,
};
// skip if contents empty
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);
}
},
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements A-language-server Area: Language server client C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

2 participants