mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 12:53:10 +02:00
Fix conflict resolution
This commit is contained in:
@ -147,7 +147,7 @@ impl Completer for CommandCompletion {
|
|||||||
&mut self,
|
&mut self,
|
||||||
working_set: &StateWorkingSet,
|
working_set: &StateWorkingSet,
|
||||||
_stack: &Stack,
|
_stack: &Stack,
|
||||||
prefix: &[u8],
|
_prefix: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use super::{completion_options::NuMatcher, MatchAlgorithm};
|
use super::{completion_options::NuMatcher, MatchAlgorithm};
|
||||||
use crate::{
|
use crate::completions::CompletionOptions;
|
||||||
completions::{matches, CompletionOptions},
|
|
||||||
SemanticSuggestion,
|
|
||||||
};
|
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
use nu_engine::env_to_string;
|
use nu_engine::env_to_string;
|
||||||
use nu_path::dots::expand_ndots;
|
use nu_path::dots::expand_ndots;
|
||||||
@ -165,7 +162,7 @@ pub struct FileSuggestion {
|
|||||||
|
|
||||||
/// # Parameters
|
/// # Parameters
|
||||||
/// * `cwds` - A list of directories in which to search. The only reason this isn't a single string
|
/// * `cwds` - A list of directories in which to search. The only reason this isn't a single string
|
||||||
/// is because dotnu_completions searches in multiple directories at once
|
/// is because dotnu_completions searches in multiple directories at once
|
||||||
pub fn complete_item(
|
pub fn complete_item(
|
||||||
want_directory: bool,
|
want_directory: bool,
|
||||||
span: nu_protocol::Span,
|
span: nu_protocol::Span,
|
||||||
@ -264,6 +261,7 @@ pub fn complete_item(
|
|||||||
if should_collapse_dots {
|
if should_collapse_dots {
|
||||||
p = collapse_ndots(p);
|
p = collapse_ndots(p);
|
||||||
}
|
}
|
||||||
|
let cwd = p.cwd.clone();
|
||||||
let path = original_cwd.apply(p, path_separator);
|
let path = original_cwd.apply(p, path_separator);
|
||||||
let style = ls_colors.as_ref().map(|lsc| {
|
let style = ls_colors.as_ref().map(|lsc| {
|
||||||
lsc.style_for_path_with_metadata(
|
lsc.style_for_path_with_metadata(
|
||||||
@ -344,3 +342,38 @@ pub fn adjust_if_intermediate(
|
|||||||
readjusted,
|
readjusted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Collapse multiple ".." components into n-dots.
|
||||||
|
///
|
||||||
|
/// It performs the reverse operation of `expand_ndots`, collapsing sequences of ".." into n-dots,
|
||||||
|
/// such as "..." and "....".
|
||||||
|
///
|
||||||
|
/// The resulting path will use platform-specific path separators, regardless of what path separators were used in the input.
|
||||||
|
fn collapse_ndots(path: PathBuiltFromString) -> PathBuiltFromString {
|
||||||
|
let mut result = PathBuiltFromString {
|
||||||
|
parts: Vec::with_capacity(path.parts.len()),
|
||||||
|
isdir: path.isdir,
|
||||||
|
cwd: path.cwd,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut dot_count = 0;
|
||||||
|
|
||||||
|
for part in path.parts {
|
||||||
|
if part == ".." {
|
||||||
|
dot_count += 1;
|
||||||
|
} else {
|
||||||
|
if dot_count > 0 {
|
||||||
|
result.parts.push(".".repeat(dot_count + 1));
|
||||||
|
dot_count = 0;
|
||||||
|
}
|
||||||
|
result.parts.push(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any remaining dots
|
||||||
|
if dot_count > 0 {
|
||||||
|
result.parts.push(".".repeat(dot_count + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
@ -123,7 +123,7 @@ impl Completer for CustomCompletion {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let options = custom_completion_options.unwrap_or(completion_options.clone());
|
let options = custom_completion_options.unwrap_or(completion_options.clone());
|
||||||
let mut matcher = NuMatcher::new(String::from_utf8_lossy(&prefix), options);
|
let mut matcher = NuMatcher::new(String::from_utf8_lossy(prefix), options);
|
||||||
for sugg in suggestions {
|
for sugg in suggestions {
|
||||||
matcher.add_semantic_suggestion(sugg);
|
matcher.add_semantic_suggestion(sugg);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ impl Completer for FlagCompletion {
|
|||||||
let decl = working_set.get_decl(call.decl_id);
|
let decl = working_set.get_decl(call.decl_id);
|
||||||
let sig = decl.signature();
|
let sig = decl.signature();
|
||||||
|
|
||||||
let mut matcher = NuMatcher::new(String::from_utf8_lossy(&prefix), options.clone());
|
let mut matcher = NuMatcher::new(String::from_utf8_lossy(prefix), options.clone());
|
||||||
|
|
||||||
for named in &sig.named {
|
for named in &sig.named {
|
||||||
let flag_desc = &named.desc;
|
let flag_desc = &named.desc;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::completions::{
|
use crate::completions::{
|
||||||
Completer, CompletionOptions, MatchAlgorithm, SemanticSuggestion, SuggestionKind,
|
completion_options::NuMatcher, Completer, CompletionOptions, SemanticSuggestion, SuggestionKind,
|
||||||
};
|
};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Expr, Expression},
|
ast::{Expr, Expression},
|
||||||
@ -28,7 +28,7 @@ impl Completer for OperatorCompletion {
|
|||||||
span: Span,
|
span: Span,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
_pos: usize,
|
_pos: usize,
|
||||||
_options: &CompletionOptions,
|
options: &CompletionOptions,
|
||||||
) -> Vec<SemanticSuggestion> {
|
) -> Vec<SemanticSuggestion> {
|
||||||
//Check if int, float, or string
|
//Check if int, float, or string
|
||||||
let partial = std::str::from_utf8(working_set.get_span_contents(span)).unwrap_or("");
|
let partial = std::str::from_utf8(working_set.get_span_contents(span)).unwrap_or("");
|
||||||
@ -129,17 +129,12 @@ impl Completer for OperatorCompletion {
|
|||||||
_ => vec![],
|
_ => vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let match_algorithm = MatchAlgorithm::Prefix;
|
let mut matcher = NuMatcher::new(partial, options.clone());
|
||||||
let input_fuzzy_search =
|
for (symbol, desc) in possible_operations.into_iter() {
|
||||||
|(operator, _): &(&str, &str)| match_algorithm.matches_str(operator, partial);
|
matcher.add_semantic_suggestion(SemanticSuggestion {
|
||||||
|
|
||||||
possible_operations
|
|
||||||
.into_iter()
|
|
||||||
.filter(input_fuzzy_search)
|
|
||||||
.map(move |x| SemanticSuggestion {
|
|
||||||
suggestion: Suggestion {
|
suggestion: Suggestion {
|
||||||
value: x.0.to_string(),
|
value: symbol.to_string(),
|
||||||
description: Some(x.1.to_string()),
|
description: Some(desc.to_string()),
|
||||||
span: reedline::Span::new(span.start - offset, span.end - offset),
|
span: reedline::Span::new(span.start - offset, span.end - offset),
|
||||||
append_whitespace: true,
|
append_whitespace: true,
|
||||||
..Suggestion::default()
|
..Suggestion::default()
|
||||||
@ -147,8 +142,9 @@ impl Completer for OperatorCompletion {
|
|||||||
kind: Some(SuggestionKind::Command(
|
kind: Some(SuggestionKind::Command(
|
||||||
nu_protocol::engine::CommandType::Builtin,
|
nu_protocol::engine::CommandType::Builtin,
|
||||||
)),
|
)),
|
||||||
})
|
});
|
||||||
.collect()
|
}
|
||||||
|
matcher.results()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user