haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Refactoring type constructor of data incorrectly renames the record fields too #4083

Closed Aster89 closed 7 months ago

Aster89 commented 8 months ago

Your environment

Which OS do you use? ArchLinux (up-to-date) Which version of GHC do you use and how did you install it? 9.4.8, via GHCup How is your project built (alternative: link to the project)? Irrelevant, I just open a new file

Which LSP client (editor/plugin) do you use? Vim(terminal) + YCM Which version of HLS do you use and how did you install it? 2.5.0.0, via GHCup Have you configured HLS in any way (especially: a hie.yaml file)? ... I think I haven't...

Steps to reproduce

  1. Create a one-line file with content data Foo = Bar { a :: !Int , b :: !Int }
  2. put the cursor try to refactor Bar to be Baz

Expected behaviour

The code should be become

data Foo = Bar { a :: !Int , b :: !Int }

Actual behaviour

But it becomes

data Foo = Baz { Baz :: !Int , Baz :: !Int }

Debug information

Is this the relevant piece?

2024-02-17 16:01:41,666 - DEBUG - TX: Sending message: b'Content-Length: 172\r\n\r\n{"id":2,"jsonrpc":"2.0","method":"textDocument/rename","params":{"newName":"Baz","position":{"character":13,"line":0},"textDocument":{"uri":"file:///home/enrico/uffa.hs"}}}'
2024-02-17 16:01:41,690 - DEBUG - RX: Received message: b'{"id":2,"jsonrpc":"2.0","result":{"documentChanges":[{"edits":[{"newText":"data Foo = Baz { Baz :: !Int , Baz :: !Int }","range":{"end":{"character":40,"line":0},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///home/enrico/uffa.hs","version":1}}]}}'
127.0.0.1 - - [17/Feb/2024 16:01:41] "POST /run_completer_command HTTP/1.1" 200 348
2024-02-17 16:01:41,693 - DEBUG - in-event <InotifyEvent: src_path=b'/home/enrico/.uffa.hs.swp', wd=1, mask=IN_MODIFY, cookie=0, name='.uffa.hs.swp'>
2024-02-17 16:01:41,713 - DEBUG - Event name: FileReadyToParse
2024-02-17 16:01:41,713 - INFO - Adding buffer identifiers for file: /home/enrico/uffa.hs
2024-02-17 16:01:41,714 - DEBUG - Refreshing file /home/enrico/uffa.hs: State is Open -> Open/action Change
2024-02-17 16:01:41,714 - DEBUG - TX: Sending notification: b'Content-Length: 204\r\n\r\n{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"text":"data Foo = Baz { Baz :: !Int , Baz :: !Int }\\n"}],"textDocument":{"uri":"file:///home/enrico/uffa.hs","version":2}}}'
127.0.0.1 - - [17/Feb/2024 16:01:41] "POST /event_notification HTTP/1.1" 200 2
2024-02-17 16:01:41,717 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"message":"parse error on input \xe2\x80\x98Baz\xe2\x80\x99","range":{"end":{"character":20,"line":0},"start":{"character":17,"line":0}},"severity":1,"source":"parser"}],"uri":"file:///home/enrico/uffa.hs","version":2}}'
Aster89 commented 8 months ago

I'm trying to understand how to give you the HLS logs directly, rather than those represented by YCM.


This should be the HLS log.... no?

No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.5.0.0 x86_64 ghc-9.2.8
Current directory: /home/enrico
Operating system: linux
Arguments: ["--lsp","--debug"]
Cradle directory: /home/enrico
Cradle type: Default

Tool versions found on the $PATH
cabal:          3.10.2.1
stack:          Not found
ghc:            9.4.8

