Syntax highlight completions
This commit is contained in:
parent
bf39968105
commit
54357d6553
2 changed files with 15 additions and 12 deletions
|
@ -43,8 +43,8 @@ use gpui::{
|
||||||
AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Context,
|
AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Context,
|
||||||
EventEmitter, FocusHandle, FocusableView, FontFeatures, FontStyle, FontWeight, HighlightStyle,
|
EventEmitter, FocusHandle, FocusableView, FontFeatures, FontStyle, FontWeight, HighlightStyle,
|
||||||
Hsla, InputHandler, KeyContext, Model, MouseButton, ParentElement, Pixels, Render, RenderOnce,
|
Hsla, InputHandler, KeyContext, Model, MouseButton, ParentElement, Pixels, Render, RenderOnce,
|
||||||
SharedString, Styled, Subscription, Task, TextRun, TextStyle, UniformListScrollHandle, View,
|
SharedString, Styled, StyledText, Subscription, Task, TextRun, TextStyle,
|
||||||
ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
|
UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
|
||||||
};
|
};
|
||||||
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
||||||
use hover_popover::{hide_hover, HoverState};
|
use hover_popover::{hide_hover, HoverState};
|
||||||
|
@ -1251,6 +1251,7 @@ impl CompletionsMenu {
|
||||||
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 style = style.clone();
|
||||||
|
|
||||||
let list = uniform_list(
|
let list = uniform_list(
|
||||||
cx.view().clone(),
|
cx.view().clone(),
|
||||||
|
@ -1274,13 +1275,12 @@ impl CompletionsMenu {
|
||||||
&None
|
&None
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo!("highlights")
|
let completion_runs = combine_syntax_and_fuzzy_match_highlights(
|
||||||
// let highlights = combine_syntax_and_fuzzy_match_highlights(
|
&completion.label.text,
|
||||||
// &completion.label.text,
|
&style.text,
|
||||||
// style.text.color.into(),
|
styled_runs_for_code_label(&completion.label, &style.syntax),
|
||||||
// styled_runs_for_code_label(&completion.label, &style.syntax),
|
&mat.positions,
|
||||||
// &mat.positions,
|
);
|
||||||
// )
|
|
||||||
|
|
||||||
// todo!("documentation")
|
// todo!("documentation")
|
||||||
// MouseEventHandler::new::<CompletionTag, _>(mat.candidate_id, cx, |state, _| {
|
// MouseEventHandler::new::<CompletionTag, _>(mat.candidate_id, cx, |state, _| {
|
||||||
|
@ -1364,7 +1364,10 @@ impl CompletionsMenu {
|
||||||
.bg(gpui::green())
|
.bg(gpui::green())
|
||||||
.hover(|style| style.bg(gpui::blue()))
|
.hover(|style| style.bg(gpui::blue()))
|
||||||
.when(item_ix == selected_item, |div| div.bg(gpui::red()))
|
.when(item_ix == selected_item, |div| div.bg(gpui::red()))
|
||||||
.child(SharedString::from(completion.label.text.clone()))
|
.child(
|
||||||
|
StyledText::new(completion.label.text.clone())
|
||||||
|
.with_runs(completion_runs),
|
||||||
|
)
|
||||||
.min_w(px(300.))
|
.min_w(px(300.))
|
||||||
.max_w(px(700.))
|
.max_w(px(700.))
|
||||||
})
|
})
|
||||||
|
@ -10080,7 +10083,7 @@ pub fn diagnostic_style(
|
||||||
|
|
||||||
pub fn combine_syntax_and_fuzzy_match_highlights(
|
pub fn combine_syntax_and_fuzzy_match_highlights(
|
||||||
text: &str,
|
text: &str,
|
||||||
default_style: TextStyle,
|
default_style: &TextStyle,
|
||||||
syntax_ranges: impl Iterator<Item = (Range<usize>, HighlightStyle)>,
|
syntax_ranges: impl Iterator<Item = (Range<usize>, HighlightStyle)>,
|
||||||
match_indices: &[usize],
|
match_indices: &[usize],
|
||||||
) -> Vec<TextRun> {
|
) -> Vec<TextRun> {
|
||||||
|
|
|
@ -6770,7 +6770,7 @@ fn test_combine_syntax_and_fuzzy_match_highlights() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
combine_syntax_and_fuzzy_match_highlights(
|
combine_syntax_and_fuzzy_match_highlights(
|
||||||
string,
|
string,
|
||||||
Default::default(),
|
&TextStyle::default(),
|
||||||
syntax_ranges.into_iter(),
|
syntax_ranges.into_iter(),
|
||||||
&match_indices,
|
&match_indices,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue