haskell / haskell/haskell-mode
Improvements for Haskell-Cabal mode
- Dominant language
- Emacs Lisp
- Stars
- 1.4k
- Forks
- 354
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 2
Description
Current implementation of `haskell-cabal--get-field` is quite simple and is not very helpful. It takes field name as argument and then simply tries to find `:NAME` pattern in current buffer. It returns value of first field occurrence. So, if I want to get build dependencies of test section coming after library section in my cabal file it won't help. Also, it reads value as multi-line string unconditionally, giving wrong results, for example:
``` cabal
library
default-language: Haskell2010
exposed-modules: LambdaCms.Core
, LambdaCms.Core.Message
, LambdaCms.Core.Settings
-- for the test suite
, LambdaCms.Core.Foundation
other-modules: LambdaCms.Core.Classes
, LambdaCms.Core.Handler.ActionLog
, LambdaCms.Core.Handler.Home
```
If I ask for "default-language" it will return everything including exposed and other modules. This is totally wrong. Conditions in cabal file also is not accounted (cabal file may have if-then-else conditions).
This is not fun. We need better parser if we tend to support such functionality. Likely we need two kind of them: one for whole cabal file parsing returning some kind of AST, and another special one which can partially parse cabal file starting from some line and returning partial AST.
So, for example `(haskell-cabal--get-field "exposed-modules")` should return a list of exposed modules for each section in cabal file. It would be much better if this function will take a symbol from predefined set rather than string. Also there should be possibility to restrict results specifying section, e.g. `(haskell-cabal--get-field 'exposed-modules 'library)`.
Maybe it would be better to provide such functions as:
- `haskell-cabal-get-package-field-value` — returns value of top-level fields, such as name, description, etc.
- `haskell-cabal-get-library-field-value` — returns a value of library field
- `haskell-cabal-get-executable-field-value`, `haskell-cabal-get-test-suit-field-value` — return a value of executables and test-suits fields (either all for all entities or for arbitrary one).
Contributor guide
Research direction
Start with haskell-cabal--get-field and inspect how it finds fields in the current buffer. Define the parsing scope around whole-file and partial parsing, including sections and conditions. Done means field values are separated by section, multiline values are parsed correctly, and the proposed package, library, executable, and test-suite accessors are supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- emacs-lisp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100