racer-rust / racer

Rust Code Completion utility
MIT License
3.36k stars 279 forks source link

Do not complete in comments outside code tags #694

Open torkleyy opened 7 years ago

torkleyy commented 7 years ago

I'm not sure whether this is a racer or a plugin issue.

marsam commented 7 years ago

If you use the Emacs plugin, you need to set (setq racer-complete-in-comments t)

torkleyy commented 7 years ago

@marsam thanks for your help, but I'm having this issue in 1) Atom and 2) VSC while the latter one recently got rls support

TedDriggs commented 7 years ago

VSCode-Rust seems to have fixed this problem in both racer and RLS modes.

As a user, my perspective on this issue is mixed:

  1. I really don't like getting completions after typing . in a comment outside a code-block. Trying to end a comment line with a period is especially annoying, since the Enter key inserts the highlighted suggestion.
  2. I like getting completions after typing :: - that doesn't appear in my comments unless I'm writing a path, even if it's outside a code block.
  3. I really like getting completions within inline or block code.

As a racer maintainer, I'd be interested to hear from @nrc, @KalitaAlexey and @qzed on this point. It would be easier for racer if the editor plugins handled deciding whether or not to request completions, but there may be a compelling reason that's infeasible or undesirable that I'm not seeing.

nrc commented 7 years ago

I agree this seems like an editor issue.

jwilm commented 7 years ago

Hmm; I'm not convinced this is an editor issue. For something like VSCode which is just a text editor, it seems strange for it to require semantic knowledge of the file being edited. Handling this complexity in Racer means editor plugins could simply trigger completions on :: and ., without having to do any parsing, and Racer could yield an empty response in cases where they are in a comment. Should probably be configurable, though.

nrc commented 7 years ago

OK, on consideration, perhaps this should not be a client issue. My thinking was that the RLS already has to do some of this work in other cases, but most clients are not going to have the kind of resources the RLS has so won't be able to do that. It is also nice that if Racer does this, the RLS can let Racer start a little bit earlier.

TedDriggs commented 7 years ago

So I think the desired behavior is:

  1. Calling complete outside a single or triple backtick should find nothing
  2. Calling complete inside a single backtick should complete as normal
  3. Calling complete inside a triple backtick with no language annotation or annotated with rust as the language should complete as normal
  4. Calling complete inside a triple backtick with any other language annotation should find nothing

Unfortunately, I don't see a good way of doing this other than trying to parse the whole comment block; the fact that open and closing marks are the same probably precludes a naive solution.