Skip to content

Commit 88d2e4f

Browse files
committed
helix-view/term: path completion item kinds
1 parent 75d0989 commit 88d2e4f

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

helix-term/src/ui/completion.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,27 @@ impl menu::Item for CompletionItem {
125125
}
126126
}
127127
CompletionItem::Other(core::CompletionItem { kind, .. }) => {
128-
if let Some(kind_style) = data.completion_item_kinds.get(kind.as_ref()) {
128+
let kind = match kind.as_ref() {
129+
// This is for path completion source.
130+
// Got this from helix-term/src/handlers/completion/path.rs
131+
// On unix these are all just **file** descriptors
132+
#[cfg(unix)]
133+
"block" | "socket" | "char_device" | "fifo" => "file",
134+
135+
// NOTE: Whenever you add a new completion source, you may want to add overrides
136+
// here if you wish to.
137+
x => x, // otherwise keep untouched.
138+
};
139+
140+
if let Some(kind_style) = data.completion_item_kinds.get(kind) {
129141
let style = kind_style.style.unwrap_or(data.default_style);
130142
if let Some(text) = kind_style.text.as_ref() {
131143
menu::Cell::from(Span::styled(text.clone(), style))
132144
} else {
133-
menu::Cell::from(Span::styled(kind.as_ref(), style))
145+
menu::Cell::from(Span::styled(kind, style))
134146
}
135147
} else {
136-
menu::Cell::from(Span::styled(kind.as_ref(), data.default_style))
148+
menu::Cell::from(Span::styled(kind, data.default_style))
137149
}
138150
}
139151
};

helix-view/src/editor.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,41 +2240,28 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
22402240
}
22412241
}
22422242

2243+
// NOTE: When you implement a new completion source/handler, dont forget to add
2244+
// your completion kinds here!
2245+
#[rustfmt::skip]
2246+
const ALL_KINDS: &[&str] = &[
2247+
// All of these are LSP item kinds.
2248+
// It happens that file and folder are also here.
2249+
"text", "method", "function", "constructor", "field", "variable",
2250+
"class", "interface", "module", "property", "unit", "value", "enum",
2251+
"keyword", "snippet", "color", "file", "reference", "folder",
2252+
"enum-member", "constant", "struct", "event", "operator",
2253+
"type-parameter",
2254+
// The following are specific to path completion source
2255+
// We ignore the other linux-specific ones (block, socket, etc...)
2256+
"link"
2257+
];
2258+
22432259
fn compute_completion_item_kind_styles(
22442260
theme: &Theme,
22452261
config: &DynGuard<Config>,
22462262
) -> HashMap<&'static str, CompletionItemKindStyle> {
22472263
let mut ret = HashMap::new();
2248-
// We populate with LSP kinds and additionally file+folder for path completion
2249-
for name in [
2250-
"text",
2251-
"method",
2252-
"function",
2253-
"constructor",
2254-
"field",
2255-
"variable",
2256-
"class",
2257-
"interface",
2258-
"module",
2259-
"property",
2260-
"unit",
2261-
"value",
2262-
"enum",
2263-
"keyword",
2264-
"snippet",
2265-
"color",
2266-
"file",
2267-
"reference",
2268-
"folder",
2269-
"enum-member",
2270-
"constant",
2271-
"struct",
2272-
"event",
2273-
"operator",
2274-
"type-parameter",
2275-
"file",
2276-
"folder",
2277-
] {
2264+
for &name in ALL_KINDS {
22782265
let style = theme.try_get(&format!("ui.completion.kind.{name}"));
22792266
let text = config.completion_item_kinds.get(name).cloned();
22802267
if style.is_some() || text.is_some() {

0 commit comments

Comments
 (0)