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

@@ -731,18 +731,19 @@ impl EngineState {
&self,
mut predicate: impl FnMut(&[u8]) -> bool,
ignore_deprecated: bool,
) -> Vec<(Vec<u8>, Option<String>, CommandType)> {
) -> Vec<(DeclId, Vec<u8>, Option<String>, CommandType)> {
let mut output = vec![];
for overlay_frame in self.active_overlays(&[]).rev() {
for decl in &overlay_frame.decls {
if overlay_frame.visibility.is_decl_id_visible(decl.1) && predicate(decl.0) {
let command = self.get_decl(*decl.1);
for (name, decl_id) in &overlay_frame.decls {
if overlay_frame.visibility.is_decl_id_visible(decl_id) && predicate(name) {
let command = self.get_decl(*decl_id);
if ignore_deprecated && command.signature().category == Category::Removed {
continue;
}
output.push((
decl.0.clone(),
*decl_id,
name.clone(),
Some(command.description().to_string()),
command.command_type(),
));

View File

@@ -780,21 +780,22 @@ impl<'a> StateWorkingSet<'a> {
&self,
mut predicate: impl FnMut(&[u8]) -> bool,
ignore_deprecated: bool,
) -> Vec<(Vec<u8>, Option<String>, CommandType)> {
) -> Vec<(DeclId, Vec<u8>, Option<String>, CommandType)> {
let mut output = vec![];
for scope_frame in self.delta.scope.iter().rev() {
for overlay_id in scope_frame.active_overlays.iter().rev() {
let overlay_frame = scope_frame.get_overlay(*overlay_id);
for decl in &overlay_frame.decls {
if overlay_frame.visibility.is_decl_id_visible(decl.1) && predicate(decl.0) {
let command = self.get_decl(*decl.1);
for (name, decl_id) in &overlay_frame.decls {
if overlay_frame.visibility.is_decl_id_visible(decl_id) && predicate(name) {
let command = self.get_decl(*decl_id);
if ignore_deprecated && command.signature().category == Category::Removed {
continue;
}
output.push((
decl.0.clone(),
*decl_id,
name.clone(),
Some(command.description().to_string()),
command.command_type(),
));