Consulting the cradle to get project GHC version...
2024-02-17T17:05:08.269547Z | Debug | executing command: ghc --numeric-version
Project GHC version: 9.4.8
haskell-language-server exe candidates: ["haskell-language-server-9.4.8","haskell-language-server"]
Launching haskell-language-server exe at:/home/enrico/.ghcup/bin/haskell-language-server-9.4.8
2024-02-17T17:05:08.299201Z | Debug | executing command: ghc -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2024-02-17T17:05:08.389790Z | Debug | executing command: ghc --print-libdir
2024-02-17T17:05:09.731038Z | Info | haskell-language-server version: 2.5.0.0 (GHC: 9.4.8) (PATH: /home/enrico/.ghcup/hls/2.5.0.0/lib/haskell-language-server-2.5.0.0/bin/haskell-language-server-9.4.8)
2024-02-17T17:05:09.731764Z | Info | Directory: /home/enrico
2024-02-17T17:05:09.731863Z | Info | Starting (haskell-language-server) LSP server...
  GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsLogLevel = Debug, argsLogFile = Nothing, argsLogStderr = True, argsLogClient = False, argsThreads = 0, argsProjectGhcVersion = False}
  PluginIds: [ pragmas-suggest
             , pragmas-completion
             , retrie
             , ghcide-completions
             , alternateNumberFormat
             , ghcide-code-actions-bindings
             , explicit-fields
             , ghcide-hover-and-symbols
             , ghcide-code-actions-type-signatures
             , floskell
             , fourmolu
             , ghcide-extend-import-action
             , ghcide-code-actions-fill-holes
             , importLens
             , LSPRecorderCallback
             , cabal
             , qualifyImportedNames
             , moduleName
             , splice
             , stylish-haskell
             , changeTypeSignature
             , hlint
             , class
             , ormolu
             , callHierarchy
             , stan
             , ghcide-type-lenses
             , codeRange
             , cabal-fmt
             , eval
             , rename
             , ghcide-code-actions-imports-exports
             , gadt
             , overloaded-record-dot
             , ghcide-core
             , explicit-fixity
             , pragmas-disable ]
2024-02-17T17:05:09.733423Z | Info | Logging heap statistics every 60.00s
 2024-02-17T17:05:09.736818Z | Info | Starting LSP server...
  If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
  PluginIds: [ pragmas-suggest
             , pragmas-completion
             , retrie
             , ghcide-completions
             , alternateNumberFormat
             , ghcide-code-actions-bindings
             , explicit-fields
             , ghcide-hover-and-symbols
             , ghcide-code-actions-type-signatures
             , floskell
             , fourmolu
             , ghcide-extend-import-action
             , ghcide-code-actions-fill-holes
             , importLens
             , LSPRecorderCallback
             , cabal
             , qualifyImportedNames
             , moduleName
             , splice
             , stylish-haskell
             , changeTypeSignature
             , hlint
             , class
             , ormolu
             , callHierarchy
             , stan
             , ghcide-type-lenses
             , codeRange
             , cabal-fmt
             , eval
             , rename
             , ghcide-code-actions-imports-exports
             , gadt
             , overloaded-record-dot
             , ghcide-core
             , explicit-fixity
             , pragmas-disable ]
2024-02-17T17:05:09.737143Z | Info | Starting server
2024-02-17T17:05:09.738121Z | Debug | LSP: set new config: {  }
2024-02-17T17:05:09.738577Z | Info | Started LSP server in 0.00s
2024-02-17T17:05:09.742851Z | Debug | executing command: ghc --print-libdir
2024-02-17T17:05:09.776673Z | Debug | Setting initial dynflags...
2024-02-17T17:05:09.776790Z | Debug | shouldRunSubset: True
2024-02-17T17:05:09.776905Z | Debug | Initializing exports map from hiedb
2024-02-17T17:05:09.777136Z | Info | Registering IDE configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 7627154443253916145 "file:///home/enrico"], clientSettings = hashed (Just (Object (fromList [])))}
2024-02-17T17:05:09.778344Z | Debug | LSP: not requesting configuration since the client does not support workspace/configuration
2024-02-17T17:05:09.778447Z | Debug | LSP: set new config: {  }
2024-02-17T17:05:09.778489Z | Debug | Configuration changed: Config {checkParents = CheckOnSave, checkProject = True, formattingProvider = "ormolu", cabalFormattingProvider = "cabal-fmt", maxCompletions = 40, plugins = fromList []}
2024-02-17T17:05:09.779552Z | Debug | Shake session initialized
2024-02-17T17:05:09.780229Z | Debug | Finished build session
AsyncCancelled
2024-02-17T17:05:09.780232Z | Debug | Restarting build session due to config change
Action Queue: []
Keys: [GetClientSettings; ]
Aborting previous build session took 0.00s 
2024-02-17T17:05:09.780424Z | Debug | Done initializing exports map from hiedb. Size: 7
2024-02-17T17:05:09.780443Z | Debug | LSP: not requesting configuration since the client does not support workspace/configuration
2024-02-17T17:05:09.780632Z | Debug | VFS: opening file:///home/enrico/uffa.hs
2024-02-17T17:05:09.780950Z | Debug | Set files of interest to: fromList [(NormalizedFilePath "/home/enrico/uffa.hs",Modified {firstOpen = True})]
2024-02-17T17:05:09.781174Z | Debug | Finished build session
AsyncCancelled
2024-02-17T17:05:09.781188Z | Debug | Restarting build session due to /home/enrico/uffa.hs (modified)
Action Queue: []
Keys: [ GetClientSettings; 
      , IsFileOfInterest; /home/enrico/uffa.hs
      , GetModificationTime; /home/enrico/uffa.hs ]
