hls-alternate-number-format-plugin: Provide Alternate Number Formats plugin for Haskell Language Server

[ apache, development, library ] [ Propose Tags ]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,
Dependencies aeson, base (>=4.12 && <5), containers, ghc-boot-th (<9.2), ghcide (>=1.6 && <1.7), hie-compat, hls-graph, hls-plugin-api (>=1.3 && <1.4), lens, lsp, mtl, regex-tdfa, syb, text, unordered-containers [details]
License Apache-2.0
Author Nick Suchecki
Maintainer nicksuchecki@gmail.com
Revised Revision 1 made by Bodigrim at 2022-05-01T18:16:21Z
Category Development
Uploaded by jneira at 2022-01-29T12:32:22Z
Distributions Arch:, NixOS:
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2285 total (121 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-30 [all 1 reports]

Readme for hls-alternate-number-format-plugin-

[back to package description]

Alternate Number Format Plugin

The alternate number format plugin provides alternative formatting for Numeric Literals in source code. These can be any numeric literal such as 123, 0x45 or any of the other numeric formats. The plugin is context aware and will provide suggestions based on currently active GHC extensions.


The plugin requires no extra setup to work. Simply place your cursor on top of a literal and invoke the codeAction command for your editor.


Alternate format suggestions

Currently Supported GHC Extensions:

  • BinaryLiterals
  • HexFloatLiterals
  • NumDecimalLiterals


The plugin is relatively simple, it traverses a files source contents using the GHC API. As it encounters Literals (of the type HsExpr with the constructor of either HsLit or HsOverLit), it will construct an internal Literal datatype that has additional information for use to generate suggestions. Currently, the traversal is done in the file, Literal.hs, using the package SYB for most of the heavy lifting.

The plugin extends on top of SYB as the traversal done by basic combinators is not perfect. For whatever reason, when starting at the root ParsedModule the SYB traversal ignores Pattern Binds (LPat GhcPs). As a result, a combinator was created to match on TWO separate underlying types to dispatch on.

To generate suggestions, the plugin leverages the Numeric package which provides a multitude of conversion functions to and from strings/numerics. The only slight change is the addition of extra work when using NumDecimals extension. The plugin will attempt to generate 3 choices for the user (this choice is not given for Fractional numerics).

Known Quirks

  • Currently (and probably inefficiently), a Set is used as general accumulator for all Literals being captured. This is because again, through the intricacies of using SYB, we somehow will traverse Source Text multiple times and collect duplicate literals.

  • In the Test Suite, we are required to be explicit in where our codeActions will occur. Otherwise, a simple call to getAllCodeActions will not work, for whatever reason, there is not enough time to generate the code actions.

  • PrimLiterals are currently ignored. GHC API does not attach Source Text to Primitive Literal Nodes. As such these are ignored in the plugin.

  • Similarly, anything that produces a bad Source Span (i.e. can't be easily replaced by an edit) is ignored as well.


  • First Release