History

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

Julia committed 3 years ago

Commit ea6f3661 parent b8876f21 file · +30 −16Browse files

Unified · Split

crates/editor/src/editor.rs+30−16
@@ -60,10 +60,10 @@ use itertools::Itertools; · 59 unmodified lines
6060 pub use language::{char_kind, CharKind};
6161 use language::{
6262 language_settings::{self, all_language_settings, InlayHintSettings},
63− point_from_lsp, AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion,
64− CursorShape, Diagnostic, DiagnosticSeverity, File, IndentKind, IndentSize, Language,
65− LanguageServerName, OffsetRangeExt, OffsetUtf16, Point, Selection, SelectionGoal,
66− TransactionId,
63+ point_from_lsp, prepare_completion_documentation, AutoindentMode, BracketPair, Buffer,
64+ CodeAction, CodeLabel, Completion, CursorShape, Diagnostic, DiagnosticSeverity, Documentation,
65+ File, IndentKind, IndentSize, Language, LanguageServerName, OffsetRangeExt, OffsetUtf16, Point,
66+ Selection, SelectionGoal, TransactionId,
6767 };
6868 use link_go_to_definition::{
6969 hide_link_definition, show_link_definition, GoToDefinitionLink, InlayHighlight,
@@ -1075,21 +1075,37 @@ impl CompletionsMenu { · 1005 unmodified lines
10751075 })
10761076 .map(|(ix, _)| ix);
10771077
1078+ let project = editor.project.clone();
10781079 let completions = self.completions.clone();
10791080 let matches = self.matches.clone();
10801081 let selected_item = self.selected_item;
10811082
1082− let alongside_docs_width = style.autocomplete.alongside_docs_width;
1083− let alongside_docs_container_style = style.autocomplete.alongside_docs_container;
1084− let outer_container_style = style.autocomplete.container;
1085−
10861083 let list = UniformList::new(self.list.clone(), matches.len(), cx, {
10871084 let style = style.clone();
10881085 move |_, range, items, cx| {
10891086 let start_ix = range.start;
1090− let completions = completions.read();
1087+ let mut completions = completions.write();
1088+
10911089 for (ix, mat) in matches[range].iter().enumerate() {
1092− let completion = &completions[mat.candidate_id];
1090+ let completion = &mut completions[mat.candidate_id];
1091+
1092+ if completion.documentation.is_none() {
1093+ if let Some(lsp_docs) = &completion.lsp_completion.documentation {
1094+ let project = project
1095+ .as_ref()
1096+ .expect("It is impossible have LSP servers without a project");
1097+
1098+ let language_registry = project.read(cx).languages();
1099+
1100+ completion.documentation = prepare_completion_documentation(
1101+ lsp_docs,
1102+ language_registry,
1103+ None,
1104+ &style.theme,
1105+ );
1106+ }
1107+ }
1108+
10931109 let documentation = &completion.documentation;
10941110 let item_ix = start_ix + ix;
10951111
@@ -1121,9 +1137,7 @@ impl CompletionsMenu { · 25 unmodified lines
11211137 ),
11221138 );
11231139
1124− if let Some(language::Documentation::SingleLine(text)) =
1125− documentation
1126− {
1140+ if let Some(Documentation::SingleLine(text)) = documentation {
11271141 Flex::row()
11281142 .with_child(completion_label)
11291143 .with_children((|| {
@@ -1209,11 +1223,11 @@ impl CompletionsMenu { · 79 unmodified lines
12091223 let documentation = &completion.documentation;
12101224
12111225 match documentation {
1212− Some(language::Documentation::MultiLinePlainText(text)) => {
1226+ Some(Documentation::MultiLinePlainText(text)) => {
12131227 Some(Text::new(text.clone(), style.text.clone()))
12141228 }
12151229
1216− Some(language::Documentation::MultiLineMarkdown(parsed)) => {
1230+ Some(Documentation::MultiLineMarkdown(parsed)) => {
12171231 Some(render_parsed_markdown(parsed, &style, cx))
12181232 }
12191233
@@ -1221,7 +1235,7 @@ impl CompletionsMenu { · 1 unmodified line
12211235 }
12221236 })
12231237 .contained()
1224− .with_style(outer_container_style)
1238+ .with_style(style.autocomplete.container)
12251239 .into_any()
12261240 }
12271241

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t