Closed geraldus closed 9 years ago
@judah well, this sounds reasonable for me, I'm just too new to GHC codebase. I can take care about this stuff, but need some clarification.
Let me briefly repeat what's happening. The entry point is ghciCompleteWord
function. It takes a line, and searching completions for its last word. The point of interest is last case, where completeExpression
function called for whole line. The latter uses completeQuotedWord
function. It tries to get file path completions first if expression is quoted with "
(I didn't understood this well), and in other case it uses completeIdentifier
function. Finally, completeIdentifier
uses wrapIdentCompleter
function which is the crux of the matter.
Now I'm confused a bit, completeIdentifier
function is used a lot in other places, for example in ghciCommands
function, I didn't find Command
definition yet, but I suspect that the third element of tuple is a completion function to be used with that command (and that's why there is listFiles
used internally, because some commands expect path as input also). So it is possible to write a new function for a specific use case, but I believe that completeIndentifier
should be fixed itself, for example when I type :info >>
in REPL and hit Tab it shows me all imported names too, likely this is not expected bahaviour.
What do you think, what can you suggest?
Pinging @hvr , can you please review this discussion also?
Command is defined in ghc/GhciMonad.hs; as you guessed, the third element is a CompletionFunc.
You're right that we need to change this for more than just expressions (e.g. :info, :type), and the right fix might be to change completeIdentifier itself as you've suggested. You just need to be careful that this doesn't affect the word-breaking behavior of other completers like, for example, completeSetModule, which tab-completes ":module +" or ":module -" to a list of module names. But since that's handled by a separate function (wrapIdentCompleterWithModifier) it might be fine regardless.
Let me know if you'd like any other pointers in the code or run into any other problems getting this working.
Ok, after some delay I've finally figured out most important things for me, let's close this, because I have to continue with Phab again.
For more details see issue #10576 https://ghc.haskell.org/trac/ghc/ticket/10576
I've tested this with GHC head build, here is some results:
Note, that in case of empty input or only whitespace input it still will return all imported names, but I suppose this is different issue.
Also, operator symbols also could be any [non-ascii] Unicode symbol or punctuation, but this stuff is unsupported.