Aborting previous build session took 0.00s 
2024-02-17T17:05:09.781370Z | Debug | Opened text document: file:///home/enrico/uffa.hs
2024-02-17T17:05:09.781678Z | Debug | hlint: Getting hlint ideas for  NormalizedFilePath "/home/enrico/uffa.hs"
2024-02-17T17:05:09.782118Z | Info | Cradle path: uffa.hs
2024-02-17T17:05:09.782217Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for uffa.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2024-02-17T17:05:09.789341Z | Debug | Cradle: Cradle {cradleRootDir = "/home/enrico", cradleOptsProg = CradleAction: Default}
2024-02-17T17:05:09.789428Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2024-02-17T17:05:09.789560Z | Debug | executing command: ghc --print-libdir
2024-02-17T17:05:09.825376Z | Debug | Session loading result: Right (ComponentOptions {componentOptions = ["-dynamic"], componentRoot = "/home/enrico", componentDependencies = []},"/home/enrico/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/lib")
2024-02-17T17:05:09.853990Z | Info | Interface files cache directory: /home/enrico/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda-1a596a151463f2c53ee4feb14ecd276a1ccebfda
2024-02-17T17:05:09.854390Z | Info | Making new HscEnv. In-place unit ids: [ main-1a596a151463f2c53ee4feb14ecd276a1ccebfda ]
2024-02-17T17:05:09.894806Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 5),fromList [])
2024-02-17T17:05:09.894922Z | Debug | Known files updated:
  fromList [(TargetFile NormalizedFilePath "/home/enrico/uffa.hs",fromList ["/home/enrico/uffa.hs"])]
2024-02-17T17:05:09.895380Z | Debug | Finished build session
AsyncCancelled
2024-02-17T17:05:09.895429Z | Debug | Restarting build session due to new component
Action Queue: []
Keys: [ IsFileOfInterest; /home/enrico/uffa.hs
      , GetModificationTime; /home/enrico/uffa.hs
      , GhcSessionIO; 
      , GetKnownTargets;  ]
