Haskell Language Server: Cabal File Support
I am one of the three participants working on haskell-language-server in this year’s Summer of Haskell and I want to give you an update on the new cabal file support features coming to HLS!
Two years ago I worked on my first ever open source feature, adding a plugin which supports formatting of cabal files with cabal-fmt
when using HLS.
You may be wondering why you never noticed this useful feature in your day to day Haskell life.
Well, it was actually merged a while ago, but if you are using vscode the issue is that vscode still needs to be taught that .cabal
files are also handled by the language server, since it was only responsible for haskell files before.
So this summer, one of my goals was and is to finally get vscode-haskell to support handling .cabal
files so that all of the new features I have been working on can actually be used in vscode!
We will be adding these features in a pre-release of vscode-haskell and I want to motivate you to try it out by giving you a little feature preview of the upcoming cabal-file support.
Firstly we have the afforementioned file-formatting and also diagnostics which have actually been ready-to-use for a while and are just waiting for the vscode support!
A couple of weeks ago, a large chunk of my proposed Summer of Haskell project has been merged, which is a completion system for cabal-files.
This consists of basic completion such as keyword and stanza suggestions as well as suggestions when writing certain kinds of fields in cabal.
For example:
- We suggest relevant cabal versions when writing the cabal-version field.
- Valid licenses are suggested according to usage statistics from hackage (thank you Hécate!).
- When writing a field which contains some filepaths we suggest filepaths relative to the cabal file’s directory.
- For fields which contain module paths, we can suggest possible module paths relative to the relevant source directories.
Additionally we added some snippets that can be helpful in quickly writing a cabal file.
This includes snippets for various stanzas and their mandatory fields, and a snippet with the basic top-level fields needed for any cabal file.
All of the above is already available in the latest release of HLS (2.1.0.0) and I hope you will try it out, find it helpful and maybe help me fix some bugs or add some more features!
Now my summer of Haskell is coming to an end, I have about two weeks left and I am currently working on another exciting feature which will hopefully make working with cabal files more comfortable.
The feature is a code action that automates the tedious, manual task of adding a newly created module to a cabal file.
Together with improved error messages telling the user what and why things are going wrong, it will hopefully improve the developer experience for newcomers in particular.
As you can see in the gif, the POC is done and I am hoping to get this merged before the end of the month!