refactor(completion, lsp): include decl_id in suggetion_kind for later usage (#15536)

# Description

Should be more performant, calling for `find_decl` by name for all
entries is generally a heavy op.

# User-Facing Changes

NA

# Tests + Formatting

# After Submitting
This commit is contained in:
zc he
2025-04-15 20:24:56 +08:00
committed by GitHub
parent e5f589ccdd
commit 56d7e4bb89
7 changed files with 27 additions and 27 deletions

View File

@ -27,7 +27,7 @@ impl Completer for AttributeCompletion {
let attr_commands =
working_set.find_commands_by_predicate(|s| s.starts_with(b"attr "), true);
for (name, desc, ty) in attr_commands {
for (decl_id, name, desc, ty) in attr_commands {
let name = name.strip_prefix(b"attr ").unwrap_or(&name);
matcher.add_semantic_suggestion(SemanticSuggestion {
suggestion: Suggestion {
@ -41,7 +41,7 @@ impl Completer for AttributeCompletion {
},
append_whitespace: false,
},
kind: Some(SuggestionKind::Command(ty)),
kind: Some(SuggestionKind::Command(ty, Some(decl_id))),
});
}
@ -78,7 +78,7 @@ impl Completer for AttributableCompletion {
},
append_whitespace: false,
},
kind: Some(SuggestionKind::Command(cmd.command_type())),
kind: Some(SuggestionKind::Command(cmd.command_type(), None)),
});
}

View File

@ -1,7 +1,7 @@
use crate::completions::CompletionOptions;
use nu_protocol::{
engine::{Stack, StateWorkingSet},
Span,
DeclId, Span,
};
use reedline::Suggestion;
@ -28,7 +28,7 @@ pub struct SemanticSuggestion {
// TODO: think about name: maybe suggestion context?
#[derive(Clone, Debug, PartialEq)]
pub enum SuggestionKind {
Command(nu_protocol::engine::CommandType),
Command(nu_protocol::engine::CommandType, Option<DeclId>),
Value(nu_protocol::Type),
CellPath,
Directory,

View File

@ -75,7 +75,10 @@ impl CommandCompletion {
append_whitespace: true,
..Default::default()
},
kind: Some(SuggestionKind::Command(CommandType::External)),
kind: Some(SuggestionKind::Command(
CommandType::External,
None,
)),
},
);
}
@ -112,7 +115,7 @@ impl Completer for CommandCompletion {
},
true,
);
for (name, description, typ) in filtered_commands {
for (decl_id, name, description, typ) in filtered_commands {
let name = String::from_utf8_lossy(&name);
internal_suggs.insert(
name.to_string(),
@ -124,7 +127,7 @@ impl Completer for CommandCompletion {
append_whitespace: true,
..Suggestion::default()
},
kind: Some(SuggestionKind::Command(typ)),
kind: Some(SuggestionKind::Command(typ, Some(decl_id))),
},
);
}

View File

@ -69,7 +69,7 @@ impl Completer for ExportableCompletion<'_> {
wrapped_name(name),
Some(cmd.description().to_string()),
None,
SuggestionKind::Command(cmd.command_type()),
SuggestionKind::Command(cmd.command_type(), Some(*decl_id)),
);
}
}