Aborting previous build session took 0.00s 
2024-02-17T17:05:09.895701Z | Debug | hlint: Getting hlint ideas for  NormalizedFilePath "/home/enrico/uffa.hs"
2024-02-17T17:05:09.906821Z | Debug | Finished: InitialLoad Took: 0.01s
2024-02-17T17:05:10.058026Z | Debug | hlint: Using extensions for  NormalizedFilePath "/home/enrico/uffa.hs": [ MonomorphismRestriction
                                                                        , RelaxedPolyRec
                                                                        , ForeignFunctionInterface
                                                                        , ImplicitPrelude
                                                                        , ScopedTypeVariables
                                                                        , BangPatterns
                                                                        , NamedFieldPuns
                                                                        , GADTSyntax
                                                                        , DoAndIfThenElse
                                                                        , ConstraintKinds
                                                                        , PolyKinds
                                                                        , InstanceSigs
                                                                        , StandaloneDeriving
                                                                        , DeriveDataTypeable
                                                                        , DeriveFunctor
                                                                        , DeriveTraversable
                                                                        , DeriveFoldable
                                                                        , DeriveGeneric
                                                                        , DeriveLift
                                                                        , TypeSynonymInstances
                                                                        , FlexibleContexts
                                                                        , FlexibleInstances
                                                                        , ConstrainedClassMethods
                                                                        , MultiParamTypeClasses
                                                                        , ExistentialQuantification
                                                                        , EmptyDataDecls
                                                                        , KindSignatures
                                                                        , GeneralizedNewtypeDeriving
                                                                        , PostfixOperators
                                                                        , TupleSections
                                                                        , PatternGuards
                                                                        , RankNTypes
                                                                        , TypeOperators
                                                                        , ExplicitForAll
                                                                        , TraditionalRecordSyntax
                                                                        , BinaryLiterals
                                                                        , HexFloatLiterals
                                                                        , EmptyCase
                                                                        , NamedWildCards
                                                                        , TypeApplications
                                                                        , EmptyDataDeriving
                                                                        , NumericUnderscores
                                                                        , StarIsType
                                                                        , ImportQualifiedPost
                                                                        , StandaloneKindSignatures
                                                                        , FieldSelectors ]
2024-02-17T17:05:28.972875Z | Debug | Finished: Rename.GetHieAst Took: 0.00s
2024-02-17T17:05:28.972992Z | Debug | Finished: Rename.HieDb Took: 0.00s
2024-02-17T17:05:28.973124Z | Debug | Finished: Rename.GetHieAst Took: 0.00s
2024-02-17T17:05:28.974547Z | Debug | Finished: Rename.GetHieAst Took: 0.00s
2024-02-17T17:05:28.975082Z | Debug | Finished: Rename.GetHieAst Took: 0.00s
2024-02-17T17:05:28.975630Z | Debug | Finished: Rename.GetHieAst Took: 0.00s
2024-02-17T17:05:28.975776Z | Debug | Finished: Rename.HieDb Took: 0.00s
2024-02-17T17:05:28.975890Z | Debug | Finished: Rename.GetHieAst Took: 0.00s
2024-02-17T17:05:28.976356Z | Debug | Finished: rename: config Took: 0.00s
2024-02-17T17:05:28.976690Z | Debug | Finished: Rename.GetParsedModule Took: 0.00s
2024-02-17T17:05:28.977716Z | Debug | Finished: Rename.GetAnnotatedParsedSource Took: 0.00s
2024-02-17T17:05:29.005507Z | Debug | Set files of interest to: fromList [(NormalizedFilePath "/home/enrico/uffa.hs",Modified {firstOpen = False})]
2024-02-17T17:05:29.005762Z | Debug | Finished build session
AsyncCancelled
2024-02-17T17:05:29.005768Z | Debug | Restarting build session due to /home/enrico/uffa.hs (modified)
Action Queue: []
Keys: [ IsFileOfInterest; /home/enrico/uffa.hs
      , GetModificationTime; /home/enrico/uffa.hs
      , GetModificationTime; /home/enrico/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda-1a596a151463f2c53ee4feb14ecd276a1ccebfda/_home_enrico_uffa/hs.hie ]
Aborting previous build session took 0.00s 
2024-02-17T17:05:29.006048Z | Debug | Modified text document: file:///home/enrico/uffa.hs
2024-02-17T17:05:29.007617Z | Debug | hlint: Getting hlint ideas for  NormalizedFilePath "/home/enrico/uffa.hs"
2024-02-17T17:06:09.773100Z | Info | Live bytes: 21.75MB Heap size: 581.96MB
jhrcek commented 8 months ago

Thanks for the bug report! In this case logs are not necessary, the reproducer you described is sufficient (I managed to reproduce it too). I'll look into this and try to fix it.

fendor commented 8 months ago

@jhrcek FWIW, I think this is relatively well-known and a bug in hiedb.

theGhostJW commented 8 months ago

perhaps @fendor is referring to this: https://github.com/wz1000/HieDb/issues/45

also looks like this has been logged before: https://github.com/haskell/haskell-language-server/issues/2915

fendor commented 7 months ago

Closing in favour of #2915