-
Notifications
You must be signed in to change notification settings - Fork 97
Conversation
I thought the idea was to not implement completion support directly in |
@mpickering I think the plan was always to implement completions inside ghcide. It was things like Hoogle/HLint/LiquidHaskell we thought were best handled by plugins. |
I was not aware on any plans on this respect, I just found |
Just wanted to say I tried this out and it works very nicely! |
Just mentioning that you are probably inheriting haskell/haskell-ide-engine#1434 from me. |
Thanks for the heads up @fendor - would be great if we can eventually share these (either because hie and ghcide merge, or because there is a common underlying library everyone uses) |
Thanks for the PR, I’m hoping to get around to taking a look at this tomorrow but from an initial look, it looks great 👍 |
There's still a problem I need to solve. The completions only work if the chnages make the problem still typecheck. For example, if I have thing :: String -> I and I want to obtain completions for thing :: String -> Int this is type-correct code and The question here is: is there any way to "save" the latest type correct |
The core of the IDE was designed to support getting stale values, e.g. |
So if I changed my usage of |
This reverts commit 04ca13b.
|
defer type errors will defer type errors, but not parse or name errors, which tends to be when you are asking for completions, and typically I want the best completions that can be found in < 0.1s. I think this is the right place to use stale results. |
The code looks good to me, thanks a lot! I’ve also tested it on an internal codebase and it doesn’t seem to increase memory usage significantly which I was a bit afraid off. I am trying to figure out what we need to make sure that this doesn’t cause any licensing problems. I’ll get back to you once I know what steps need to be taken. |
It would be great if you could test the code. It seems that everything works fine except for qualified imports, but I cannot find the reason why. Also, the new version with Some other issues before considering merging:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great with some minor comments and seems to work very nicely in some manual tests, thanks a lot! I would that we add at least one test that makes sure we don’t break this completely before merging.
I’ve left an inline comment on the withSnippets
stuff. I think it makes sense to keep it for now.
As for the other bug, I would suggest to address this in a separate PR. For now, a test marked as an expected failure would be great.
(I’ve got a response on the licensing question and that’s all good)
Thanks for fixing the positions, I would still like to see some tests before merging this. Doesn’t need to be comprehensive but at least one basic integration test and one that exercises the |
I've written some preliminary tests. However, I cannot get my head around how to check the stale file; I've tried several ways but all of them lead to a stuck test. |
I’ve pushed a fix for the tests. The two expected failures where caused by the fact that those did not typecheck nor did you have a stale result. I changed them to first produce something that typechecks so you have a stale result. Given that this already exercises the stale codepath I’ve removed the separate test for that. Do you have anything else that you want to address? Otherwise I think this should be ready to land (I’ll be on vacation so it might take me longer to respond). |
No, the PR looks perfect to me. I guess we now should wait for bug reports and other problems that may arise. |
parseNs (String "z") = pure tvName | ||
parseNs _ = mempty | ||
|
||
instance FromJSON NameDetails where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this JSON stuff is not needed here because it is only used for the resolveCompletion
LSP request, where the types of non local names and documentation is looked up. It doesn't seem like you added support for the resolve completion request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I didn't implement the resolver completion request, since all information is already sent in the original response. Is this wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you are going to get types for things not defined in the active module, since they are looked up in the local type env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't plan to implement the resolve completion request, you can remove everything to do with JSON - which is everything from line 42 to 77.
-- default to value context if no explicit context | ||
context = fromMaybe ValueContext $ getCContext pos (tm_parsed_module tm) | ||
|
||
{- correct the position by moving 'foo :: Int -> String -> ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@serras sorry for digging up this old PR, but do you remember the rationale for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this code was taken from haskell-ide-engine
, and I think that's where this originated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, I was one of the original implementors! Guess I'll have to do some more digging...
* Initial implementation of completion support * Add fuzzy to set of additional dependencies in 8.8 * Fix test * Work a bit more on completion * Attempt at getting completions from last good tckd module * Revert "Attempt at getting completions from last good tckd module" This reverts commit 04ca13b9d831eaaf013239cd8cbc49ea284b6de1. * "useWithStale" everywhere * Some suggestions by @cocreature * Adjust positions in the document * Start working on tests * Fix compilation problem * Fix tests * Better type tests
* Initial implementation of completion support * Add fuzzy to set of additional dependencies in 8.8 * Fix test * Work a bit more on completion * Attempt at getting completions from last good tckd module * Revert "Attempt at getting completions from last good tckd module" This reverts commit 04ca13b9d831eaaf013239cd8cbc49ea284b6de1. * "useWithStale" everywhere * Some suggestions by @cocreature * Adjust positions in the document * Start working on tests * Fix compilation problem * Fix tests * Better type tests
* Initial implementation of completion support * Add fuzzy to set of additional dependencies in 8.8 * Fix test * Work a bit more on completion * Attempt at getting completions from last good tckd module * Revert "Attempt at getting completions from last good tckd module" This reverts commit 04ca13b9d831eaaf013239cd8cbc49ea284b6de1. * "useWithStale" everywhere * Some suggestions by @cocreature * Adjust positions in the document * Start working on tests * Fix compilation problem * Fix tests * Better type tests
This PR adds completion support (as per #211). Right now it's mostly stripped out parts of
haskell-ide-engine
, put back together into the rule-based system ofghcide
. It seems to work for value level things, but not so well for type-level things, so further investigation is needed.The information shown is also very basic. In the future the idea is to also return the documentation of the functions, if available.