Skip to content
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

Combine completion candidates with metadata regarding them #16

Closed
bbatsov opened this issue Sep 9, 2014 · 12 comments
Closed

Combine completion candidates with metadata regarding them #16

bbatsov opened this issue Sep 9, 2014 · 12 comments

Comments

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 9, 2014

Emacs has a feature that allows you to annotate a completion candidate with addition information - e.g. the type of the candidate (function, macro, interface, etc). You can see the feature in action for Emacs Lisp completions. For this to effectively used, however, it'd be beneficial if one could retrieve a completion candidate together with some metadata regarding it (perhaps the type and the ns/package of the candidate, maybe others make sense as well), so avoid having to do one of two things:

  • retrieve the metadata for each candidate individually (which is slow)
  • retrieve all candidates and then do a second function call to retrieve the metadata for all of them

Obviously this is not a must-have feature, but it'd be nice to have something like this in tools like CIDER. I'm also not quite sure if packages like compliment should handle this or their clients, but I wanted to start a discussion on the subject.

@alexander-yakushev
Copy link
Owner

I know about this feature, ac-nrepl used that by calling the backend numerous times to retrieve candidates for each category. I didn't know how to preserve the functionality while reducing the number of calls to one, so I just gave up on that.

I'd be happy to bring it back if it is possible to do without hampering the performance. Perhaps the backend could return candidates in groups, according to their category. Although I'm not sure how then you can use it in ac (ac requires a new source per category which means a separate request per source — or doing some unreliable caching magic).

Also, what about the ns/package of the candidate? It is already given out in the popup doc that is requested per candidate. Is it important to have it in completion, for all candidates at once?

@bbatsov
Copy link
Collaborator Author

bbatsov commented Sep 9, 2014

I'd be happy to bring it back if it is possible to do without hampering the performance. Perhaps the backend could return candidates in groups, according to their category. Although I'm not sure how then you can use it in ac (ac requires a new source per category which means a separate request per source — or doing some unreliable caching magic).

I think that only the nREPL calls are expensive and doing some type checks in Java should be fairly fast. Once a client receives the candidates and the metadata grouping them on the client side should be pretty fast as well. @gtrak suggested returning a list of maps for the candidates in a similar issue for ClojureScript completion. This seems like a good idea to me. Initially the map could have only two elements - the name and the type of the candidate.

Also, what about the ns/package of the candidate? It is already given out in the popup doc that is requested per candidate. Is it important to have it in completion, for all candidates at once?

I just mentioned this as some other metadata we might need (theoretically) beside the candidate's type.

@alexander-yakushev
Copy link
Owner

I think that only the nREPL calls are expensive and doing some type checks in Java should be fairly fast. Once a client receives the candidates and the metadata grouping them on the client side should be pretty fast as well. @gtrak suggested returning a list of maps for the candidates in a similar issue for ClojureScript completion. This seems like a good idea to me. Initially the map could have only two elements - the name and the type of the candidate.

Yes. What I'm saying is that the only way (at least that I'm aware about) in auto-complete to assign a letter for a candidate is to create a separate source for that letter. So that you have a source for vars, a source for namespaces, a source for functions etc. Now every source has its individual retrieval function that should return the list of completions of that type. How would you multiplex all those calls into single nREPL request? By saving the results of a single request into some local state, so that all the sources' retrieval functions will take candidates from that saved state? Seems pretty hackish to me.

@bbatsov
Copy link
Collaborator Author

bbatsov commented Sep 9, 2014

Don't know about auto-complete, but if you're using completion-at-point every candidate is simply passed to an annotation function with adds the extra data for it (here's an example). This works transparently for company-mode and guess auto-complete-mode should start respecting completion-at-point instead of defining its own abstractions.

@alexander-yakushev
Copy link
Owner

auto-complete-mode should start respecting completion-at-point instead of defining its own abstractions.

I'm afraid you are addressing the wrong person with this claim:).

@bbatsov
Copy link
Collaborator Author

bbatsov commented Nov 25, 2014

@alexander-yakushev So, shall we do this or no? People keep asking me about showing candidate type data for a while now and I have to know whether I'll have to do in the middleware or you'll do it in compliment.

@alexander-yakushev
Copy link
Owner

Yeah, perhaps this needs to be done after all. So, does it mean instead of "reduce-kv" to return {:name "reduce-kv" :type :var :namespace "clojure.core"}?

Also, in company mode do you plan just to attach the type tag to candidate name? How will it know not to insert that tag into buffer when completing?

@bbatsov
Copy link
Collaborator Author

bbatsov commented Nov 25, 2014

Also, in company mode do you plan just to attach the type tag to candidate name? How will it know not to insert that tag into buffer when completing?

There's some standard Emacs support for this. See https://github.com/clojure-emacs/cider/blob/master/cider-interaction.el#L798

@alexander-yakushev
Copy link
Owner

OK, it will be easier just to "Hulk smash me write, Bozhidar comment". ETA is tomorrow.

@bbatsov
Copy link
Collaborator Author

bbatsov commented Nov 25, 2014

:-) Guess so.

@bbatsov
Copy link
Collaborator Author

bbatsov commented Dec 3, 2014

Ping :-)

@alexander-yakushev
Copy link
Owner

OK, I need some more time for this. I haven't yet figured the correct way to do this to preserve compatibility with the old method, and to keep the code nice. But I'll get to it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants