haskell / haskell-language-server

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

Errors get mixed up after edit #167

Closed itsfarseen closed 10 months ago

itsfarseen commented 4 years ago

I'm using Neovim + Coc.nvim + HLS.

Suppose I have a function with a bunch of errors: hls1

Now I fix one of those errors. But the error doesn't disappear yet. hls2

Curiously, a new error has appeared. Looks like HLS misplaces the text I just inserted earlier into the next line. gGetState is juxtaposed onto doVarDeclare "foo" TypeInt. There wasn't an error in this line before. hls3

Reloading the file using :e in neovim fixes the misplaced errors. So does :CocRestart. Anecdotally, this has happened before in HLS + VSCode.

itsfarseen commented 4 years ago

Here's a minimal repro: https://github.com/happycoder97/hls-wierd-error-repro Screenshot: hlsrepro

Here, "STOP"a is read as "STOP" aa.

PS: I tried this one more time, but it didn't cause misplaced errors this time.

itsfarseen commented 4 years ago

This happens almost every time in my project here: https://github.com/happycoder97/compiler-lab-nitc . But I can't reliably reproduce it in smaller projects.

Avi-D-coder commented 4 years ago

Can you post a debug log

itsfarseen commented 4 years ago

Note: I got these logs from :CocCommand workspace.showOutput. Kindly let me know if you need a different log.

Debug log:

ghcide version: 0.1.0.0 (GHC: 8.8.3) (PATH: /home/farzeen/.local/bin/h
askell-language-server-wrapper) (GIT hash: d2654185eef1b0d703cebc694e8
5438e20600e37)
g
hcide version: 0.1.0.0 (GHC: 8.8.3) (PATH: /home/farzeen
/.local/bin/haskell-language-ser
ver-8.8.3) (GIT hash: d2654185ee
f1b0d703cebc694e85438e20600e37)
Sta
rting (haskell-language-server)LSP
 server...
  with arguments: A
