Skip to content

Commit

Permalink
feat(pragmas): add all language extensions as options (#12)
Browse files Browse the repository at this point in the history
* refactor(pragmas): extra -#} into a single text node

* feat: add all language extensions
  • Loading branch information
gregorias committed Nov 12, 2023
1 parent aa8ee67 commit ba1db34
Showing 1 changed file with 149 additions and 27 deletions.
176 changes: 149 additions & 27 deletions lua/haskell-snippets/pragmas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,141 @@ local pragmas = {
all = {},
}

--- List of language extensions fetched from
--- https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/table.html as
--- of 2023-11-11.
---
---@type string[]
local language_extensions = {
'AllowAmbiguousTypes',
'ApplicativeDo',
'Arrows',
'BangPatterns',
'BinaryLiterals',
'BlockArguments',
'CApiFFI',
'ConstrainedClassMethods',
'ConstraintKinds',
'CPP',
'CUSKs',
'DataKinds',
'DatatypeContexts',
'DeepSubsumption',
'DefaultSignatures',
'DeriveAnyClass',
'DeriveDataTypeable',
'DeriveFoldable',
'DeriveFunctor',
'DeriveGeneric',
'DeriveLift',
'DeriveTraversable',
'DerivingStrategies',
'DerivingVia',
'DisambiguateRecordFields',
'DuplicateRecordFields',
'EmptyCase',
'EmptyDataDecls',
'EmptyDataDeriving',
'ExistentialQuantification',
'ExplicitForAll',
'ExplicitNamespaces',
'ExtendedDefaultRules',
'ExtendedLiterals',
'FieldSelectors',
'FlexibleContexts',
'FlexibleInstances',
'ForeignFunctionInterface',
'FunctionalDependencies',
'GADTs',
'GADTSyntax',
'GeneralisedNewtypeDeriving',
'GHC2021',
'GHCForeignImportPrim',
'Haskell2010',
'Haskell98',
'HexFloatLiterals',
'ImplicitParams',
'ImplicitPrelude',
'ImportQualifiedPost',
'ImpredicativeTypes',
'IncoherentInstances',
'InstanceSigs',
'InterruptibleFFI',
'KindSignatures',
'LambdaCase',
'LexicalNegation',
'LiberalTypeSynonyms',
'LinearTypes',
'MagicHash',
'MonadComprehensions',
'MonoLocalBinds',
'MonomorphismRestriction',
'MultiParamTypeClasses',
'MultiWayIf',
'NamedFieldPuns',
'NamedWildCards',
'NegativeLiterals',
'NondecreasingIndentation',
'NPlusKPatterns',
'NullaryTypeClasses',
'NumDecimals',
'NumericUnderscores',
'OverlappingInstances',
'OverloadedLabels',
'OverloadedLists',
'OverloadedRecordDot',
'OverloadedRecordUpdate',
'OverloadedStrings',
'PackageImports',
'ParallelListComp',
'PartialTypeSignatures',
'PatternGuards',
'PatternSynonyms',
'PolyKinds',
'PostfixOperators',
'QualifiedDo',
'QuantifiedConstraints',
'QuasiQuotes',
'Rank2Types',
'RankNTypes',
'RebindableSyntax',
'RecordWildCards',
'RecursiveDo',
'RoleAnnotations',
'Safe',
'ScopedTypeVariables',
'StandaloneDeriving',
'StandaloneKindSignatures',
'StarIsType',
'StaticPointers',
'Strict',
'StrictData',
'TemplateHaskell',
'TemplateHaskellQuotes',
'TraditionalRecordSyntax',
'TransformListComp',
'Trustworthy',
'TupleSections',
'TypeAbstractions',
'TypeApplications',
'TypeData',
'TypeFamilies',
'TypeFamilyDependencies',
'TypeInType',
'TypeOperators',
'TypeSynonymInstances',
'UnboxedSums',
'UnboxedTuples',
'UndecidableInstances',
'UndecidableSuperClasses',
'UnicodeSyntax',
'UnliftedDatatypes',
'UnliftedFFITypes',
'UnliftedNewtypes',
'Unsafe',
'ViewPatterns',
}

local ls = require('luasnip')
local s = ls.snippet
local sn = ls.snippet_node
Expand All @@ -25,6 +160,16 @@ local dynamic = ls.dynamic_node

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

-- This needs to be a function, because LuaSnip's functions modify the input
-- structures in place. We need to ensure that every time we use this
-- structure, we have a fresh copy.
local function language_extension_interior_snippet()
return sn(1, {
text('LANGUAGE '),
choice(1, vim.list_extend({ insert(1) }, vim.tbl_map(text, language_extensions))),
})
end

pragmas.prag = s({
trig = 'prag',
dscr = 'Compiler pragma',
Expand All @@ -33,13 +178,8 @@ pragmas.prag = s({
choice(1, {
sn(nil, {
insert(1),
text(' #-}'),
}),
sn(nil, {
text('LANGUAGE '),
insert(1),
text(' #-}'),
}),
language_extension_interior_snippet(),
sn(nil, {
text('OPTIONS_GHC '),
choice(1, {
Expand All @@ -52,52 +192,34 @@ pragmas.prag = s({
}),
}),
}),
text(' #-}'),
}),
sn(nil, {
text('OPTIONS_GHC -F -pgmF '),
insert(1),
text(' #-}'),
}),
sn(nil, {
text('INLINE '),
insert(1),
text(' #-}'),
}),
sn(nil, {
text('INLINABLE '),
insert(1),
text(' #-}'),
}),
sn(nil, {
text('NOINLINE '),
insert(1),
text(' #-}'),
}),
}),
text(' #-}'),
})
table.insert(pragmas.all, pragmas.prag)

pragmas.lang = s({
trig = 'lang',
dscr = 'LANGUAGE pragma',
}, {
text('{-# LANGUAGE '),
choice(1, {
insert(1),
text('ScopedTypeVariables'),
text('RecordWildCards'),
text('LambdaCase'),
text('QuasiQuotes'),
text('ViewPatterns'),
text('DerivingVia'),
text('DeriveAnyClass'),
text('DeriveGeneric'),
text('MultiParamTypeClasses'),
text('TypeFamilies'),
text('DataKinds'),
text('OverloadedLists'),
}),
text('{-# '),
language_extension_interior_snippet(),
text(' #-}'),
})
table.insert(pragmas.all, pragmas.lang)
Expand Down

0 comments on commit ba1db34

Please sign in to comment.