Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#3017](https://github.com/clojure-emacs/cider/issues/3017): Annotate company completion kinds.

### Bugs fixed

* [#3020](https://github.com/clojure-emacs/cider/issues/3020): Fix session linking on Windows, e.g. when jumping into a library on the classpath.
Expand Down
27 changes: 27 additions & 0 deletions cider-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ backend, and ABBREVIATION is a short form of that type."
:group 'cider
:package-version '(cider . "0.9.0"))

(defconst cider-completion-kind-alist
'(("class" class)
("field" field)
("function" function)
("import" class)
("keyword" keyword)
("local" variable)
("macro" macro)
("method" method)
("namespace" module)
("protocol" enum)
("protocol-function" enum-member)
("record" struct)
("special-form" keyword)
("static-field" field)
("static-method" interface)
("type" parameter)
("var" variable))
Copy link
Member

@expez expez Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use constant for this (or vice versa) so you can easily tell the difference between local and global variables in the completion list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to change most of those afterwards anyways. E.g. I don't think that macro is a misc, but rather a built-in and so on. But I think there's little point in debating this too much in this particular PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?
image

I think constant may be a bit misleading, but maybe it's ok. I'll let @bbatsov decide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many nuances to consider and this has to be aligned with how clojure-mode works internally as well. That's why I think we can sort it out later. Just update the changelog and for now we're good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. I don't think that macro is a misc

Btw I've changed this to use macro icon, but given that there's no macro icon in company mode, it will default to misc icon automatically. Originally I've used misc because I was not aware of this mechanism. Maybe we can submit an issue to company mode so they could include a macro icon? Or maybe this should be done to vscode, because the icons are from there, and this will benefit to other plugins that use NREPL, like Calva.

Also triangle square and circle kinda seem like a good icon to represent macros, as this is really puzzling :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. We basically mirror VS Code's type. Not to say we can't extend the list, but getting nice icons can be a problem.

Anyway, check out https://github.com/emacs-mirror/emacs/blob/6ec3cf1ccb5380acc376e89140b8d3a7fa4e471a/lisp/progmodes/elisp-mode.el#L647-L655

Since there are no "real" keywords in Lisp, reusing this kind for macros and special forms seemed like a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding local variables, we use the value kind (following the example of some LSP servers). Which differentiates them nicely.

Copy link
Contributor Author

@andreyorst andreyorst Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are no "real" keywords in Lisp, reusing this kind for macros and special forms seemed like a good idea.

Clojure actually does have real keywords, and CIDER annotates those with <k>:

image

Though the icon kinda suggests that this is language-level keyword, not data keyword, so maybe a different icon could be used for those.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this context I actually meant keywords in the sense of "built-ins"/"reserved words". That's how elisp-mode and clojure-mode work. Anyways, not a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreyorst These kind of keywords are present in Elisp as well.

But that's not what is usually called a keyword in most programming languages (in Ruby, we call them "symbols", for example). And as someone who routinely works with several languages, I like to see annotations (and icons) have more universal meanings.

"Icon mapping for company-mode.")

(defcustom cider-completion-annotations-include-ns 'unqualified
"Controls passing of namespaces to `cider-annotate-completion-function'.

Expand Down Expand Up @@ -192,6 +212,12 @@ completion functionality."
(concat (when ns (format " (%s)" ns))
(when type (format " <%s>" type))))

(defun cider-company-symbol-kind (symbol)
"Get SYMBOL kind for company-mode."
(let ((type (get-text-property 0 'type symbol)))
(or (cadr (assoc type cider-completion-kind-alist))
type)))

(defun cider-annotate-symbol (symbol)
"Return a string suitable for annotating SYMBOL.
If SYMBOL has a text property `type` whose value is recognised, its
Expand All @@ -213,6 +239,7 @@ performed by `cider-annotate-completion-function'."
(list (car bounds) (cdr bounds)
(completion-table-dynamic #'cider-complete)
:annotation-function #'cider-annotate-symbol
:company-kind #'cider-company-symbol-kind
:company-doc-buffer #'cider-create-doc-buffer
:company-location #'cider-company-location
:company-docsig #'cider-company-docsig))))
Expand Down