Skip to content

Commit ba1db34

Browse files
authored
feat(pragmas): add all language extensions as options (#12)
* refactor(pragmas): extra -#} into a single text node * feat: add all language extensions
1 parent aa8ee67 commit ba1db34

File tree

1 file changed

+149
-27
lines changed

1 file changed

+149
-27
lines changed

lua/haskell-snippets/pragmas.lua

Lines changed: 149 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,141 @@ local pragmas = {
1515
all = {},
1616
}
1717

18+
--- List of language extensions fetched from
19+
--- https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/table.html as
20+
--- of 2023-11-11.
21+
---
22+
---@type string[]
23+
local language_extensions = {
24+
'AllowAmbiguousTypes',
25+
'ApplicativeDo',
26+
'Arrows',
27+
'BangPatterns',
28+
'BinaryLiterals',
29+
'BlockArguments',
30+
'CApiFFI',
31+
'ConstrainedClassMethods',
32+
'ConstraintKinds',
33+
'CPP',
34+
'CUSKs',
35+
'DataKinds',
36+
'DatatypeContexts',
37+
'DeepSubsumption',
38+
'DefaultSignatures',
39+
'DeriveAnyClass',
40+
'DeriveDataTypeable',
41+
'DeriveFoldable',
42+
'DeriveFunctor',
43+
'DeriveGeneric',
44+
'DeriveLift',
45+
'DeriveTraversable',
46+
'DerivingStrategies',
47+
'DerivingVia',
48+
'DisambiguateRecordFields',
49+
'DuplicateRecordFields',
50+
'EmptyCase',
51+
'EmptyDataDecls',
52+
'EmptyDataDeriving',
53+
'ExistentialQuantification',
54+
'ExplicitForAll',
55+
'ExplicitNamespaces',
56+
'ExtendedDefaultRules',
57+
'ExtendedLiterals',
58+
'FieldSelectors',
59+
'FlexibleContexts',
60+
'FlexibleInstances',
61+
'ForeignFunctionInterface',
62+
'FunctionalDependencies',
63+
'GADTs',
64+
'GADTSyntax',
65+
'GeneralisedNewtypeDeriving',
66+
'GHC2021',
67+
'GHCForeignImportPrim',
68+
'Haskell2010',
69+
'Haskell98',
70+
'HexFloatLiterals',
71+
'ImplicitParams',
72+
'ImplicitPrelude',
73+
'ImportQualifiedPost',
74+
'ImpredicativeTypes',
75+
'IncoherentInstances',
76+
'InstanceSigs',
77+
'InterruptibleFFI',
78+
'KindSignatures',
79+
'LambdaCase',
80+
'LexicalNegation',
81+
'LiberalTypeSynonyms',
82+
'LinearTypes',
83+
'MagicHash',
84+
'MonadComprehensions',
85+
'MonoLocalBinds',
86+
'MonomorphismRestriction',
87+
'MultiParamTypeClasses',
88+
'MultiWayIf',
89+
'NamedFieldPuns',
90+
'NamedWildCards',
91+
'NegativeLiterals',
92+
'NondecreasingIndentation',
93+
'NPlusKPatterns',
94+
'NullaryTypeClasses',
95+
'NumDecimals',
96+
'NumericUnderscores',
97+
'OverlappingInstances',
98+
'OverloadedLabels',
99+
'OverloadedLists',
100+
'OverloadedRecordDot',
101+
'OverloadedRecordUpdate',
102+
'OverloadedStrings',
103+
'PackageImports',
104+
'ParallelListComp',
105+
'PartialTypeSignatures',
106+
'PatternGuards',
107+
'PatternSynonyms',
108+
'PolyKinds',
109+
'PostfixOperators',
110+
'QualifiedDo',
111+
'QuantifiedConstraints',
112+
'QuasiQuotes',
113+
'Rank2Types',
114+
'RankNTypes',
115+
'RebindableSyntax',
116+
'RecordWildCards',
117+
'RecursiveDo',
118+
'RoleAnnotations',
119+
'Safe',
120+
'ScopedTypeVariables',
121+
'StandaloneDeriving',
122+
'StandaloneKindSignatures',
123+
'StarIsType',
124+
'StaticPointers',
125+
'Strict',
126+
'StrictData',
127+
'TemplateHaskell',
128+
'TemplateHaskellQuotes',
129+
'TraditionalRecordSyntax',
130+
'TransformListComp',
131+
'Trustworthy',
132+
'TupleSections',
133+
'TypeAbstractions',
134+
'TypeApplications',
135+
'TypeData',
136+
'TypeFamilies',
137+
'TypeFamilyDependencies',
138+
'TypeInType',
139+
'TypeOperators',
140+
'TypeSynonymInstances',
141+
'UnboxedSums',
142+
'UnboxedTuples',
143+
'UndecidableInstances',
144+
'UndecidableSuperClasses',
145+
'UnicodeSyntax',
146+
'UnliftedDatatypes',
147+
'UnliftedFFITypes',
148+
'UnliftedNewtypes',
149+
'Unsafe',
150+
'ViewPatterns',
151+
}
152+
18153
local ls = require('luasnip')
19154
local s = ls.snippet
20155
local sn = ls.snippet_node
@@ -25,6 +160,16 @@ local dynamic = ls.dynamic_node
25160

26161
local util = require('haskell-snippets.util')
27162

163+
-- This needs to be a function, because LuaSnip's functions modify the input
164+
-- structures in place. We need to ensure that every time we use this
165+
-- structure, we have a fresh copy.
166+
local function language_extension_interior_snippet()
167+
return sn(1, {
168+
text('LANGUAGE '),
169+
choice(1, vim.list_extend({ insert(1) }, vim.tbl_map(text, language_extensions))),
170+
})
171+
end
172+
28173
pragmas.prag = s({
29174
trig = 'prag',
30175
dscr = 'Compiler pragma',
@@ -33,13 +178,8 @@ pragmas.prag = s({
33178
choice(1, {
34179
sn(nil, {
35180
insert(1),
36-
text(' #-}'),
37-
}),
38-
sn(nil, {
39-
text('LANGUAGE '),
40-
insert(1),
41-
text(' #-}'),
42181
}),
182+
language_extension_interior_snippet(),
43183
sn(nil, {
44184
text('OPTIONS_GHC '),
45185
choice(1, {
@@ -52,52 +192,34 @@ pragmas.prag = s({
52192
}),
53193
}),
54194
}),
55-
text(' #-}'),
56195
}),
57196
sn(nil, {
58197
text('OPTIONS_GHC -F -pgmF '),
59198
insert(1),
60-
text(' #-}'),
61199
}),
62200
sn(nil, {
63201
text('INLINE '),
64202
insert(1),
65-
text(' #-}'),
66203
}),
67204
sn(nil, {
68205
text('INLINABLE '),
69206
insert(1),
70-
text(' #-}'),
71207
}),
72208
sn(nil, {
73209
text('NOINLINE '),
74210
insert(1),
75-
text(' #-}'),
76211
}),
77212
}),
213+
text(' #-}'),
78214
})
79215
table.insert(pragmas.all, pragmas.prag)
80216

81217
pragmas.lang = s({
82218
trig = 'lang',
83219
dscr = 'LANGUAGE pragma',
84220
}, {
85-
text('{-# LANGUAGE '),
86-
choice(1, {
87-
insert(1),
88-
text('ScopedTypeVariables'),
89-
text('RecordWildCards'),
90-
text('LambdaCase'),
91-
text('QuasiQuotes'),
92-
text('ViewPatterns'),
93-
text('DerivingVia'),
94-
text('DeriveAnyClass'),
95-
text('DeriveGeneric'),
96-
text('MultiParamTypeClasses'),
97-
text('TypeFamilies'),
98-
text('DataKinds'),
99-
text('OverloadedLists'),
100-
}),
221+
text('{-# '),
222+
language_extension_interior_snippet(),
101223
text(' #-}'),
102224
})
103225
table.insert(pragmas.all, pragmas.lang)

0 commit comments

Comments
 (0)