Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into editor2-autocomplete

Antonio Scandurraf2c63781f961
diff --cc crates/editor2/src/editor.rs
index 1e8714cc657,fa7bfd77cc0..3801b965c2a
--- a/crates/editor2/src/editor.rs
+++ b/crates/editor2/src/editor.rs
@@@ -1223,196 -1223,208 +1223,199 @@@ impl CompletionsMenu
style: &EditorStyle,
workspace: Option<WeakView<Workspace>>,
cx: &mut ViewContext<Editor>,
- ) -> AnyElement<Editor> {
- // enum CompletionTag {}
-
+ ) -> AnyElement {
- todo!("old implementation below")
- }
+ let settings = EditorSettings::get_global(cx);
+ let show_completion_documentation = settings.show_completion_documentation;
- // enum CompletionTag {}
+ let widest_completion_ix = self
+ .matches
+ .iter()
+ .enumerate()
+ .max_by_key(|(_, mat)| {
+ let completions = self.completions.read();
+ let completion = &completions[mat.candidate_id];
+ let documentation = &completion.documentation;
+
+ let mut len = completion.label.text.chars().count();
+ if let Some(Documentation::SingleLine(text)) = documentation {
+ if show_completion_documentation {
+ len += text.chars().count();
+ }
+ }
- // let settings = EditorSettings>(cx);
- // let show_completion_documentation = settings.show_completion_documentation;
+ len
+ })
+ .map(|(ix, _)| ix);
- // let widest_completion_ix = self
- // .matches
- // .iter()
- // .enumerate()
- // .max_by_key(|(_, mat)| {
- // let completions = self.completions.read();
- // let completion = &completions[mat.candidate_id];
- // let documentation = &completion.documentation;
+ let completions = self.completions.clone();
+ let matches = self.matches.clone();
+ let selected_item = self.selected_item;
- let list = uniform_list("completions", matches.len(), move |editor, range, cx| {
- let start_ix = range.start;
- let completions_guard = completions.read();
- // let mut len = completion.label.text.chars().count();
- // if let Some(Documentation::SingleLine(text)) = documentation {
- // if show_completion_documentation {
- // len += text.chars().count();
- // }
- // }
++ let list = uniform_list(
++ cx.view().clone(),
++ "completions",
++ matches.len(),
++ move |editor, range, cx| {
++ let start_ix = range.start;
++ let completions_guard = completions.read();
- matches[range]
- .iter()
- .enumerate()
- .map(|(ix, mat)| {
- let item_ix = start_ix + ix;
- let candidate_id = mat.candidate_id;
- let completion = &completions_guard[candidate_id];
- // len
- // })
- // .map(|(ix, _)| ix);
++ matches[range]
++ .iter()
++ .enumerate()
++ .map(|(ix, mat)| {
++ let item_ix = start_ix + ix;
++ let candidate_id = mat.candidate_id;
++ let completion = &completions_guard[candidate_id];
- let documentation = if show_completion_documentation {
- &completion.documentation
- } else {
- &None
- };
- // let completions = self.completions.clone();
- // let matches = self.matches.clone();
- // let selected_item = self.selected_item;
-
- // let list = UniformList::new(self.list.clone(), matches.len(), cx, {
- // let style = style.clone();
- // move |_, range, items, cx| {
- // let start_ix = range.start;
- // let completions_guard = completions.read();
-
- // for (ix, mat) in matches[range].iter().enumerate() {
- // let item_ix = start_ix + ix;
- // let candidate_id = mat.candidate_id;
- // let completion = &completions_guard[candidate_id];
-
- // let documentation = if show_completion_documentation {
- // &completion.documentation
- // } else {
- // &None
- // };
++ let documentation = if show_completion_documentation {
++ &completion.documentation
++ } else {
++ &None
++ };
- // todo!("highlights")
- // let highlights = combine_syntax_and_fuzzy_match_highlights(
- // &completion.label.text,
- // style.text.color.into(),
- // styled_runs_for_code_label(&completion.label, &style.syntax),
- // &mat.positions,
- // )
- // items.push(
- // MouseEventHandler::new::<CompletionTag, _>(
- // mat.candidate_id,
- // cx,
- // |state, _| {
- // let item_style = if item_ix == selected_item {
- // style.autocomplete.selected_item
- // } else if state.hovered() {
- // style.autocomplete.hovered_item
- // } else {
- // style.autocomplete.item
- // };
--
- // todo!("documentation")
- // MouseEventHandler::new::<CompletionTag, _>(mat.candidate_id, cx, |state, _| {
- // let completion_label = HighlightedLabel::new(
- // completion.label.text.clone(),
- // combine_syntax_and_fuzzy_match_highlights(
- // &completion.label.text,
- // style.text.color.into(),
- // styled_runs_for_code_label(&completion.label, &style.syntax),
- // &mat.positions,
- // ),
- // );
- // Text::new(completion.label.text.clone(), style.text.clone())
- // .with_soft_wrap(false)
- // .with_highlights();
- // let completion_label =
- // Text::new(completion.label.text.clone(), style.text.clone())
- // .with_soft_wrap(false)
- // .with_highlights(
- // combine_syntax_and_fuzzy_match_highlights(
- // &completion.label.text,
- // style.text.color.into(),
- // styled_runs_for_code_label(
- // &completion.label,
- // &style.syntax,
- // ),
- // &mat.positions,
- // ),
- // );
--
- // if let Some(Documentation::SingleLine(text)) = documentation {
- // h_stack()
- // .child(completion_label)
- // .with_children((|| {
- // let text_style = TextStyle {
- // color: style.autocomplete.inline_docs_color,
- // font_size: style.text.font_size
- // * style.autocomplete.inline_docs_size_percent,
- // ..style.text.clone()
- // };
- // if let Some(Documentation::SingleLine(text)) = documentation {
- // Flex::row()
- // .with_child(completion_label)
- // .with_children((|| {
- // let text_style = TextStyle {
- // color: style.autocomplete.inline_docs_color,
- // font_size: style.text.font_size
- // * style.autocomplete.inline_docs_size_percent,
- // ..style.text.clone()
- // };
--
- // let label = Text::new(text.clone(), text_style)
- // .aligned()
- // .constrained()
- // .dynamically(move |constraint, _, _| gpui::SizeConstraint {
- // min: constraint.min,
- // max: vec2f(constraint.max.x(), constraint.min.y()),
- // });
- // let label = Text::new(text.clone(), text_style)
- // .aligned()
- // .constrained()
- // .dynamically(move |constraint, _, _| {
- // gpui::SizeConstraint {
- // min: constraint.min,
- // max: vec2f(
- // constraint.max.x(),
- // constraint.min.y(),
- // ),
- // }
- // });
--
- // if Some(item_ix) == widest_completion_ix {
- // Some(
- // label
- // .contained()
- // .with_style(style.autocomplete.inline_docs_container)
- // .into_any(),
- // )
- // } else {
- // Some(label.flex_float().into_any())
- // }
- // })())
- // .into_any()
- // } else {
- // completion_label.into_any()
- // }
- // .contained()
- // .with_style(item_style)
- // .constrained()
- // .dynamically(move |constraint, _, _| {
- // if Some(item_ix) == widest_completion_ix {
- // constraint
- // } else {
- // gpui::SizeConstraint {
- // min: constraint.min,
- // max: constraint.min,
- // }
- // }
- // })
- // })
- // .with_cursor_style(CursorStyle::PointingHand)
- // .on_down(MouseButton::Left, move |_, this, cx| {
- // this.confirm_completion(
- // &ConfirmCompletion {
- // item_ix: Some(item_ix),
- // },
- // cx,
- // )
- // .map(|task| task.detach());
- // })
- // .constrained()
- //
- div()
- .id(mat.candidate_id)
- .bg(gpui::green())
- .hover(|style| style.bg(gpui::blue()))
- .when(item_ix == selected_item, |div| div.bg(gpui::blue()))
- .child(completion.label.text.clone())
- .min_w(px(300.))
- .max_w(px(700.))
- })
- .collect()
- })
- // if Some(item_ix) == widest_completion_ix {
- // Some(
- // label
- // .contained()
- // .with_style(
- // style
- // .autocomplete
- // .inline_docs_container,
- // )
- // .into_any(),
- // )
- // } else {
- // Some(label.flex_float().into_any())
- // }
- // })())
- // .into_any()
- // } else {
- // completion_label.into_any()
- // }
- // .contained()
- // .with_style(item_style)
- // .constrained()
- // .dynamically(
- // move |constraint, _, _| {
- // if Some(item_ix) == widest_completion_ix {
- // constraint
- // } else {
- // gpui::SizeConstraint {
- // min: constraint.min,
- // max: constraint.min,
- // }
- // }
- // },
- // )
- // },
- // )
- // .with_cursor_style(CursorStyle::PointingHand)
- // .on_down(MouseButton::Left, move |_, this, cx| {
- // this.confirm_completion(
- // &ConfirmCompletion {
- // item_ix: Some(item_ix),
- // },
- // cx,
- // )
- // .map(|task| task.detach());
- // })
- // .constrained()
- // .with_min_width(style.autocomplete.completion_min_width)
- // .with_max_width(style.autocomplete.completion_max_width)
- // .into_any(),
- // );
- // }
- // }
- // })
- // .with_width_from_item(widest_completion_ix);
-
- // enum MultiLineDocumentation {}
-
- // Flex::row()
- // .with_child(list.flex(1., false))
- // .with_children({
- // let mat = &self.matches[selected_item];
- // let completions = self.completions.read();
- // let completion = &completions[mat.candidate_id];
- // let documentation = &completion.documentation;
-
- // match documentation {
- // Some(Documentation::MultiLinePlainText(text)) => Some(
- // Flex::column()
- // .scrollable::<MultiLineDocumentation>(0, None, cx)
- // .with_child(
- // Text::new(text.clone(), style.text.clone()).with_soft_wrap(true),
- // )
- // .contained()
- // .with_style(style.autocomplete.alongside_docs_container)
- // .constrained()
- // .with_max_width(style.autocomplete.alongside_docs_max_width)
- // .flex(1., false),
- // ),
-
- // Some(Documentation::MultiLineMarkdown(parsed)) => Some(
- // Flex::column()
- // .scrollable::<MultiLineDocumentation>(0, None, cx)
- // .with_child(render_parsed_markdown::<MultiLineDocumentation>(
- // parsed, &style, workspace, cx,
- // ))
- // .contained()
- // .with_style(style.autocomplete.alongside_docs_container)
- // .constrained()
- // .with_max_width(style.autocomplete.alongside_docs_max_width)
- // .flex(1., false),
- // ),
-
- // _ => None,
- // }
- // })
- // .contained()
- // .with_style(style.autocomplete.container)
- // .into_any()
- // }
++ // todo!("highlights")
++ // let highlights = combine_syntax_and_fuzzy_match_highlights(
++ // &completion.label.text,
++ // style.text.color.into(),
++ // styled_runs_for_code_label(&completion.label, &style.syntax),
++ // &mat.positions,
++ // )
++
++ // todo!("documentation")
++ // MouseEventHandler::new::<CompletionTag, _>(mat.candidate_id, cx, |state, _| {
++ // let completion_label = HighlightedLabel::new(
++ // completion.label.text.clone(),
++ // combine_syntax_and_fuzzy_match_highlights(
++ // &completion.label.text,
++ // style.text.color.into(),
++ // styled_runs_for_code_label(&completion.label, &style.syntax),
++ // &mat.positions,
++ // ),
++ // );
++ // Text::new(completion.label.text.clone(), style.text.clone())
++ // .with_soft_wrap(false)
++ // .with_highlights();
++
++ // if let Some(Documentation::SingleLine(text)) = documentation {
++ // h_stack()
++ // .child(completion_label)
++ // .with_children((|| {
++ // let text_style = TextStyle {
++ // color: style.autocomplete.inline_docs_color,
++ // font_size: style.text.font_size
++ // * style.autocomplete.inline_docs_size_percent,
++ // ..style.text.clone()
++ // };
++
++ // let label = Text::new(text.clone(), text_style)
++ // .aligned()
++ // .constrained()
++ // .dynamically(move |constraint, _, _| gpui::SizeConstraint {
++ // min: constraint.min,
++ // max: vec2f(constraint.max.x(), constraint.min.y()),
++ // });
++
++ // if Some(item_ix) == widest_completion_ix {
++ // Some(
++ // label
++ // .contained()
++ // .with_style(style.autocomplete.inline_docs_container)
++ // .into_any(),
++ // )
++ // } else {
++ // Some(label.flex_float().into_any())
++ // }
++ // })())
++ // .into_any()
++ // } else {
++ // completion_label.into_any()
++ // }
++ // .contained()
++ // .with_style(item_style)
++ // .constrained()
++ // .dynamically(move |constraint, _, _| {
++ // if Some(item_ix) == widest_completion_ix {
++ // constraint
++ // } else {
++ // gpui::SizeConstraint {
++ // min: constraint.min,
++ // max: constraint.min,
++ // }
++ // }
++ // })
++ // })
++ // .with_cursor_style(CursorStyle::PointingHand)
++ // .on_down(MouseButton::Left, move |_, this, cx| {
++ // this.confirm_completion(
++ // &ConfirmCompletion {
++ // item_ix: Some(item_ix),
++ // },
++ // cx,
++ // )
++ // .map(|task| task.detach());
++ // })
++ // .constrained()
++ //
++ div()
++ .id(mat.candidate_id)
++ .bg(gpui::green())
++ .hover(|style| style.bg(gpui::blue()))
++ .when(item_ix == selected_item, |div| div.bg(gpui::blue()))
++ .child(SharedString::from(completion.label.text.clone()))
++ .min_w(px(300.))
++ .max_w(px(700.))
++ })
++ .collect()
++ },
++ )
+ .with_width_from_item(widest_completion_ix);
+
- list.render()
++ list.render_into_any()
+ // todo!("multiline documentation")
+ // enum MultiLineDocumentation {}
+
+ // Flex::row()
+ // .with_child(list.flex(1., false))
+ // .with_children({
+ // let mat = &self.matches[selected_item];
+ // let completions = self.completions.read();
+ // let completion = &completions[mat.candidate_id];
+ // let documentation = &completion.documentation;
+
+ // match documentation {
+ // Some(Documentation::MultiLinePlainText(text)) => Some(
+ // Flex::column()
+ // .scrollable::<MultiLineDocumentation>(0, None, cx)
+ // .with_child(
+ // Text::new(text.clone(), style.text.clone()).with_soft_wrap(true),
+ // )
+ // .contained()
+ // .with_style(style.autocomplete.alongside_docs_container)
+ // .constrained()
+ // .with_max_width(style.autocomplete.alongside_docs_max_width)
+ // .flex(1., false),
+ // ),
+
+ // Some(Documentation::MultiLineMarkdown(parsed)) => Some(
+ // Flex::column()
+ // .scrollable::<MultiLineDocumentation>(0, None, cx)
+ // .with_child(render_parsed_markdown::<MultiLineDocumentation>(
+ // parsed, &style, workspace, cx,
+ // ))
+ // .contained()
+ // .with_style(style.autocomplete.alongside_docs_container)
+ // .constrained()
+ // .with_max_width(style.autocomplete.alongside_docs_max_width)
+ // .flex(1., false),
+ // ),
+
+ // _ => None,
+ // }
+ // })
+ // .contained()
+ // .with_style(style.autocomplete.container)
+ // .into_any()
+ }
pub async fn filter(&mut self, query: Option<&str>, executor: BackgroundExecutor) {
let mut matches = if let Some(query) = query {