rguments {argLSP = True, argsC
wd = Nothing, argFiles = [], ar
gsVersion = False, argsShak
eProfiling = Nothing, argsT
esting = False, argsExampleP
lugin = False, argsDebugOn =
 False, argsLogFile = N
othing, argsThreads = 1}

 with plugins: [Plugin
Id "brittany",PluginId "f
loskell",PluginId "ghcide"
,PluginId "ormolu",PluginId 
"pragmas",PluginId "sty
lish-haskell"]
If you are
 seeing this in a terminal,
 you probably should have r
un ghcide WITHOUT the --l
sp option!

Started LS
P server in 0.01s
2020-06-19 21:01:33.817906167 [ThreadId 9] - Opened text document: file:///media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/Grammar.hs
Consulting the cradle for "/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/Grammar.hs"
> Using main module: 1. Package `CompilerLab' component CompilerLab:test:test with main-is file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Main.hs
> The following GHC options are incompatible with GHCi and have not been passed to it: -O0
> Configuring GHCi with the following packages: CompilerLab
> 
> Warning: Didn't find expected autogen file:
>          /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/test/autogen/cabal_macros.h
> /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/install/x86_64-linux-tinfo6/607c143364e763a7367bb164afd98c5142cd57441210e89197a284a68ba91b4a/8.8.3/pkgdb:/media/linux2/home.stack/snapshots/x86_64-linux-tinfo6/607c143364e763a7367bb164afd98c5142cd57441210e89197a284a68ba91b4a/8.8.3/pkgdb:/media/linux2/home.stack/programs/x86_64-linux/ghc-tinfo6-8.8.3/lib/ghc-8.8.3/package.conf.d
Right (ComponentOptions {componentOptions = ["-i","-odir=/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/odir","-hidir=/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/odir","-hide-all-packages","-i/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/test","-i/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests","-i/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/lib","-i/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/test/autogen","-i/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/global-autogen","-i/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/test/test-tmp","-stubdir=/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build","-package-id=base-4.13.0.0","-package-id=array-0.5.4.0","-package-id=directory-1.3.6.0","-package-id=errors-2.3.0-CZhgfPaBXTPCfGic2ImHVz","-package-id=extra-1.7.3-9ADZwIWVgpD4k272huY0G3","-package-id=filepath-1.4.2.1","-package-id=flow-1.0.21-DML4FjglMQl1JD228dkjZI","-package-id=mtl-2.2.2","-package-id=tasty-1.2.3-LtPeLd2EnbBKYZJAnJoZU2","-package-id=tasty-hunit-0.10.0.2-4WSPXWptOidLICn8Z96nuN","-package-id=tasty-golden-2.3.3.2-IrlWdDX4AdxIlSD50PPz76","-package-id=unordered-containers-0.2.10.0-KujsThAgCnwGXBG7PJnkNO","-package-id=utf8-string-1.0.1.1-IRxNMq5AVf036EceEkASq3","-package-id=bytestring-0.10.10.0","-Wall","-Wno-name-shadowing","-j8","-fprof-auto","-fprof-cafs","-ghci-script=/tmp/haskell-stack-ghci/1a7b97da/ghci-script","-package-db","/media/linux2/Projects/10.BTechCSE/S6/CompilerLab/.stack-work/install/x86_64-linux-tinfo6/607c143364e763a7367bb164afd98c5142cd57441210e89197a284a68ba91b4a/8.8.3/pkgdb","-package-db","/media/linux2/home.stack/snapshots/x86_64-linux-tinfo6/607c143364e763a7367bb164afd98c5142cd57441210e89197a284a68ba91b4a/8.8.3/pkgdb","-package-db","/media/linux2/home.stack/programs/x86_64-linux/ghc-tinfo6-8.8.3/lib/ghc-8.8.3/package.conf.d"], componentRoot = "/media/linux2/Projects/10.BTechCSE/S6/CompilerLab", componentDependencies = ["CompilerLab.cabal","package.yaml","stack.yaml"]})
"Making new HscEnv[main]"
(([],Just HscEnvEq 4),fromList [("CompilerLab.cabal",Just 2020-06-17 13:50:38.7997132 UTC),("package.yaml",Nothing),("stack.yaml",Just 2020-06-18 06:09:45.093197807 UTC)])
2020-06-19 21:01:35.798204145 [ThreadId 678] - finish: FileStoreTC (took 1.98s)
2020-06-19 21:01:36.02151702 [ThreadId 1768] - finish: InitialLoad (took 0.22s)
2020-
06-19 21:01:36.456855068 [ThreadId 1770] - DocumentHigh
light request at position 79:3 
in file: /media/linux2/Proj
ects/10.BTechCSE/S6/Compi
lerLab/tests/Test/Grammar.hs

2020-06-19 21:01:56.639438014 [ThreadId 9] - Modified text document: file:///media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/Grammar.hs
2020-06-19 21:01:56.818919627 [ThreadId 2358] - finish: FileStoreTC (took 0.18s)
2020-06-19
 21:02:06.007000389 [ThreadId 2360] - DocumentHighlight request at posi
tion 79:20 in file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/test
s/Test/Grammar.hs
2020-06-19 21:02:09
.008806828 [ThreadId 2605] - DocumentHighlight request at position 79:20 in
 file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/Grammar.
hs
2020-06-19 21:02:16.930690913 [ThreadId 9] - Modified text document: file:///media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/Grammar.hs
2020-06-19 21:02:16.937871911 [ThreadId 2870] - finish: FileStoreTC (took 0.01s)
2020-06-19 2
1:02:17.808140526 [ThreadId 2896] - DocumentHighlight request at positio
n 83:7 in file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/
Test/Grammar.hs
2020-0
6-19 21:02:21.971831884 [ThreadId 2920] - DocumentHighlight request at position 8
3:7 in file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/Gr
ammar.hs
2020-06-19
 21:02:22.447439042 [ThreadId 2942] - DocumentHighlight request at position
 83:7 in file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/T
est/Gram
mar.hs
2020-0
6-19 21:02:25.314545537 [ThreadId 2964] - DocumentHighlight request at positi
on 83:7 in file: /media/linux2/Projects/10.BTechCSE/S6/CompilerLab/tests/Test/G
rammar.hs

Screenshots to show when those debug log got generated:

Opened the file, all errors are showing correctly. 2020-06-19-210153_1366x768_scrot

Fixed an error, diagnostics still shows it as error. 2020-06-19-210211_1366x768_scrot

Added a after syms in line 83. Something wierd happened. 2020-06-19-210230_1366x768_scrot

jneira commented 3 years ago

Any vim/neovim user could try to reproduce the problem?

teto commented 3 years ago

I haven't had this issue with native LSP so maybe some coc issue. Last week an update was made in neovim that breaks hls + neovim but not sure which is the culprit

Doing

lspconfig.hls.setup({
       ...
    flags = {
        allow_incremental_sync = false;
    }
})

fixes it.

mjlbach commented 3 years ago

I guess the question is what could be causing an issue for HLS when using incremental sync with text ranges. Previously we sent the full buffer on each text change, but now we match vscode/coc and send only the change from the last edit. It works fine with every other language server that I can see.

florentc commented 3 years ago

I often run into the same issue with neovim native LSP client and hls. I have yet to find how to reliably reproduce the issue.

michaelpj commented 10 months ago

Tentatively closing as no new reports recently.