Send LSP Completion Item Kind (#11443)

# Description

This commit fills in the completion item kind into the
`textDocument/completion` response so that LSP client can present more
information to the user.

It is an improvement in the context of #10794

# User-Facing Changes

Improved information display in editor's intelli-sense menu


![output](https://github.com/nushell/nushell/assets/16558417/991dc0a9-45d1-4718-8f22-29002d687b93)
This commit is contained in:
Marc Schreiber
2024-03-25 02:14:12 +01:00
committed by GitHub
parent d1a8992590
commit e7bdd08a04
16 changed files with 384 additions and 199 deletions

View File

@ -2,7 +2,7 @@ use crate::{ast::Call, Alias, BlockId, Example, IoStream, PipelineData, ShellErr
use super::{EngineState, Stack, StateWorkingSet};
#[derive(Debug)]
#[derive(Clone, Debug, PartialEq)]
pub enum CommandType {
Builtin,
Custom,

View File

@ -4,7 +4,8 @@ use lru::LruCache;
use super::cached_file::CachedFile;
use super::{usage::build_usage, usage::Usage, StateDelta};
use super::{
Command, EnvVars, OverlayFrame, ScopeFrame, Stack, Variable, Visibility, DEFAULT_OVERLAY_NAME,
Command, CommandType, EnvVars, OverlayFrame, ScopeFrame, Stack, Variable, Visibility,
DEFAULT_OVERLAY_NAME,
};
use crate::ast::Block;
use crate::debugger::{Debugger, NoopDebugger};
@ -733,7 +734,7 @@ impl EngineState {
&self,
predicate: impl Fn(&[u8]) -> bool,
ignore_deprecated: bool,
) -> Vec<(Vec<u8>, Option<String>)> {
) -> Vec<(Vec<u8>, Option<String>, CommandType)> {
let mut output = vec![];
for overlay_frame in self.active_overlays(&[]).rev() {
@ -743,7 +744,11 @@ impl EngineState {
if ignore_deprecated && command.signature().category == Category::Removed {
continue;
}
output.push((decl.0.clone(), Some(command.usage().to_string())));
output.push((
decl.0.clone(),
Some(command.usage().to_string()),
command.command_type(),
));
}
}
}

View File

@ -1,4 +1,5 @@
use super::cached_file::CachedFile;
use super::CommandType;
use super::{
usage::build_usage, Command, EngineState, OverlayFrame, StateDelta, Variable, VirtualPath,
Visibility, PWD_ENV,
@ -708,7 +709,7 @@ impl<'a> StateWorkingSet<'a> {
&self,
predicate: impl Fn(&[u8]) -> bool,
ignore_deprecated: bool,
) -> Vec<(Vec<u8>, Option<String>)> {
) -> Vec<(Vec<u8>, Option<String>, CommandType)> {
let mut output = vec![];
for scope_frame in self.delta.scope.iter().rev() {
@ -721,7 +722,11 @@ impl<'a> StateWorkingSet<'a> {
if ignore_deprecated && command.signature().category == Category::Removed {
continue;
}
output.push((decl.0.clone(), Some(command.usage().to_string())));
output.push((
decl.0.clone(),
Some(command.usage().to_string()),
command.command_type(),
));
}
}
}