Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Add GetHieAsts rule, Replace SpanInfo, add support for DocumentHighlight and scope-aware completions for local variables #784

Merged
merged 23 commits into from
Sep 27, 2020

Conversation

wz1000
Copy link
Collaborator

@wz1000 wz1000 commented Sep 12, 2020

This is all the remaining changes from the hls-3 branch.

Drops support for GHC 8.4

Fixes #663

Changes:

  • Remove the GetSpanInfo rule, depend entirely on GetHieAst for hover, go to definition etc.

New features:

  • Document Highlight for highlighting references of a Name in the same file
  • Completion for local variables in scope via GetBindings

Missing features:

  • Go to definition for module names
  • Kind info on hover
  • Relevant constraints on hover

TODOs:

  • Add tests for new features
  • fix as many existing tests as possible
  • Re-add as many missing features as possible, using something like the DocMap mechanism
  • Benchmark performance differences

Related GHC MRs for .hie file changes:

https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4037

https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4068

One has already been merged into the ghc-9.0 branch, the other will be merged soon hopefully

Old description:

This is the slight modification of what already lives in the hls-3 and hiedb-3 branches, necessary for haskell/haskell-language-server#391

We make some modifications to be able to save the HieAst before compressing the types. We compress the types on demand when we actually need to write the file to disk. This should improve hls performance somewhat as we get rid of the overhead of type compression (which can be expensive) in most cases.

@isovector
Copy link
Contributor

Marvelous. Thank you so much!

@pepeiborra
Copy link
Collaborator

Will other clients like Stan be able to use the hie files produced by ghcide? If not, maybe we should change the file extension

@pepeiborra
Copy link
Collaborator

Any changes worth upstreaming to ghc?

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems a bit incomplete. Is there any reason for that?

src/Development/IDE/Core/Rules.hs Show resolved Hide resolved
src/Development/IDE/Core/Rules.hs Show resolved Hide resolved
@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 13, 2020

Will other clients like Stan be able to use the hie files produced by ghcide? If not, maybe we should change the file extension

Yes, the hie files are generated in precisely the same way.

Any changes worth upstreaming to ghc?

Yeah, we need enrichHie exported. I will make a MR today. Hopefully it can get into 9.0

@wz1000 wz1000 changed the title Add GetHieAsts rule Add GetHieAsts rule, Replace SpanInfo, add support for DocumentHighlight and scope-aware completions for local variables Sep 18, 2020
@pepeiborra
Copy link
Collaborator

I just updated the benchmarks to measure allocations and delayed actions

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of changes I do not understand, but they've been in HLS since 0.2.0 so I am happy to merge them provided the tests pass and the new benchmarks don't show any nasty regressions.

progress

src/Development/IDE/Core/RuleTypes.hs Show resolved Hide resolved
src/Development/IDE/Spans/LocalBindings.hs Show resolved Hide resolved
src/Development/IDE/Spans/LocalBindings.hs Outdated Show resolved Hide resolved
@@ -392,19 +396,7 @@ getCompletions ideOpts cc pm pmapping prefixInfo caps withSnippets = do
to 'foo :: Int -> String -> '
^
-}
pos =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this stuff anymore because of fuzzy position mapping. I had to wade through multiple git commits across repositories to find @bubba as the source of this code. If I understand correctly, it existed so that we could detect type contexts even if the module didn't parse.

Suppose the cursor is at the |

foo :: Integer -> Integer -> |

So the idea was to strip out the trailing "-> ", and then look for the "context" of the position (whether it was in a value/type/import etc.) at the position (newPositionToOld would just return Nothing).

Now, fromDelta will return the original range that was inserted to/replaced, so we can use it instead.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 21, 2020

I'm a bit busy this week, will hopefully finish this up on the weekend.

Till then, here's a gif demonstrating local completions(you can try it out by running haskell-language-server):

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

I am leaning towards not adding back the "relevant constraints on hover" feature.

  1. It is not complete, it misses many constraints (for example, constraints introduced by GADT pattern matching etc.)
  2. It will require a generic SYB style traversal of the AST, which is not needed for anything else anymore thanks to this PR
  3. GHC 9.0 will allow writing this feature properly with the changes from https://gitlab.haskell.org/ghc/ghc/-/merge_requests/1286
  4. (the weakest reason) this feature hasn't existed in HLS for a long time and nobody has seemed to miss it.

/cc @pepeiborra @ndmitchell thoughts?

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

I have fixed as many tests as I plan to. The remaining failures are genuine behavior divergences that I don't think are worth fixing. Please review them once CI completes.

The only TODO remaining is to add tests for the new features.

@pepeiborra
Copy link
Collaborator

I am fine with dropping the "constraints on hover" feature, it was bit erratic for me and only seemed to work on declaration lhs's. Is there any chance of back porting #1286 to the ghcide fork of Hie files?

Ignoring the tests related to that feature, there are only 5 failing tests, all related to hover. Good job!

Please share some benchmarks if you have the chance too.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

Here are the interesting benchmark results:

hover after edit seems to be down:

completions after edit is up, but that is to be expected since we are doing more work, calculating local completions:

