visual-studio-codehaskelltemplate-haskellhaskell-language-server

How to get HLS to Evaluate a Template Haskell splice and insert the resulting code in its place?


I am using the Visual Studio Code Haskell extension. The Haskell Language Server (hls) docs state that it has a feature that:

Evaluates a Template Haskell splice and inserts the resulting code in its place.

It is supplied by hls-splice-plugin

How do I get that on Visual Studio Code? I would like to replace my makeLenses' with normal haskell code, if possible.


Solution

  • You don't need to install anything in particular. The hls-splice-plugin is part of the standard HLS installation that gets set up by the "Haskell" extension.

    I just tested it myself: set up a basic project with Cabal file and Lens code and the splice feature was available, see screenshot.

    Showing Plugin availability

    Note that the hls-splice-plugin is a "tier 3" plugin, and is (at time of writing in May 2025) unsupported for GHC versions 9.10.1, 9.12.2

    You can lookup all supported plugins in your hls installation by running ./haskell-language-server-9.6.7 --list-plugins - in my case this executable was installed by the Haskell extension and placed in ~/.ghcup/hls/2.10.0.0/bin.

    The result looks like this:

    $ ./haskell-language-server-9.6.7 --list-plugins
    LSPRecorderCallback:
        Internal plugin
    alternateNumberFormat:
        Provides code actions to convert numeric literals to different formats
    ...SNIP...
    splice:
        Provides a code action to evaluate a TemplateHaskell splice
    stan:
        Provides stan diagnostics. Built with stan-0.2.0.0
    stylish-haskell:
        Provides formatting of Haskell files via stylish-haskell. Built with stylish-haskell-0.14.6.0