Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix completion for qualified import #2838

Merged
merged 3 commits into from
Dec 2, 2023

Conversation

xsebek
Copy link
Contributor

@xsebek xsebek commented Apr 18, 2022

  • add the missing test case for Completions broken for pre-qualified import #2824
  • fix how we get the module name considering it can be preceded by qualified
  • use parsed context for import completions
    • add regression test for fixed multiline import
  • refactor getCompletions function

@michaelpj
Copy link
Collaborator

Can we mark this as failing somehow so we can merge it without the fix?

ghcide/test/exe/Main.hs Outdated Show resolved Hide resolved
@xsebek
Copy link
Contributor Author

xsebek commented Apr 20, 2022

@michaelpj there are other tests marked as such, so it can surely be done.

The second one should be passing though, so I need to check what I am testing. 😅

@xsebek xsebek force-pushed the qualified-completion branch 2 times, most recently from 914a216 to e14f12d Compare May 21, 2022 17:06
@xsebek xsebek changed the title Test qualified completion Fix completion for qualified import May 21, 2022
@xsebek xsebek marked this pull request as ready for review May 21, 2022 19:14
@xsebek xsebek requested a review from pepeiborra as a code owner May 21, 2022 19:14
@xsebek
Copy link
Contributor Author

xsebek commented May 21, 2022

@michaelpj I marked it as expected to fail, but then I found the fix anyway 😀

ghcide/test/exe/Main.hs Outdated Show resolved Hide resolved
@xsebek
Copy link
Contributor Author

xsebek commented May 22, 2022

Btw. I have no idea what is CI trying to tell me:

EDIT: OK, now that I have my glasses, I see there is one grey job not skipped but cancelled, which caused this condition to fail.

@michaelpj
Copy link
Collaborator

I reran the failed jobs, let's see what happens.

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs Outdated Show resolved Hide resolved
ghcide/test/exe/Main.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/Completions/Logic.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/Completions/Logic.hs Outdated Show resolved Hide resolved
@xsebek xsebek force-pushed the qualified-completion branch from 61d1d30 to 9806d3f Compare May 25, 2022 01:14
@xsebek
Copy link
Contributor Author

xsebek commented May 25, 2022

@michaelpj Good news, using the parsed context seems to have fixed the problem with multiline import completions! 👍

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Good news, using the parsed context seems to have fixed the problem with multiline import completions!

Could we add a regression test for this?

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/Completions/Logic.hs Outdated Show resolved Hide resolved
@xsebek xsebek force-pushed the qualified-completion branch from 9806d3f to 4de4bb1 Compare May 26, 2022 20:39
@xsebek
Copy link
Contributor Author

xsebek commented May 26, 2022

@michaelpj sure, I added a regression test. 🙂

@xsebek xsebek force-pushed the qualified-completion branch from 4de4bb1 to 2b1cf8a Compare May 30, 2022 20:17
@xsebek
Copy link
Contributor Author

xsebek commented May 30, 2022

The CI smiles on me this day! ☀️

@pepeiborra could you please check the comments above? 🙂

@xsebek xsebek force-pushed the qualified-completion branch 2 times, most recently from 277faef to ab717b3 Compare June 4, 2022 18:19
@xsebek
Copy link
Contributor Author

xsebek commented Jun 4, 2022

After inspecting the CI (see comment above), I decided to keep the manual parsing.

@pepeiborra @michaelpj If the CI passes, I think it is ready to merge.

EDIT: Let me backtrack on backtracking and try the CI again... 👀

@xsebek xsebek force-pushed the qualified-completion branch from ab717b3 to 48ed975 Compare June 7, 2022 13:05
@xsebek
Copy link
Contributor Author

xsebek commented Jun 9, 2022

Weird, the test fails on GHC 8.8.4 because there is an unexpected command with import Control.Monad qualified as M (j)

-- explicit qualified post:    FAIL (1.80s)
-- test/exe/Main.hs:4826:
-- Expected no command but got:
Just (Command {
  _title = "extend import",
  _command = "143210:ghcide-completions:extendImport",
  _arguments = Just [Object (fromList 
    [("doc",String "file:///tmp/extra-dir-35255587795340/A.hs")
    ,("importName",String "Control.Monad")
    ,("importQual",Null)
    ,("newThing",String "join")
    ,("thingParent",Null)
  ])]
})

This seems very strange to me because it does not happen on 8.10 and to normal pre-qualified import test. 😕

Also from what I gather "extend import" should show up only if the join was written outside the import list.

@michaelpj
Copy link
Collaborator

