haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Implement completionItem/resolve

Open wz1000 opened this issue 3 years ago • 3 comments

Implement completionItem/resolve to lazily resolve types and documentation for completion items. This results in very big memory usage improvments while also improving the responsiveness of completions. Usually when GHC typechecks code, it reads in and deserializes interfaces lazily, so if the code imports a bunch of modules, the interfaces will only be read in and deserialized if a particular name is actually required for typechecking.

However, when we greedily generate completion lists, the act of querying for types and documentation results in sucking in and deserializing interface sections for every single name in scope. This is very bad for memory usage as it negates virtually all the benefits of lazy deserialization.

Instead, we can compute types and documentation on demand for individual completion items using the completionItem/resolve LSP functionality.

A downside to this is that we can no longer generate snippets for functions arguments with placeholders mentioning the types because we no longer have this information available when we generate the original completion, and it is not supported by LSP to resolve the actual completion snippet using completionItem/resolve.

However, I don't personally consider this to be a very big deal because this feature was unreliable (eg for things from the export map which weren't in scope) and I found it to be quite annoying when it did work.

wz1000 avatar Sep 21 '22 04:09 wz1000

Wow, this is a big deal!

michaelpj avatar Sep 21 '22 10:09 michaelpj

Also: tests?

michaelpj avatar Sep 21 '22 12:09 michaelpj

Oh one last thing: we definitely want a cautionary comment on the main completion handler warning people not to accidentally pull in information from interface files in future!

michaelpj avatar Sep 22 '22 08:09 michaelpj

https://github.com/haskell/haskell-language-server/pull/3080 gets the HIE file during completions, is that acceptable?

michaelpj avatar Sep 26 '22 08:09 michaelpj

https://github.com/haskell/haskell-language-server/pull/3080 gets the HIE file during completions, is that acceptable?

I am pretty confident getting the HIE file is 👍

pepeiborra avatar Sep 26 '22 10:09 pepeiborra

I merged the record dot completions PR, which has introduced some conflicts.

michaelpj avatar Sep 27 '22 09:09 michaelpj

pre-commit check is also failing, I think you're missing formatting

michaelpj avatar Dec 19 '22 11:12 michaelpj