1

I have the following Visual Studio Code extensions for Haskell installed:

enter image description here

Let's say I create a new stack project:

stack new vscode-red-squiggly-test

And setup Lib.hs and Main.hs as follows:

enter image description here

This builds and runs just fine:

stack build
stack exec vscode-red-squiggly-test-exe

Now, if I add an item xyz to Lib.hs and reference it in Main.hs:

enter image description here

as you can see, a red squiggly show up under xyz.

Now, at this point, I can build and run the program just fine.

The hint when I hover over the squiggly is as follows:

enter image description here

If I close vscode, run stack build, and relaunch vscode via code ., the squiggly goes away.

So... is there a way to make the squiggly go away without having to relaunch vscode?

The suggested quick-fix is to add the following to the file:

{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}

However, I'd obviously like to avoid that as it turns off the nice feature of detecting truly undefined variables.

Notes

  • My Haskell environment is running within WSL on Windows.
  • The vscode instance is running on Windows, initiated from within vscode via code ..

Update

  • I've submitted this as an issue.
dharmatech
  • 8,979
  • 8
  • 42
  • 88
  • 2
    I can't reproduce your problem, it turns out hls can defer your project. Would you share your debug output by enabling trace in the setting? – July Treee Aug 01 '21 at 08:16
  • @JulyTree, yes I'd be happy to. Can you let me know how to enable tracing? :-) – dharmatech Aug 01 '21 at 09:36
  • 1
    Open setting in vscode and search `hasekll`, then you'll find a trace at the below, set it from off to messages. After that, restart your vscode, open output, there is debug message. – July Treee Aug 01 '21 at 09:44
  • @JulyTree, OK, tracing is enabled. However, in 'OUTPUT' tab, I don't see any messages after I recreated the issue. Should I select a particular item from the menu displayed in this screenshot? https://i.imgur.com/ewU6Flh.png Happy to setup a zoom with you if that's easier. :-) – dharmatech Aug 01 '21 at 10:17
  • @JulyTree, OK, I think I found the output: https://pastebin.com/f2FxaLAr That's what appears after I hover over the red squiggly. – dharmatech Aug 01 '21 at 10:26
  • See the list, I think `Haskell(vscode-red-squiggly-test)` is the one. By the way, maybe you can disable `Haskell HSX` temporarily, `Haskell language server` is enough as I know, they have conflicts probably. – July Treee Aug 01 '21 at 10:29
  • @JulyTree, here's one more: https://pastebin.com/9HW6f6We That's what appears when I add I reference a definition that's newly added to `Lib`. – dharmatech Aug 01 '21 at 10:30
  • Log shows well, maybe you can disable `HSX` first? – July Treee Aug 01 '21 at 10:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235507/discussion-between-july-tree-and-dharmatech). – July Treee Aug 01 '21 at 10:35
  • @dharmatech In Emacs, I sometimes have to restart LSP if I’ve modified a library and want those changes to propagate to the executable. Might this work with VSCode as well? – bradrn Aug 01 '21 at 11:30
  • @bradrn, I can give that a whirl. How do you restart LSP? – dharmatech Aug 01 '21 at 12:39
  • @dharmatech Not sure, sorry… in Emacs I can run `lsp-restart-workspace`, but I don’t use VSCode so I’m not sure. Perhaps you could try closing and reopening the application if you haven’t already? – bradrn Aug 01 '21 at 12:45
  • @bradm, Ah OK. Yes, restarting vscode does resolve the issue for that one squiggly. Creating a new definition however results in a new squiggly. :-) I'd have to restart after every definition. – dharmatech Aug 01 '21 at 12:46
  • 1
    @dharmatech Sadly, yes, it does seem that editing two components at once is a bit clunky. That being said, I find that generally I only work on one component at a time. – bradrn Aug 01 '21 at 12:48

1 Answers1

5

This won't help resolve your problem, which is probably a Haskell Language server bug, but the quickest way to restart Haskell Language Server in VS Code is:

  • Ctrl+Shift+P
  • Start typing until you find: Haskell: Restart Haskell LSP Server

This resolves a lot of HLS issues, and is unfortunately often neccessary, since HLs is not quite production-stable yet.

Happy Haskelling!

Jonathan
  • 1,955
  • 5
  • 30
  • 50
Ari Fordsham
  • 2,437
  • 7
  • 28
  • OK, I'm at a computer now. Yes, this suggestion works! However, I have to `stack build` before restarting LSP on order for it to work. – dharmatech Aug 01 '21 at 20:52
  • 1
    I've submitted an issue: https://github.com/haskell/haskell-language-server/issues/2058 – dharmatech Aug 01 '21 at 20:54
  • thanks for reporting the issue, the issue is quite similar to https://github.com/haskell/haskell-language-server/issues/1822 – jneira Aug 02 '21 at 06:49
  • We have some issues with the setup of the project specially related with stack although we are working in improve it :-) – jneira Aug 02 '21 at 06:51