I restarted the tests, and now the 8.6.5 one fails as well in the same way. It also doesn't fail except on ubuntu. Perhaps it's just flaky, and we're missing a call to wait for something somewhere?

@pepeiborra
Copy link
Collaborator

pepeiborra commented Jul 31, 2022

Consistent failure:


Building test suite 'func-test' for hls-1.7.0.0..
Running 1 test suites...
Test suite func-test: RUNNING...
haskell-language-server
  completions
    import function completions: FAIL (2.28s)
      test/functional/Completion.hs:144:
      expected: Just CiFunction
       but got: Just CiStruct
1 out of 1 tests failed (2.28s)
Test suite func-test: FAIL

https://github.com/haskell/haskell-language-server/runs/7592685137?check_suite_focus=true#step:10:290

The test needs adjusting, the new result is more correct thanks to the changes in this PR.

@xsebek are you able to adjust the test and get this PR finally merged?

@pepeiborra pepeiborra added the status: unfinished Status for PRs that have been semi-abandoned label Aug 13, 2022
@xsebek xsebek force-pushed the qualified-completion branch from bcbcd28 to a619e5c Compare October 15, 2023 11:47
- add test for post-qualified completion
- add failing test for pre-qualified completion
- add failing test for multiline import
- fix how we get the module name considering it can be preceded by `qualified`
- use parsed context for import completions
  - add regression test for fixed multiline import
- refactor `getCompletions` function
@xsebek xsebek force-pushed the qualified-completion branch from a619e5c to cf6db6c Compare October 15, 2023 12:01
@xsebek
Copy link
Contributor Author

xsebek commented Oct 15, 2023

Sorry for leaving this open for so long!

@pepeiborra I fixed the test failing on CiStruct but after rebase on upstream/master I could not find the test again. 😕

I will wait to see what the CI says this time and hopefully finally get this merged.

@fendor
Copy link
Collaborator

fendor commented Oct 15, 2023

I fixed the test failing on CiStruct but after rebase on upstream/master I could not find the test again.

@xsebek That's my fault, we cleaned up the func-test suite, and apparently I misjudged that the completion tests are redundant.

@xsebek
Copy link
Contributor Author

xsebek commented Oct 15, 2023

@fendor thanks for the quick response. 👍

The CI did not finish well:

  • on macOS all tests were skipped, but are shown as green
  • ubuntu with GHC 9.2 failed on one flaky test sends indefinite progress notifications
  • Nix failed on ubuntu because "No space left on device"
  • Nix failed on macOS because of fourmolu dependency

Any tips to make the CI green?

@fendor
Copy link
Collaborator

fendor commented Oct 15, 2023

We don't run the tests on macos (honestly, I don't know why, this will surely bite us at some point) and nix CI is optional. It will actually be reduced #3804 quite soon, so don't worry about that.

I restarted the test suite for the flaky test, sounds like this PR is green and doesn't require your input at the moment.

@fendor fendor added status: needs review This PR is ready for review and removed status: unfinished Status for PRs that have been semi-abandoned labels Oct 18, 2023
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Am I correct in the assumption, the way this actually fixes the issue is by using maybeContext parsing the module and reliably giving a module name?

This PR has the trade-off that we sometimes can't suggest a module correctly if there is a parse error in the file, for example,

module Test where 

import
import 
--      ^ Put your cursor here

will not suggest imports. That's a change in behaviour, but I don't think it is a blocking one.

I think we should document, perhaps in the function documentation of getCompletions, which classes of completions are dependent on an existing parsed module and which are not?

@xsebek
Copy link
Contributor Author

xsebek commented Nov 11, 2023

@fendor Yes, I switched to using the (hopefully) parsed context, which makes it work in more situations including multiline.

Maintaining the ad-hoc parsing does not seem worthwhile to me. I assume GHC does not stop on first parse error, so anything that it can manage to parse we will be able to use for suggestions. Your example seems to me like something GHC could (and should) handle better than HLS.

The rest of the completions seem to use a mix of HIE AST (recordDotSyntaxCompls) and ad-hoc text parsing (enteredQual). I don't know the detail, so my guess might be more misleading than useful. 😕

@fendor
Copy link
Collaborator

fendor commented Nov 11, 2023

I assume GHC does not stop on first parse error

GHC does stop after the first parse error.

I think that's fine by me. A Haskell file shouldn't have parse errors in it anyway.

@fendor fendor added merge me Label to trigger pull request merge and removed status: needs review This PR is ready for review labels Dec 2, 2023
@fendor fendor enabled auto-merge December 2, 2023 10:36
@fendor fendor merged commit 51db1f2 into haskell:master Dec 2, 2023
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants