Skip to content

Commit 7aedbc9

Browse files
committed
Add README and bump version to 1.0.0.0.
1 parent 856cd92 commit 7aedbc9

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Alternate Number Format Plugin
2+
3+
The alternate number format plugin provides alternative formatting for Numeric Literals in source code.
4+
These can be any numeric literal such as `123`, `0x45` or any of the other numeric formats.
5+
The plugin is context aware and will provide suggestions based on currently active GHC extensions.
6+
7+
## Setup
8+
9+
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.
10+
11+
## Demo
12+
13+
![Alternate format suggestions](HLSInt.gif)
14+
15+
### Currently Supported GHC Extensions:
16+
- `BinaryLiterals`
17+
- `HexFloatLiterals`
18+
- `NumDecimalLiterals`
19+
20+
## Design
21+
22+
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.
23+
Currently, the traversal is done in the file, `Literal.hs`, using the package [SYB](https://hackage.haskell.org/package/syb) for most of the heavy lifting.
24+
25+
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.
26+
27+
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).
28+
29+
### Known Quirks
30+
- 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.
31+
32+
- 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.
33+
34+
- `PrimLiterals` are currently ignored. GHC API does not attach Source Text to Primitive Literal Nodes. As such these are ignored in the plugin.
35+
36+
- Similarly, anything that produces a bad Source Span (i.e. can't be easily replaced by an edit) is ignored as well.
37+
38+
## Changelog
39+
### 1.0.0.0
40+
- First Release

plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: hls-alternate-number-format-plugin
3-
version: 0.1.0.0
3+
version: 1.0.0.0
44
synopsis: Provide Alternate Number Formats plugin for Haskell Language Server
55
description:
66
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>

0 commit comments

Comments
 (0)