-
-
Notifications
You must be signed in to change notification settings - Fork 391
Import Regression: Wrong Import Placement on first Import #2100
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
Comments
OMG this is the neverending history. A regression test is absolutely needed as first step. |
sure! I can have a look tomorrow |
hi, so I played around a little with this just now and it seems the issue is whenever the first (non-empty) line after the 'module ... where' is a comment, if you put anything above the comment the 'import' seems to be added above that correctly, as an example, with a data declaration above the comment the import gets added above that: module Test import Data.Monoid -- newly added -- | some comment The problem seems to be with this function:
Where there are two cases, when the import list is empty, it finds the position from 'hsmodDecls', and if it matches this case and the first line is a comment, we have the problem with the import being added under the comment. The second case is when there are imports, so the import list isn't empty, in which case it finds the position from 'hsmodImports', and will add the suggested import under the current last import in the file, which works fine once the existing imports are in the correct position, as mentioned already. So I'd be happy to try to make a fix for this some evening later in the week if that suits, but it would be good to add a number of tests as well, so I was wondering where's the best place to add them? There's a 'test' folder in '/ghcide/...', but I didn't see any tests for this functionality there, and there's two import plugins (refine and explicit) but I don't think either are particularly related to this issue. Just to make sure I add them in a sensible place. Thanks! |
@nini-faroux many thanks for the head up, i think the place for such tests could be haskell-language-server/ghcide/test/exe/Main.hs Line 1579 in a5d70ee
|
that's great, thanks @jneira |
Remove HasSrcSpan import
Remove HasSrcSpan import Amend extendImportHandler' function Amend old import tests
* Remove HasSrcSpan import * Amend extendImportHandler' function * Amend old import tests * Adapt tests for windows newline issue
* Remove HasSrcSpan import * Amend extendImportHandler' function * Amend old import tests * Adapt tests for windows newline issue
* Remove HasSrcSpan import * Amend extendImportHandler' function * Amend old import tests * Adapt tests for windows newline issue Co-authored-by: Javier Neira <[email protected]>
Here's a weird one: first imports are inserted in wrong place. Unsure why.
Your environment
Output of
haskell-language-server --probe-tools
orhaskell-language-server-wrapper --probe-tools
:askell-language-server version: 1.3.0.0 (GHC: 8.10.4) (PATH: /Users/emilypi/.ghcup/bin/haskell-language-server-wrapper-1.3.0) (GIT hash: e7c5e90b6df5dff2760d76169eddaea3bdd6a831) Tool versions found on the $PATH cabal: 3.4.0.0 stack: 2.5.1 ghc: 8.10.4
Which OS do you use:
MacOS Big Sure
Which lsp-client do you use:
Emacs
Describe your project (alternative: link to the project):
*.cabal files, cabal.project
Contents of
hie.yaml
:Steps to reproduce
Expected behaviour
Imports should be inserted in correct area of the module.
Actual behaviour
The first import is inserted above the first signicant decl, regardless of comments.
The text was updated successfully, but these errors were encountered: