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 366 forks source link

Completions not show up after typing a few lines #2149

Closed aplqo closed 2 years ago

aplqo commented 3 years ago

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.0.0.0 (GHC: 8.8.4) (PATH: /home/aplqo/.local/bin/haskell-language-server) (GIT hash: 4cd1cf934638881e52b3eba9f70157a4b799c0e9)
Tool versions found on the $PATH
cabal:      3.0.0.0
stack:      Not found
ghc:        8.8.4

Which OS do you use: Debian bullseye Which lsp-client do you use: vim with coc Describe your project (alternative: link to the project): single file or cabal Contents of hie.yaml:

cradle:
  direct:
    arguments: []

Steps to reproduce

Create a blank file then type code.

Expected behaviour

Completion shows up while typing

Actual behaviour

Completion stop showing up after typing a few lines. But coc with hls 0.9.0 or vscode with hls 1.3.0 don’t have that problem.

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output: 1.0.0 log ``` haskell-language-server version: 1.0.0.0 (GHC: 8.8.4) (PATH: /home/aplqo/.local/bin/haskell-language-server) (GIT hash: 4cd1cf934638881e52b3eba9f70157a4b799c0e9) 2021-08-31 23:32:19.406748939 [ThreadId 4] DEBUG hls: Set files of interest to: [(NormalizedFilePath "/home/aplqo/test/Test.hs",OnDisk)] 2021-08-31 23:32:19.407850068 [ThreadId 29] INFO hls: File: Hidden: no Range: 1:1-2:1 Source: compiler Severity: DsError Message: Internal error, getIdeGlobalExtras, no entry for IdeConfigurationVar CallStack (from HasCallStack): errorIO, called at src/Development/IDE/Core/Shake.hs:284:20 in ghcide-1.0.0.0-inplace:Development.IDE.Core.Shake 2021-08-31 23:32:19.408109074 [ThreadId 28] INFO hls: Consulting the cradle for "Test.hs" Output from setting up the cradle Cradle {cradleRootDir = "/home/aplqo/test", cradleOptsProg = CradleAction: Direct} 2021-08-31 23:32:19.45423619 [ThreadId 28] DEBUG hls: Session loading result: Right (ComponentOptions {componentOptions = [], componentRoot = "/home/aplqo/test", componentDependencies = []},"/usr/lib/ghc") 2021-08-31 23:32:19.508225513 [ThreadId 28] INFO hls: Using interface files cache dir: /home/aplqo/.cache/ghcide/main-da39a3ee5e6b4b0d3255bfef95601890afd80709 2021-08-31 23:32:19.508410718 [ThreadId 28] INFO hls: Making new HscEnv[main] 2021-08-31 23:32:19.520975549 [ThreadId 28] DEBUG hls: New Component Cache HscEnvEq: (([],Just HscEnvEq 16),fromList [("/home/aplqo/test/hie.yaml",Just 2021-08-31 14:18:13.220986348 UTC)]) 2021-08-31 23:32:19.521165154 [ThreadId 28] DEBUG hls: Known files updated: fromList [(TargetFile NormalizedFilePath "/home/aplqo/test/Test.hs",["/home/aplqo/test/Test.hs"])] 2021-08-31 23:32:19.521479062 [ThreadId 28] DEBUG hls: Restarting build session (aborting the previous one took 0.00s) 2021-08-31 23:32:19.521652267 [ThreadId 14] DEBUG hls: Finishing build session(exception: AsyncCancelled) 2021-08-31 23:32:19.547498048 [ThreadId 105] INFO hls: finish: User TypeCheck (took 0.03s) 2021-08-31 23:32:19.54987261 [ThreadId 114] INFO hls: finish: GetHie (took 0.00s) 2021-08-31 23:32:19.550038015 [ThreadId 115] INFO hls: finish: GenerateCore (took 0.00s) ghcide setup tester in /home/aplqo/test. Report bugs at https://github.com/haskell/haskell-language-server/issues Step 1/4: Finding files to test in /home/aplqo/test Found 1 files Step 2/4: Looking for hie.yaml files that control setup Found 1 cradle (/home/aplqo/test/hie.yaml) Step 3/4: Initializing the IDE Step 4/4: Type checking the files Completed (1 file worked, 0 files failed) ``` 0.9.0 log ``` haskell-language-server version: 0.9.0.0 (GHC: 8.8.4) (PATH: /home/aplqo/.local/bin/haskell-language-server) (GIT hash: 46d2a3dc7ef49ba57b2706022af1801149ab3f2b) (haskell-language-server)Ghcide setup tester in /home/aplqo/test. Report bugs at https://github.com/haskell/haskell-language-server/issues Tool versions found on the $PATH cabal: 3.0.0.0 stack: Not found ghc: 8.8.4 Step 1/4: Finding files to test in /home/aplqo/test Found 1 files Step 2/4: Looking for hie.yaml files that control setup Found 1 cradle Step 3/4: Initializing the IDE Step 4/4: Type checking the files [INFO] Consulting the cradle for "Test.hs" Output from setting up the cradle Cradle {cradleRootDir = "/home/aplqo/test", cradleOptsProg = CradleAction: Direct} [INFO] Using interface files cache dir: ghcide [INFO] Making new HscEnv[main] Completed (1 file worked, 0 files failed) [INFO] finish: User TypeCheck (took 0.03s) ```

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs: ``` # versions vim version: VIM - Vi IMproved 8.2 8022434 node version: v14.17.5 coc.nvim version: 0.0.80-3086844413 coc.nvim directory: /home/aplqo/.vim/plugged/coc.nvim term: dumb platform: linux ## Log of coc.nvim 2021-08-31T23:50:56.341 INFO (pid:4848) [services] - registered service "languageserver.haskell" 2021-08-31T23:50:56.345 INFO (pid:4848) [services] - haskell state change: stopped => starting 2021-08-31T23:50:56.347 INFO (pid:4848) [plugin] - coc.nvim 0.0.80-3086844413 initialized with node: v14.17.5 after 44ms 2021-08-31T23:50:56.351 INFO (pid:4848) [language-client-index] - Language server "languageserver.haskell" started with 4859 2021-08-31T23:50:56.506 INFO (pid:4848) [services] - haskell state change: starting => running 2021-08-31T23:50:56.511 INFO (pid:4848) [services] - service languageserver.haskell started 2021-08-31T23:50:57.945 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:00.374 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:00.653 INFO (pid:4848) [completion-complete] - Results from: around,languageserver.haskell 2021-08-31T23:51:01.866 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:05.796 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:09.318 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:12.053 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:13.117 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:17.346 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:21.260 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:24.714 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:29.342 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:32.962 INFO (pid:4848) [completion-complete] - Results from: languageserver.haskell 2021-08-31T23:51:36.690 INFO (pid:4848) [completion-complete] - Results from: around,languageserver.haskell 2021-08-31T23:51:51.804 INFO (pid:4848) [attach] - receive notification: showInfo [] ```
jneira commented 3 years ago

Hi, thanks for the bug report, i dont see any error in the output log but i am not sure if it is set to trace level. Could you execute the server with -d? otoh, it is reproduced with another editor?

aplqo commented 3 years ago

I run server with -d flag.I think HLS 1.0.0(which has the problem) reported a error:



  Internal error, getIdeGlobalExtras, no entry for IdeConfigurationVar
  CallStack (from HasCallStack):
  errorIO, called at src/Development/IDE/Core/Shake.hs:284:20 in
  ghcide-1.0.0.0-inplace:Development.IDE.Core.Shake
2021-08-31 23:32:19.408109074 [ThreadId 28] INFO hls: Consulting the cradle for "Test.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/home/aplqo/test", cradleOptsProg = CradleAction: Direct}
2021-08-31 23:32:19.45423619 [ThreadId 28] DEBUG hls: Session loading result: Right (ComponentOptions {componentOptions = [], componentRoot = "/home/aplqo/test", componentDependencies = []},"/usr/lib/ghc")
2021-08-31 23:32:19.508225513 [ThreadId 28] INFO hls: Using interface files cache dir: /home/aplqo/.cache/ghcide/main-da39a3ee5e6b4b0d3255bfef95601890afd80709
2021-08-31 23:32:19.508410718 [ThreadId 28] INFO hls: Making new HscEnv[main]
2021-08-31 23:32:19.520975549 [ThreadId 28] DEBUG hls:    New Component Cache HscEnvEq: (([],Just HscEnvEq 16),fromList [("/home/aplqo/test/hie.yaml",Just 2021-08-31 14:18:13.220986348 UTC)])
2021-08-31 23:32:19.521165154 [ThreadId 28] DEBUG hls:    Known files updated: fromList [(TargetFile NormalizedFilePath "/home/aplqo/test/Test.hs",["/home/aplqo/test/Test.hs"])]
2021-08-31 23:32:19.521479062 [ThreadId 28] DEBUG hls:    Restarting build session (aborting the previous one took 0.00s)
2021-08-31 23:32:19.521652267 [ThreadId 14] DEBUG hls:    Finishing build session(exception: AsyncCancelled)
2021-08-31 23:32:19.547498048 [ThreadId 105] INFO hls:    finish: User TypeCheck (took 0.03s)
2021-08-31 23:32:19.54987261 [ThreadId 114] INFO hls: finish: GetHie (took 0.00s)
2021-08-31 23:32:19.550038015 [ThreadId 115] INFO hls:    finish: GenerateCore (took 0.00s)
ghcide setup tester in /home/aplqo/test.
Report bugs at https://github.com/haskell/haskell-language-server/issues
aplqo commented 3 years ago

I tried some editors. Here are results:

I don't know if hls has problem or coc.nvim has problem ,but I tried vim inside a container with newly installed vim and coc, so I think the problem isn't caused by other vim extension.

aplqo commented 3 years ago

It seems that HLS stops responding after typing some text. And when completion stops, HLS often reports a parse error on the beginning of the line.I think the parse error is caused by partial input.

aplqo commented 3 years ago

Git bisect shows that 9c40dcff1b989b14e05b5aebe96f3da78c6ea25c is the first commit to have this issue.

aplqo commented 3 years ago

I found that almost every time HLS stops working, it reports a error haskell-language-server: Data.Text.Internal.Fusion.Common.index: Index too large.

input file:

module DataAbstract.Set.UnordListDuplicate where

import DataAbstract.Set.UnorderedList (elementOfSet, intersection, mkSet)
newtype Name x = Name x der
adjoin :: (Eq a) => a -> [a] -> [a]
adjoin x s = x : s

union :: (Eq a) => [a] -> [a] -> [a]
union = (++)

{-
   1. adjoin and union become more effiecient, but elementOfSet become slower
   2. When there many adjoins and unions
   -}

lsp logs before error:


[Trace - 11:51:30 PM] Sending notification 'textDocument/didChange'.
Params: {
    "originalLines": [
        "module DataAbstract.Set.UnordListDuplicate where",
        "",
        "import DataAbstract.Set.UnorderedList (elementOfSet, intersection, mkSet)",
        "newtype Name x = Name",
        "adjoin :: (Eq a) => a -> [a] -> [a]",
        "adjoin x s = x : s",
        "",
        "union :: (Eq a) => [a] -> [a] -> [a]",
        "union = (++)",
        "",
        "{-",
        "   1. adjoin and union become more effiecient, but elementOfSet become slower",
        "   2. When there many adjoins and unions",
        "   -}"
    ],
    "textDocument": {
        "version": 22,
        "uri": "file:///home/aplqo/sicp-exercises-haskell/src/DataAbstract/Set/UnordListDuplicate.hs"
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 3,
                    "character": 21
                },
                "end": {
                    "line": 3,
                    "character": 21
                }
            },
            "rangeLength": 0,
            "text": " "
        }
    ]
}

[Trace - 11:51:31 PM] Sending request 'textDocument/completion - (24)'.
Params: {
    "textDocument": {
        "uri": "file:///home/aplqo/sicp-exercises-haskell/src/DataAbstract/Set/UnordListDuplicate.hs"
    },
    "position": {
        "line": 3,
        "character": 23
    },
    "context": {
        "triggerKind": 1
    }
}

haskell-language-server: Data.Text.Internal.Fusion.Common.index: Index too large
CallStack (from HasCallStack):
  error, called at libraries/text/Data/Text/Internal/Fusion/Common.hs:943:24 in text-1.2.4.0:Data.Text.Internal.Fusion.Common
aplqo commented 2 years ago

I found neovim doesn't has that issue. Sorry for disturbing.