There is some funkyness with the allocations for document symbols I can't explain:

The rest seem to be unchanged, except for the shape of the allocation graph: http://78.47.113.11/benchmarks/

@pepeiborra
Copy link
Collaborator

Look at the "Delayed work" column in the results.csv file:

  • "Hover after edit" is almost twice as efficient in delayed time. 50% more efficient in user time, 50% less allocations
  • "Document symbols after edit" is almost twice as efficient in delayed time
  • "Completions after edit" is almost twice as inefficient in delayed time and allocates 19% more

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

What exactly is delayed time?

@pepeiborra
Copy link
Collaborator

What exactly is delayed time?

The time spent waiting for all the delayed actions in the Shake queue to complete

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

The regression in completion performance is expected since we now depend on Typecheck, not just GetParsedModule. Stale information should hide most of the difference in actual use I think. I've taken care to still generate completions using only the ParsedModule if typechecking fails.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

I have no idea why there is a change for DocumentSymbols.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

Added tests! This is done except for that one Unexpected Pass on 8.10.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 26, 2020

I don't have the energy to figure out why the test is passing on 8.10 but not on GHC versions before that. I diffed the HieAst generation code, but could find no obvious culprits. I'm just CPPing the error away. With any luck this is good to go now.

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 27, 2020

Any opinions on whether I should remove 8.4 specific CPP in this PR, or a different one?

@pepeiborra
Copy link
Collaborator

pepeiborra commented Sep 27, 2020

I would say merge this when ready and clean up 8.4 CPP in another PR to minimise conflicts

@wz1000
Copy link
Collaborator Author

wz1000 commented Sep 27, 2020

OK, I think this is ready, we can merge if you are happy.

@pepeiborra pepeiborra merged commit 62f4d06 into haskell:master Sep 27, 2020
pepeiborra pushed a commit to pepeiborra/ghcide that referenced this pull request Oct 5, 2020
…ght and scope-aware completions for local variables (haskell#784)

* Add GetHieAsts rule

* hlint

* fix build for 8.4

* Reimplement Hover/GotoDefn in terms of HIE Files.
Implement Document Hightlight LSP request
Add GetDocMap, GetHieFile rules.

* Fix gotodef for record fields

* Completion for locals

* Don't need to hack cursor position because of fuzzy ranges

* hlint

* fix bench and warning on 8.10

* disable 8.4 CI jobs

* Don't collect module level bindings

* tweaks

* Show kinds

* docs

* Defs for ModuleNames

* Fix some tests

* hlint

* Mark remaining tests as broken

* Add completion tests

* add highlight tests

* Fix HieAst for 8.6

* CPP away the unexpected success

* More CPP hacks for 8.10 tests
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…ght and scope-aware completions for local variables (haskell/ghcide#784)

* Add GetHieAsts rule

* hlint

* fix build for 8.4

* Reimplement Hover/GotoDefn in terms of HIE Files.
Implement Document Hightlight LSP request
Add GetDocMap, GetHieFile rules.

* Fix gotodef for record fields

* Completion for locals

* Don't need to hack cursor position because of fuzzy ranges

* hlint

* fix bench and warning on 8.10

* disable 8.4 CI jobs

* Don't collect module level bindings

* tweaks

* Show kinds

* docs

* Defs for ModuleNames

* Fix some tests

* hlint

* Mark remaining tests as broken

* Add completion tests

* add highlight tests

* Fix HieAst for 8.6

* CPP away the unexpected success

* More CPP hacks for 8.10 tests
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…ght and scope-aware completions for local variables (haskell/ghcide#784)

* Add GetHieAsts rule

* hlint

* fix build for 8.4

* Reimplement Hover/GotoDefn in terms of HIE Files.
Implement Document Hightlight LSP request
Add GetDocMap, GetHieFile rules.

* Fix gotodef for record fields

* Completion for locals

* Don't need to hack cursor position because of fuzzy ranges

* hlint

* fix bench and warning on 8.10

* disable 8.4 CI jobs

* Don't collect module level bindings

* tweaks

* Show kinds

* docs

* Defs for ModuleNames

* Fix some tests

* hlint

* Mark remaining tests as broken

* Add completion tests

* add highlight tests

* Fix HieAst for 8.6

* CPP away the unexpected success

* More CPP hacks for 8.10 tests
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
…ght and scope-aware completions for local variables (haskell/ghcide#784)

* Add GetHieAsts rule

* hlint

* fix build for 8.4

* Reimplement Hover/GotoDefn in terms of HIE Files.
Implement Document Hightlight LSP request
Add GetDocMap, GetHieFile rules.

* Fix gotodef for record fields

* Completion for locals

* Don't need to hack cursor position because of fuzzy ranges

* hlint

* fix bench and warning on 8.10

* disable 8.4 CI jobs

* Don't collect module level bindings

* tweaks

* Show kinds

* docs

* Defs for ModuleNames

* Fix some tests

* hlint

* Mark remaining tests as broken

* Add completion tests

* add highlight tests

* Fix HieAst for 8.6

* CPP away the unexpected success

* More CPP hacks for 8.10 tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upstream things from hls-2
3 participants