forked from extern/nushell
nu-cli: external completer precedence before file (#6652)
This commit is contained in:
parent
5959d1366a
commit
e629ef203a
@ -60,10 +60,10 @@ impl NuCompleter {
|
|||||||
fn external_completion(
|
fn external_completion(
|
||||||
&self,
|
&self,
|
||||||
block_id: BlockId,
|
block_id: BlockId,
|
||||||
spans: Vec<String>,
|
spans: &[String],
|
||||||
offset: usize,
|
offset: usize,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Vec<Suggestion> {
|
) -> Option<Vec<Suggestion>> {
|
||||||
let stack = self.stack.clone();
|
let stack = self.stack.clone();
|
||||||
let block = self.engine_state.get_block(block_id);
|
let block = self.engine_state.get_block(block_id);
|
||||||
let mut callee_stack = stack.gather_captures(&block.captures);
|
let mut callee_stack = stack.gather_captures(&block.captures);
|
||||||
@ -75,9 +75,9 @@ impl NuCompleter {
|
|||||||
var_id,
|
var_id,
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: spans
|
vals: spans
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|it| Value::String {
|
.map(|it| Value::String {
|
||||||
val: it,
|
val: it.to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@ -109,13 +109,13 @@ impl NuCompleter {
|
|||||||
offset,
|
offset,
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return Some(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => println!("failed to eval completer block: {}", err),
|
Err(err) => println!("failed to eval completer block: {}", err),
|
||||||
}
|
}
|
||||||
|
|
||||||
vec![]
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completion_helper(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
|
fn completion_helper(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
|
||||||
@ -213,7 +213,11 @@ impl NuCompleter {
|
|||||||
// We got no results for internal completion
|
// We got no results for internal completion
|
||||||
// now we can check if external completer is set and use it
|
// now we can check if external completer is set and use it
|
||||||
if let Some(block_id) = config.external_completer {
|
if let Some(block_id) = config.external_completer {
|
||||||
return self.external_completion(block_id, spans, offset, new_span);
|
if let Some(external_result) =
|
||||||
|
self.external_completion(block_id, &spans, offset, new_span)
|
||||||
|
{
|
||||||
|
return external_result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,6 +344,15 @@ impl NuCompleter {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to complete using an external completer (if set)
|
||||||
|
if let Some(block_id) = config.external_completer {
|
||||||
|
if let Some(external_result) =
|
||||||
|
self.external_completion(block_id, &spans, offset, new_span)
|
||||||
|
{
|
||||||
|
return external_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for file completion
|
// Check for file completion
|
||||||
let mut completer = FileCompletion::new(self.engine_state.clone());
|
let mut completer = FileCompletion::new(self.engine_state.clone());
|
||||||
out = self.process_completion(
|
out = self.process_completion(
|
||||||
@ -354,12 +367,6 @@ impl NuCompleter {
|
|||||||
if !out.is_empty() {
|
if !out.is_empty() {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to complete using an exnternal compelter (if set)
|
|
||||||
if let Some(block_id) = config.external_completer {
|
|
||||||
return self
|
|
||||||
.external_completion(block_id, spans, offset, new_span);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user