haskell-ide-engine
haskell-ide-engine copied to clipboard
Autoimports mangles yaml file
When using the action for adding missing imports it mangles the formatting of yaml files and removes any comments:
Original:
name: test
version: 0.1.0.0
github: "meck/test"
license: BSD3
author: "Johan Eklund"
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
dependencies:
- base >= 4.7 && < 5
library:
source-dirs: src
executables:
test-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- test
tests:
test-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- test
After auto importing HTTP:
library:
source-dirs: src
tests:
test-test:
source-dirs: test
main: Spec.hs
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- test
dependencies:
- HTTP
- base >= 4.7 && < 5
name: test
version: 0.1.0.0
extra-source-files:
- README.md
- ChangeLog.md
author: Johan Eklund
github: meck/test
license: BSD3
executables:
test-exe:
source-dirs: app
main: Main.hs
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- test
It would also be nice if it did a stack install package and the equivalent for cabal in order for the error to clear, otherwise it stays around and you can redo the action and add the package multiple times.
Maybe save the file as well, but saving a file might not be in the purview of an LSP server?
There was a GSOC project for format preserving YAML, but it unfortunately did not complete.
Without that kind of support we cannot do anything, and this is why the file is not saved. It is a suggestion, if you are happy with it, you can use it, else hit undo.
Yes, this issue pretty much prevents me from using the "add
@alanz Maybe if we restrict ourselves to modifying only the top-level dependencies: list maybe this part of the yaml file could be identified and updated with minimal amount of parsing (without using Yaml library altogether) -> just split by lines, identify the next span of lines starting with "-" and insert the new dependency at the correct position (ideally in alphabetic order). I think this best-effort approach would be immediately useful and cover majority of cases (more than is the case today).
Alternatively one could consider replacing the yaml library with http://hackage.haskell.org/package/HsYAML-0.2.1.0/docs/Data-YAML-Event.html which promises an event-stream oriented YAML parsing with the ability of preserving comments and format. But unfortunately my googling didn't find any examples / projects using this library so I'm not sure how hard it would be to integrate into HIE.