Configure stylish-haskell for LSP with Sublime Text

Viewed 431

I've installed LSP for Sublime Text 3 and configured it to talk to the Haskell language server by following https://lsp.readthedocs.io/en/latest/#haskell. This works great. However there are no plugins that run stylish-haskell for Sublime Text. Haskell language server mentions that it supports configuring a formatting provider at https://github.com/haskell/haskell-language-server#language-specific-server-options, but I cannot find how to configure this for LSP with Sublime Text.

How do I get stylish-haskell to work for Sublime Text 3?

1 Answers

I have the same question. After reading the docs it looks as if for this to work there should be some way to instruct the Sublime Text LSP implementation (https://lsp.sublimetext.io/language_servers/) to set the haskell.formattingProvider to stylish-haskell. I don't see any way to do this.

In the meantime I have been using the FilterPipes package (https://packagecontrol.io/packages/FilterPipes) to manually run files through stylish-haskell. It works, but it's not perfect. It runs from the Sublime Text installation directory (on my system /Applications/Sublime Text.app/Contents/MacOS), which means it does not read the local .stylish-haskell.yaml config file.

There is a stylish-haskell plugin for Sublime Text 2 (https://github.com/hairyhum/SublimeStylishHaskell); it should be simple to adapt it for Sublime Text 3 (or 4 coming soon I suppose), but integration with LSP would be better.

Update:

I think this is the solution -- add a settings clause to your LSP config for Haskell as follows:

"haskell-language-server": {
    "enabled": true,
    "command": ["haskell-language-server-wrapper", "--lsp"],
    "scopes": ["source.haskell"],
    "syntaxes": ["Packages/Haskell/Haskell.sublime-syntax"],
    "languageId": "haskell",
    "settings": {
        "haskell.formattingProvider": "stylish-haskell"
    },
},
Related