-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove 'help-circle.svg' (question mark) icon from unknown autocompletions #50
Remove 'help-circle.svg' (question mark) icon from unknown autocompletions #50
Conversation
I think we should hide icons only when all are unknown, otherwise it will introduce visual inconsistency when a LSP plugin is supported but kinds are not matched due to a minor issue (customization, outdated handling on gnvim) or simply absent for that particular item. |
Good point! So we find a different icon for text completions, and then if all of the completions are unknown, we show no icons. I actually got this functionality to work in a local clone of mine. It uses a boolean parameter in the |
Unknown completions in the pmenu now show icons if one or more completions' kinds in the pmenu are known (to gnvim). This is done by iterating throughout the items in the pmenu when necessary to check if their completion kind is known (to gnvim).
Showing the help-circle when there are some known kinds is the way to go, so we avoid visual inconsistencies (just like @badosu noted). On a case when there are no icons shown (e.g. all kinds are unknown), remember to add some padding to the left side of the actual text. I would also avoid differing the code paths too much. Regarding the issue that you are still facing: how to detect when a pub enum CompletionItemKind {
Function,
Constructor,
File,
Folder,
//...
Unknown,
}
impl CompletionItemKind {
pub fn is_unknown(&self) -> bool {
match self {
CompletionItemKind::Unknown => true,
_ => false,
}
}
}
// Detecting if some of `items` is unknown/known:
items.iter().find(|item| !item.is_unkown()).is_some()) I didn't try this, so I'm not completely sure how it'll play out. We already have a "know set" of kinds, might has well make the type system aware of it. I'll try to add some notes to other parts of the code some other day (its getting late here). |
Thanks @vhakulinen for the info, I will try to get that working. If it goes well I’ll push a commit for review. |
So, how does this look for nvim_bridge.rs? Is this at all like what you were thinking @vhakulinen? diff --git a/src/nvim_bridge.rs b/src/nvim_bridge.rs
index 72a9777..fe0eec5 100644
--- a/src/nvim_bridge.rs
+++ b/src/nvim_bridge.rs
@@ -211,10 +211,79 @@ pub enum OptionSet {
NotSupported(String),
}
+#[derive(Clone)]
+pub enum CompletionItemKind {
+ Class,
+ Color,
+ Constant,
+ Constructor,
+ Enum,
+ EnumMember,
+ Event,
+ Function,
+ File,
+ Folder,
+ Field,
+ Interface,
+ Keyword,
+ Method,
+ Module,
+ Operator,
+ Property,
+ Reference,
+ Snippet,
+ Struct,
+ Text,
+ TypeParameter,
+ Unit,
+ Unknown,
+ Value,
+ Variable,
+}
+
+impl CompletionItemKind {
+ pub fn new_from_str(kind: &str) -> Self {
+ match kind {
+ "class" => CompletionItemKind::Class,
+ "color" => CompletionItemKind::Color,
+ "constant" => CompletionItemKind::Constant,
+ "constructor" => CompletionItemKind::Constructor,
+ "enum" => CompletionItemKind::Enum,
+ "enum member" => CompletionItemKind::EnumMember,
+ "event" => CompletionItemKind::Event,
+ "function" => CompletionItemKind::Function,
+ "file" => CompletionItemKind::File,
+ "folder" => CompletionItemKind::Folder,
+ "field" => CompletionItemKind::Field,
+ "interface" => CompletionItemKind::Interface,
+ "keyword" => CompletionItemKind::Keyword,
+ "method" => CompletionItemKind::Method,
+ "module" => CompletionItemKind::Module,
+ "operator" => CompletionItemKind::Operator,
+ "property" => CompletionItemKind::Property,
+ "reference" => CompletionItemKind::Reference,
+ "snippet" => CompletionItemKind::Snippet,
+ "struct" => CompletionItemKind::Struct,
+ "text" => CompletionItemKind::Text,
+ "type parameter" => CompletionItemKind::TypeParameter,
+ "unit" => CompletionItemKind::Unit,
+ "value" => CompletionItemKind::Value,
+ "variable" => CompletionItemKind::Variable,
+ _ => CompletionItemKind::Unknown,
+ }
+ }
+ pub fn is_unknown(&self) -> bool {
+ match self {
+ CompletionItemKind::Unknown => true,
+ _ => false,
+ }
+ }
+}
+
#[derive(Clone)]
pub struct CompletionItem {
pub word: String,
- pub kind: String,
+ pub kind: CompletionItemKind,
pub menu: String,
pub info: String,
}
@@ -679,7 +748,7 @@ fn parse_redraw_event(args: Vec<Value>) -> Vec<RedrawEvent> {
for item in unwrap_array!(args[0]) {
let item = unwrap_array!(item);
let word = unwrap_str!(item[0]).to_owned();
- let kind = unwrap_str!(item[1]).to_owned();
+ let kind = CompletionItemKind::new_from_str(&unwrap_str!(item[1]).to_owned());
let menu = unwrap_str!(item[2]).to_owned();
let info = unwrap_str!(item[3]).to_owned(); I made changes in other files to accommodate this diff, but this is the core of the change, so I want to make sure this is solid before I settle on my other diffs (and put them up for review). |
One question: should I implement a |
Some notable changes in this commit include the additoin of the 'CompletionItemKind' enum to nvim_bridge.rs per vhakulinen's suggestion, in addition to changing the 'CompletionItemWidgetWrap::create' function to take a reference to the other items in the popupmenu. That function then checks whether or not any other items in the pmenu have icons to determine if it should use an icon for the created 'CompletionItemWidgetWrap' object if it's kind is unknown. I have also refactored `get_icon_pixbuf` and `get_icon_name_for_kind` to take a reference to a 'CompletionItemKind' instead of a 'str'.
Changes have been pushed for review; any suggestions are welcome and much appreciated. Also, note that I have commented out the |
Remember to run |
….com/smolck/gnvim into no-icon-for-unknown-completion-items
Changes have been pushed for review. (Removed WIP from title since this only needs maybe a bit more polish.) |
Looking good! Just couple minor things that need to be fixed. |
@vhakulinen I’ve pushed the changes you requested. If there is anything left that needs fixing/changing please let me know. As a side note, thank you for all of your help with this PR and my previous one. Taught (and still teaching) me valuable information about Rust, in addition to better, more efficient and idiomatic ways of doing things. |
Try adding a |
LGTM 👍 |
Merged! Thanks for your efforts! I made couple small changes: other was to remove unnecessary clone (effectively a copy) and added missing padding on info item when the icon is not shown. |
This is an idea of how to remove the 'help-circle.svg' icon from autocompletions that are unknown to clean up the look for completions with unsupported or unimplemented kinds (like those of LanguageClient-Neovim):
Any feedback would be much appreciated! Currently this works by filling in an empty image in the popupmenu if there is an error with the icon's
gdk_pixbuf
(which is created from returning the "None" string in theget_icon_name_for_kind
function).See #47.