Comments renaming should not be allowed
Your environment
Which OS do you use?
Operating System: openSUSE Tumbleweed 20231206 KDE Plasma Version: 5.27.9 KDE Frameworks Version: 5.112.0 Qt Version: 5.15.11 Kernel Version: 6.6.3-1-default (64-bit) Graphics Platform: X11
Which version of GHC do you use and how did you install it?
Output of haskell-language-server-wrapper --probe-tools:
haskell-language-server version: 2.4.0.0 (GHC: 9.0.2) (PATH: /home/az/.ghcup/hls/2.4.0.0/lib/haskell-language-server-2.4.0.0/bin/haskell-language-server-wrapper)
Tool versions found on the $PATH
cabal: 3.6.2.1
stack: 2.11.1
ghc: 9.4.7
Tool versions in your project
2023-12-18T06:37:13.171524Z | Debug | executing command: ghc --numeric-version
ghc: 9.4.7
Installed via curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
How is your project built (alternative: link to the project)?
N/A
Which LSP client (editor/plugin) do you use?
VSCode 1.85.0 + haskell.haskell 2.4.2
Which version of HLS do you use and how did you install it?
See above.
Have you configured HLS in any way (especially: a hie.yaml file)?
No.
Steps to reproduce
I discovered the issue accidentally when using a spell checker to correct a typo in my comment. But it caused an error message from HLS. These are the steps to reproduce:
-
Open a
.hsfile and place the cursor on a comment. -
Press
F2. -
The word will be prompted to rename.
-
Enter a new word and press
Enter, error occurs:
Expected behaviour
Renaming comments should never be allowed, i.e, pressing F2 on comments should have no effect at all.
Actual behaviour
There is a renaming prompt but renaming will eventually cause error.
Include debug information
Execute in the root of your project the command haskell-language-server-wrapper --debug . and paste the logs here (you can find the executable location here):
Debug output:
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.4.0.0 x86_64 ghc-9.0.2
Current directory: /home/az/workspace/playground-Haskell/playground/Penn-spring-15
Operating system: linux
Arguments: ["--debug","."]
Cradle directory: /home/az/workspace/playground-Haskell/playground/Penn-spring-15
Cradle type: Default
Tool versions found on the $PATH
cabal: 3.6.2.1
stack: 2.11.1
ghc: 9.4.7
Consulting the cradle to get project GHC version...
2023-12-19T08:59:14.336850Z | Debug | executing command: ghc --numeric-version
Project GHC version: 9.4.7
haskell-language-server exe candidates: ["haskell-language-server-9.4.7","haskell-language-server"]
Launching haskell-language-server exe at:/home/az/.ghcup/bin/haskell-language-server-9.4.7
2023-12-19T08:59:14.370612Z | Debug | executing command: ghc -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2023-12-19T08:59:14.465947Z | Debug | executing command: ghc --print-libdir
2023-12-19T08:59:15.952401Z | Info | haskell-language-server version: 2.4.0.0 (GHC: 9.4.7) (PATH: /home/az/.ghcup/hls/2.4.0.0/lib/haskell-language-server-2.4.0.0/bin/haskell-language-server-9.4.7)
2023-12-19T08:59:15.953132Z | Info | Directory: /home/az/workspace/playground-Haskell/playground/Penn-spring-15
2023-12-19T08:59:15.953370Z | Info | Logging heap statistics every 60.00s
ghcide setup tester in /home/az/workspace/playground-Haskell/playground/Penn-spring-15.
Report bugs at https://github.com/haskell/haskell-language-server/issues
Step 1/4: Finding files to test in /home/az/workspace/playground-Haskell/playground/Penn-spring-15
Found 2 files
Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
()
Step 3/4: Initializing the IDE
2023-12-19T08:59:16.043207Z | Debug | Initializing exports map from hiedb
2023-12-19T08:59:16.044802Z | Debug | Shake session initialized
Step 4/4: Type checkin2023-12-19T08:59:16.045101Z | Debug | Done initializing exports map from hiedb. Size: 0
g the files
2023-12-19T08:59:16.051016Z | Info | Cradle path: 01-intro.hs
2023-12-19T08:59:16.051689Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for 01-intro.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.
2023-12-19T08:59:16.079383Z | Debug | Cradle: Cradle {cradleRootDir = "/home/az/workspace/playground-Haskell/playground/Penn-spring-15", cradleOptsProg = CradleAction: Default}
2023-12-19T08:59:16.079586Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2023-12-19T08:59:16.079977Z | Debug | executing command: ghc --print-libdir
2023-12-19T08:59:16.116266Z | Debug | Session loading result: Right (ComponentOptions {componentOptions = ["-dynamic"], componentRoot = "/home/az/workspace/playground-Haskell/playground/Penn-spring-15", componentDependencies = []},"/home/az/.ghcup/ghc/9.4.7/lib64/ghc-9.4.7/lib")
2023-12-19T08:59:16.147423Z | Info | Interface files cache directory: /home/az/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda-1a596a151463f2c53ee4feb14ecd276a1ccebfda
2023-12-19T08:59:16.147783Z | Info | Making new HscEnv. In-place unit ids: [ main-1a596a151463f2c53ee4feb14ecd276a1ccebfda ]
2023-12-19T08:59:16.174230Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 4),fromList [])
2023-12-19T08:59:16.174546Z | Debug | Known files updated:
fromList [(TargetFile NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs",fromList ["/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs"])]
2023-12-19T08:59:16.175015Z | Debug | Finished build session
AsyncCancelled
2023-12-19T08:59:16.175136Z | Debug | Restarting build session due to new component
Action Queue: [User TypeCheck]
Keys: [GhcSessionIO; , GetKnownTargets; ]
Aborting previous build session took 0.00s
2023-12-19T08:59:16.176152Z | Debug | hlint: Getting hlint ideas for NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs"
2023-12-19T08:59:16.176388Z | Debug | hlint: Getting hlint ideas for NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/02-poly-FPP.hs"
2023-12-19T08:59:16.240635Z | Info | Cradle path: 02-poly-FPP.hs
2023-12-19T08:59:16.240815Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for 02-poly-FPP.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.
2023-12-19T08:59:16.248616Z | Debug | Cradle: Cradle {cradleRootDir = "/home/az/workspace/playground-Haskell/playground/Penn-spring-15", cradleOptsProg = CradleAction: Default}
2023-12-19T08:59:16.248719Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2023-12-19T08:59:16.248932Z | Debug | executing command: ghc --print-libdir
2023-12-19T08:59:16.360446Z | Debug | Session loading result: Right (ComponentOptions {componentOptions = ["-dynamic"], componentRoot = "/home/az/workspace/playground-Haskell/playground/Penn-spring-15", componentDependencies = []},"/home/az/.ghcup/ghc/9.4.7/lib64/ghc-9.4.7/lib")
2023-12-19T08:59:16.426082Z | Info | Interface files cache directory: /home/az/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda-1a596a151463f2c53ee4feb14ecd276a1ccebfda
2023-12-19T08:59:16.426595Z | Info | Interface files cache directory: /home/az/.cache/ghcide/main-1a596a151463f2c53ee4feb14ecd276a1ccebfda-1a596a151463f2c53ee4feb14ecd276a1ccebfda
2023-12-19T08:59:16.427516Z | Info | Making new HscEnv. In-place unit ids: [ main-1a596a151463f2c53ee4feb14ecd276a1ccebfda
, main-1a596a151463f2c53ee4feb14ecd276a1ccebfda ]
2023-12-19T08:59:16.436604Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 6),fromList [])
2023-12-19T08:59:16.465046Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 7),fromList [])
2023-12-19T08:59:16.465276Z | Debug | Known files updated:
fromList [(TargetFile NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/02-poly-FPP.hs",fromList ["/home/az/workspace/playground-Haskell/playground/Penn-spring-15/02-poly-FPP.hs"]),(TargetFile NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs",fromList ["/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs"])]
2023-12-19T08:59:16.502470Z | Debug | Finished build session
AsyncCancelled
2023-12-19T08:59:16.502560Z | Debug | Restarting build session due to new component
Action Queue: [User TypeCheck]
Keys: [GhcSessionIO; ]
Aborting previous build session took 0.04s
2023-12-19T08:59:16.502692Z | Debug | hlint: Getting hlint ideas for NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs"
2023-12-19T08:59:16.520457Z | Debug | hlint: Getting hlint ideas for NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/02-poly-FPP.hs"
2023-12-19T08:59:16.711449Z | Debug | hlint: Using extensions for NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.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 ]
2023-12-19T08:59:16.900538Z | Debug | hlint: Using extensions for NormalizedFilePath "/home/az/workspace/playground-Haskell/playground/Penn-spring-15/02-poly-FPP.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 ]
2023-12-19T08:59:16.990386Z | Info | hlint: updateFileDiagnostics published different from new diagnostics - file diagnostics: File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 105:8-105:21
Source: hlint
Severity: DiagnosticSeverity_Information
Message: EvaluateFound:True && FalseWhy not:False
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 107:13-107:26
Source: hlint
Severity: DiagnosticSeverity_Information
Message: EvaluateFound:False || TrueWhy not:True
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 109:8-109:20
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Redundant bracketFound:('a' == 'a')Why not:'a' == 'a'
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 111:8-111:17
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Redundant bracketFound:(16 /= 3)Why not:16 /= 3
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 134:5-134:19
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Use evenFound:n `mod` 2 == 0Why not:even n
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 208:8-208:14
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Use list literalFound:1 : []Why not:[1]
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 210:8-210:20
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Use list literalFound:3 : (1 : [])Why not:[3, 1]
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 212:8-212:22
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Use list literalFound:2 : 3 : 4 : []Why not:[2, 3, 4]
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 214:21-214:35
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Use list literalFound:2 : 3 : 4 : []Why not:[2, 3, 4]
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 225:1-227:46
Source: hlint
Severity: DiagnosticSeverity_Information
Message:
Use foldr
Found:
intListLength [] = 0
intListLength (x : xs) = 1 + intListLength xs
Why not:
intListLength xs = foldr (\ x -> (+) 1) 0 xs
File: /home/az/workspace/playground-Haskell/playground/Penn-spring-15/01-intro.hs
Hidden: no
Range: 232:13-232:21
Source: hlint
Severity: DiagnosticSeverity_Information
Message: Use list literal patternFound:(x : [])Why not:[x]
2023-12-19T08:59:17.008159Z | Debug | Finished: User TypeCheck Took: 0.51s
2023-12-19T08:59:17.036935Z | Debug | Finished: GetHie Took: 0.02s
2023-12-19T08:59:17.038173Z | Debug | Finished: GenerateCore Took: 0.00s
Completed (2 files worked, 0 files failed)
Paste the contents of extension specific log, you can check instructions about how to find it here
Extension log:
2023-12-19T09:00:58.657929Z | Error | rename: Internal Error: Renaming of an imported name is unsupported
[Error - 5:00:58 PM] Request textDocument/rename failed.
Message: rename: Internal Error: Renaming of an imported name is unsupported
Code: -32603
2023-12-19T09:01:05.695432Z | Info | Live bytes: 410.59MB Heap size: 1522.53MB
2023-12-19T09:01:18.237218Z | Warning | LSP: no handler for: "$/setTrace"
2023-12-19T09:01:41.353329Z | Warning | LSP: no handler for: "$/setTrace"
2023-12-19T09:02:05.740575Z | Info | Live bytes: 410.59MB Heap size: 1522.53MB
2023-12-19T09:03:05.741596Z | Info | Live bytes: 410.59MB Heap size: 1522.53MB
Thank you for the bug report!
Moving this to the main repo as this feature is provided by HLS.
Fix implemented in https://github.com/haskell/haskell-language-server/pull/4111 which leverages Prepare rename lsp method to prevent client from creating rename requests for things that can't be renamed (stuff within comments, keywords etc.). Also the error handling was improved in cases where clients sends invalid rename request anyway.