haskell / haskell/haskell-language-server

Exception thrown by stylish-haskell plugin on format

Open
#2,698 17 comments 0 reactions 0 assignees View on GitHub
component: formatters type: bug
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
3d 21h
Merged PRs (30d)
13

Description

### Your environment

Which OS do you use: macOS

Which LSP client (editor/plugin) do you use: Doom Emacs + LSP Mode/lsp-haskell

Describe your project (alternative: link to the project):
[Minimal Reproduction](https://github.com/williamareynolds/hls-stylish-plugin-test)

### Steps to reproduce

1. Install haskell-language-server version 1.6.1.0, GHC 8.10.7, and stack 2.7.3, implicit-hie. and the latest Doom Emacs with `lsp`, `lsp-haskell`, and `format +onsave`.
1. Configure lsp-haskell as follows in the doom config:

```elisp
;; Haskell
;; Process
(after! lsp-haskell
(setq haskell-process-type 'stack)
(setq lsp-haskell-brittany-on nil)
(setq lsp-haskell-fourmolu-on nil)
(setq lsp-haskell-ormolu-on nil)
(setq lsp-haskell-floskell-on nil)
(setq lsp-ui-doc-show-with-cursor t)
(setq lsp-haskell-formatting-provider "stylish-haskell")
(setq flycheck-hlintrc ".hlint.yaml"))
```

1. Build the project using `stack build`
1. Generate hie.yaml if necessary `gen-hie > hie.yaml`
1. Open app/Main.hs in a buffer, make a modification, and save. Everything should work fine.
1. Open other-app/Main.hs in a buffer, make a modification, and save. You will get an error:

`Error: (doom-hook-error before-save-hook format-all-buffer--from-hook (error "Exception in plugin PluginId \"stylish-haskell\"while processing STextDocumentFormatting: BadDependency \"GetModSummary\""))`

### Expected behaviour
The stylish-haskell plugin should be able to format the file. Other formatters work correctly (at least, the Ormolu plugin does).

### Actual behaviour
Formatting does not occur and an error is written to the Emacs message buffer:

`Error: (doom-hook-error before-save-hook format-all-buffer--from-hook (error "Exception in plugin PluginId \"stylish-haskell\"while processing STextDocumentFormatting: BadDependency \"GetModSummary\""))`

### Include debug information

--probe-tools output:
```
haskell-language-server version: 1.6.1.0 (GHC: 8.10.7) (PATH: /Users/r258625/.ghcup/bin/haskell-language-server-wrapper-1.6.1.0) (GIT hash: f4022c5bb8530cd306c53b941878244bf27a5d41)
Tool versions found on the $PATH
cabal: 3.6.2.0
stack: 2.7.3
ghc: 8.10.7
```

I couldn't find much else in the logs that looked problematic.

One thing I did find is that this issue only seems to occur (at least consistently) when two executable entrypoints have the same file name. If I change `other-app/Main.hs` to `other-app/OtherMain.hs`, rebuild, regenerate the hie.yaml, and restart the language server, the issue appears to be resolved. I think the issue is that having more than one file with the same name could be breaking the plugin. It also seems that this is only an issue with executable entry points. There are no issues with two files in the lib being called Lib.hs and Foo/Lib.hs for instance.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked minimal reproduction and compare formatting for app/Main.hs with other-app/Main.hs, where the duplicate executable entry-point filename triggers the error. Reproduce with Haskell Language Server 1.6.1.0, GHC 8.10.7, Stack 2.7.3, and stylish-haskell enabled, then inspect the behavior after renaming other-app/Main.hs and regenerating hie.yaml. Done means both executable entry points format successfully without the GetModSummary error.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.