nu_cli/completions/
base.rs1use crate::completions::CompletionOptions;
2use nu_protocol::{
3 DynamicSuggestion, Span, SuggestionKind,
4 engine::{Stack, StateWorkingSet},
5};
6use reedline::Suggestion;
7
8pub trait Completer {
9 #[allow(clippy::too_many_arguments)]
11 fn fetch(
12 &mut self,
13 working_set: &StateWorkingSet,
14 stack: &Stack,
15 prefix: impl AsRef<str>,
16 span: Span,
17 offset: usize,
18 options: &CompletionOptions,
19 ) -> Vec<SemanticSuggestion>;
20}
21
22#[derive(Debug, Default, PartialEq)]
23pub struct SemanticSuggestion {
24 pub suggestion: Suggestion,
25 pub kind: Option<SuggestionKind>,
26}
27
28impl SemanticSuggestion {
29 pub fn from_dynamic_suggestion(
30 suggestion: DynamicSuggestion,
31 span: reedline::Span,
32 style: Option<nu_ansi_term::Style>,
33 ) -> Self {
34 SemanticSuggestion {
35 suggestion: Suggestion {
36 value: suggestion.value,
37 description: suggestion.description,
38 extra: suggestion.extra,
39 append_whitespace: suggestion.append_whitespace,
40 match_indices: suggestion.match_indices,
41 style,
42 span,
43 },
44 kind: suggestion.kind,
45 }
46 }
47}
48
49impl From<Suggestion> for SemanticSuggestion {
50 fn from(suggestion: Suggestion) -> Self {
51 Self {
52 suggestion,
53 ..Default::default()
54 }
55 }
56}