haskell / haskell-language-server

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

Dump TemplateHaskell splices #3986

Open dcastro opened 7 months ago

dcastro commented 7 months ago

Your environment

Which OS do you use? Ubuntu 20.04.6

Which version of GHC do you use and how did you install it? GHC 9.4.8 via ghcup

How is your project built (alternative: link to the project)? https://github.com/serokell/tztime

Which LSP client (editor/plugin) do you use? VSCode + vscode-haskell

Which version of HLS do you use and how did you install it? HLS 2.5.0.0 via ghcup

Have you configured HLS in any way (especially: a hie.yaml file)? Just the standard gen-hie --stack > hie.yaml

What's wrong?

I remember being able to add {-# OPTIONS_GHC -ddump-splices #-} to a module and vscode would report a warning with the contents of all TH splices. I tried this again this week, using the latest version of HLS, and no warnings are reported by vscode (though building the project with stack/cabal does print the splices as per usual).

Did something change recently that made this no longer possible?

Debug information

EDIT: To reproduce the old behavior, see this comment: https://github.com/haskell/haskell-language-server/issues/3986#issuecomment-1900227516

To reproduce the problem, simply add {-# OPTIONS_GHC -ddump-splices #-} to a module and write some TH splice, e.g.:

exp :: Integer
exp = $([e| 1 |])
konn commented 7 months ago

You can just use Splice Plugin to expand splices in-place or commented out style, without resorting to -ddump things. You can basically invoke "expand TemplateHaskell Splice" code action if LHS supports the target GHC.

dcastro commented 7 months ago

@konn Thank you for your reply, but I don't think the Splice Plugin solves my use case.

I'm writing some TH code and I need a feedback loop, I want to see in real-time what code my functions are generating. -ddump does exactly what I need.

With the Splice Plugin, I'd have to expand my splice to see what code is being generated, Ctrl+Z to recover the splice, modify my TH code, repeat.

If it's not possible to have HLS report -ddump, I guess the next best thing will be to run stack with --file-watch on a terminal.

michaelpj commented 7 months ago

I don't believe this has ever been the case? -ddump-splices just sends stuff to stdout, it's not a diagnostic, and I don't think we have ever intercepted that and sent it as a message. I'm confused about what you were seeing.

konn commented 7 months ago

I'm writing some TH code and I need a feedback loop, I want to see in real-time what code my functions are generating. -ddump does exactly what I need. With the Splice Plugin, I'd have to expand my splice to see what code is being generated, Ctrl+Z to recover the splice, modify my TH code, repeat.

Ah, that makes sense. Splice Plugin once also provided the feature to expand Splice within comment, not in-place:

https://github.com/haskell/haskell-language-server/blob/866a533fbcf928e7be986390d93f9daedf94c44b/plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs#L91

But it was removed for some reason that I can't remember (Perhaps exactprint-related things). So it might be good to try to revive this feature if possible for such iteration purpose. Alternatively, we can add a config option to add expanded splice to the hover.

I don't believe this has ever been the case? -ddump-splices just sends stuff to stdout, it's not a diagnostic, and I don't think we have ever intercepted that and sent it as a message. I'm confused about what you were seeing.

I can remember and confirm that other -ddump-*, like -ddump-tc, adds a toplevel warning with HLS - so hls catches -ddump-* outputs and reports it somehow. But if I changed it to -ddump-splcie, the warning gets extinct. Instead, Error condition occurs with the LSP log says Fourmolu failed to recognise -ddump-splice option:

2024-01-19T11:11:13.710665Z | Info | fourmolu: Loaded Fourmolu config from: "/Users/hiromi/.config/fourmolu.yaml"
2024-01-19T11:11:13.712468Z | Error | fourmolu: Internal Error: OrmoluUnrecognizedOpts ("-ddump-splice" :| [])
[Error - 20:11:13] Request textDocument/formatting failed.
  Message: fourmolu: Internal Error: OrmoluUnrecognizedOpts ("-ddump-splice" :| [])
  Code: -32603 
2024-01-19T11:11:13.772855Z | Info | Typechecking reverse dependencies for NormalizedFilePath "/Users/hiromi/Documents/Programming/Haskell/git/linear-extra/linear-witness/src/Linear/Token/Linearly/Internal.hs": [ NormalizedFilePath "/Users/hiromi/Documents/Programming/Haskell/git/linear-extra/linear-witness/src/Linear/Token/Linearly.hs"
                                                                                                                                                                              , NormalizedFilePath "/Users/hiromi/Documents/Programming/Haskell/git/linear-extra/linear-witness/src/Linear/Token/Linearly/Unsafe.hs" ]

So, perhaps formatter-related glitch can be behind the scene - but disabling formatting and set formattingProvider to none didn'tchange the behaviour. So I have no idea.

dcastro commented 7 months ago

@michaelpj I was able to reproduce the old behaviour I was seeing using an older version of GHC / HLS:

image

Steps:

konn commented 7 months ago

On the other hand, I usually use the Splice expansion with Ctrl+Z in the TH macro implementation iteration, and it is the main motivation when I started to implement the Splice Plugin and it was the intended workflow to be used with Ctrl+Z or Cmd+Z. Anyway, I can under stand that such workflow feels sometimes tedious, so considering alternative features described above could help such cases.

michaelpj commented 7 months ago

Okay, I have no idea what's going on here, maybe @wz1000 knows/

soulomoon commented 7 months ago

but disabling formatting and set formattingProvider to none didn'tchange the behaviour. So I have no idea.

@konn does it mean we would have same internal error on format even if formatting is turned off?