If documentation exists and hasn't been parsed, do so at render and keep

This commit is contained in:
Julia
2023-10-06 13:26:38 -04:00
parent b8876f2b17
commit ea6f366d23
+30 -16
View File
@@ -60,10 +60,10 @@ use itertools::Itertools;
pub use language::{char_kind, CharKind}; pub use language::{char_kind, CharKind};
use language::{ use language::{
language_settings::{self, all_language_settings, InlayHintSettings}, language_settings::{self, all_language_settings, InlayHintSettings},
point_from_lsp, AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, point_from_lsp, prepare_completion_documentation, AutoindentMode, BracketPair, Buffer,
CursorShape, Diagnostic, DiagnosticSeverity, File, IndentKind, IndentSize, Language, CodeAction, CodeLabel, Completion, CursorShape, Diagnostic, DiagnosticSeverity, Documentation,
LanguageServerName, OffsetRangeExt, OffsetUtf16, Point, Selection, SelectionGoal, File, IndentKind, IndentSize, Language, LanguageServerName, OffsetRangeExt, OffsetUtf16, Point,
TransactionId, Selection, SelectionGoal, TransactionId,
}; };
use link_go_to_definition::{ use link_go_to_definition::{
hide_link_definition, show_link_definition, GoToDefinitionLink, InlayHighlight, hide_link_definition, show_link_definition, GoToDefinitionLink, InlayHighlight,
@@ -1075,21 +1075,37 @@ impl CompletionsMenu {
}) })
.map(|(ix, _)| ix); .map(|(ix, _)| ix);
let project = editor.project.clone();
let completions = self.completions.clone(); let completions = self.completions.clone();
let matches = self.matches.clone(); let matches = self.matches.clone();
let selected_item = self.selected_item; let selected_item = self.selected_item;
let alongside_docs_width = style.autocomplete.alongside_docs_width;
let alongside_docs_container_style = style.autocomplete.alongside_docs_container;
let outer_container_style = style.autocomplete.container;
let list = UniformList::new(self.list.clone(), matches.len(), cx, { let list = UniformList::new(self.list.clone(), matches.len(), cx, {
let style = style.clone(); let style = style.clone();
move |_, range, items, cx| { move |_, range, items, cx| {
let start_ix = range.start; let start_ix = range.start;
let completions = completions.read(); let mut completions = completions.write();
for (ix, mat) in matches[range].iter().enumerate() { for (ix, mat) in matches[range].iter().enumerate() {
let completion = &completions[mat.candidate_id]; let completion = &mut completions[mat.candidate_id];
if completion.documentation.is_none() {
if let Some(lsp_docs) = &completion.lsp_completion.documentation {
let project = project
.as_ref()
.expect("It is impossible have LSP servers without a project");
let language_registry = project.read(cx).languages();
completion.documentation = prepare_completion_documentation(
lsp_docs,
language_registry,
None,
&style.theme,
);
}
}
let documentation = &completion.documentation; let documentation = &completion.documentation;
let item_ix = start_ix + ix; let item_ix = start_ix + ix;
@@ -1121,9 +1137,7 @@ impl CompletionsMenu {
), ),
); );
if let Some(language::Documentation::SingleLine(text)) = if let Some(Documentation::SingleLine(text)) = documentation {
documentation
{
Flex::row() Flex::row()
.with_child(completion_label) .with_child(completion_label)
.with_children((|| { .with_children((|| {
@@ -1209,11 +1223,11 @@ impl CompletionsMenu {
let documentation = &completion.documentation; let documentation = &completion.documentation;
match documentation { match documentation {
Some(language::Documentation::MultiLinePlainText(text)) => { Some(Documentation::MultiLinePlainText(text)) => {
Some(Text::new(text.clone(), style.text.clone())) Some(Text::new(text.clone(), style.text.clone()))
} }
Some(language::Documentation::MultiLineMarkdown(parsed)) => { Some(Documentation::MultiLineMarkdown(parsed)) => {
Some(render_parsed_markdown(parsed, &style, cx)) Some(render_parsed_markdown(parsed, &style, cx))
} }
@@ -1221,7 +1235,7 @@ impl CompletionsMenu {
} }
}) })
.contained() .contained()
.with_style(outer_container_style) .with_style(style.autocomplete.container)
.into_any() .into_any()
} }