Skip to content

Commit

Permalink
feat(module): snippets for import of child modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 5, 2023
1 parent 9da75c2 commit 63d01a7
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 87 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ignore = {
"631", -- max_line_length
"122", -- read-only field of global variable
"512", -- loop executed at most once
}
read_globals = {
"vim",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2023-12-05

- Module imports:
- `qualc` snippet for qualified import of child modules.
- `impc` snippet for unqualified import of child modules.

## [1.3.0] - 2023-12-05

- Expressions: Add multi-way if snippet (`ifmw`) [[#16](https://github.com/mrcjkb/haskell-snippets.nvim/pull/16)].
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ ls.add_snippets('haskell', haskell_snippets, { key = 'haskell' })

![tty](https://github.com/mrcjkb/haskell-snippets.nvim/assets/12857160/c62eac49-e06c-4ed9-9a9c-b987c1ad498c)

#### `haskell-snippets.module.impc`

- Trigger: `impc`
- Requires a tree-sitter parser for Haskell.

![tty](https://github.com/mrcjkb/haskell-snippets.nvim/assets/12857160/6ffc5f2f-c734-4e48-ac13-99ba1f9a0b18)

#### `haskell-snippets.module.qualc`

- Trigger: `qualc`
- Requires a tree-sitter parser for Haskell.

![tty](https://github.com/mrcjkb/haskell-snippets.nvim/assets/12857160/43cef52f-eeda-48ad-bb2d-86241ac715b2)

### Data and typeclasses

#### `haskell-snippets.data.adt`
Expand Down
166 changes: 138 additions & 28 deletions doc/haskell-snippets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,29 @@ HaskellSnippetCollection *HaskellSnippetCollection*

PragmaSnippetCollection *PragmaSnippetCollection*

Fields: ~
{prag} (Snippet) Compiler pragma
{lang} (Snippet) Language pragma
{discover} (Snippet) Hspec/Sydtest discover GHC option
{nowarn} (Snippet) GHC option

pragmas.prag *pragmas.prag*

Type: ~
(Snippet) Compiler pragma


pragmas.lang *pragmas.lang*

Type: ~
(Snippet) Language pragma


pragmas.discover *pragmas.discover*

Type: ~
(Snippet) Hspec/Sydtest discover GHC option


pragmas.nowarn *pragmas.nowarn*

Type: ~
(Snippet) GHC option


==============================================================================
Expand All @@ -43,9 +61,29 @@ PragmaSnippetCollection *PragmaSnippetCollection*

ModuleSnippetCollection *ModuleSnippetCollection*

Fields: ~
{mod} (Snippet) Module declaration
{qual} (Snippet) Qualified import

module.mod *module.mod*

Type: ~
(Snippet) Module declaration


module.qual *module.qual*

Type: ~
(Snippet) Qualified import


module.impc *module.impc*

Type: ~
(Snippet|nil) Import (child module)


module.qualc *module.qualc*

Type: ~
(Snippet|nil) Qualified import (child module)


==============================================================================
Expand All @@ -55,13 +93,41 @@ ModuleSnippetCollection *ModuleSnippetCollection*

DataSnippetCollection *DataSnippetCollection*

Fields: ~
{adt} (Snippet) Algebraic data type
{newtype} (Snippet) newtype
{rec} (Snippet) Record
{cls} (Snippet) Typeclass
{ins} (Snippet) Typeclass instance
{constraint} (Snippet) Typeclass constraint

data.adt *data.adt*

Type: ~
(Snippet) Algebraic data type


data.newtype *data.newtype*

Type: ~
(Snippet) newtype


data.rec *data.rec*

Type: ~
(Snippet) Record


data.cls *data.cls*

Type: ~
(Snippet) Typeclass


data.ins *data.ins*

Type: ~
(Snippet) Typeclass instance


data.constraint *data.constraint*

Type: ~
(Snippet) Typeclass constraint


==============================================================================
Expand All @@ -71,10 +137,23 @@ DataSnippetCollection *DataSnippetCollection*

FunctionSnippetCollection *FunctionSnippetCollection*

Fields: ~
{fun} (Snippet) Function and type signature
{func} (Snippet) Function and type signature (multi-line)
{lambda} (Snippet) Lambda

functions.fn *functions.fn*

Type: ~
(Snippet) Function and type signature


functions.func *functions.func*

Type: ~
(Snippet) Function and type signature (multi-line)


functions.lambda *functions.lambda*

Type: ~
(Snippet) Lambda


==============================================================================
Expand All @@ -84,12 +163,35 @@ FunctionSnippetCollection *FunctionSnippetCollection*

ExpressionSnippetCollection *ExpressionSnippetCollection*

Fields: ~
{if_expr} (Snippet) if expression
{if_expr_multiline} (Snippet) if expression (multi-line)
{if_expr_multiway} (Snippet) if expression (multi-way)
{case} (Snippet) case expression (pattern match)
{lambdacase} (Snippet) lambda case (pattern match)

expressions.if_expr *expressions.if_expr*

Type: ~
(Snippet) if expression


expressions.if_expr_multiline *expressions.if_expr_multiline*

Type: ~
(Snippet) if expression (multi-line)


expressions.if_expr_multiway *expressions.if_expr_multiway*

Type: ~
(Snippet) if expression (multi-way)


expressions.case *expressions.case*

Type: ~
(Snippet) case expression (pattern match)


expressions.lambdacase *expressions.lambdacase*

Type: ~
(Snippet) lambda case (pattern match)


==============================================================================
Expand All @@ -99,9 +201,17 @@ ExpressionSnippetCollection *ExpressionSnippetCollection*

QuasiQuoteSnippetCollection *QuasiQuoteSnippetCollection*

Fields: ~
{qq} (Snippet) QuasiQuote
{sql} (Snippet) postgres-simple [sql||] QuasiQuote

quasiquotes.qq *quasiquotes.qq*

Type: ~
(Snippet) QuasiQuote


quasiquotes.sql *quasiquotes.sql*

Type: ~
(Snippet) postgres-simple [sql||] QuasiQuote


vim:tw=78:ts=8:noet:ft=help:norl:
9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@
devShell = pkgs.mkShell {
name = "haskell-snippets-devShell";
inherit (pre-commit-check) shellHook;
buildInputs = with pkgs; [
zlib
buildInputs = with pre-commit-hooks.packages.${system}; [
alejandra
lua-language-server
stylua
luacheck
editorconfig-checker
markdownlint-cli
];
};
in {
Expand Down
15 changes: 7 additions & 8 deletions lua/haskell-snippets/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
---@brief ]]

---@class DataSnippetCollection
---@field adt Snippet Algebraic data type
---@field newtype Snippet newtype
---@field rec Snippet Record
---@field cls Snippet Typeclass
---@field ins Snippet Typeclass instance
---@field constraint Snippet Typeclass constraint

---@type DataSnippetCollection
local data = {
---@type Snippet[] All data-related snippets
all = {},
}

Expand Down Expand Up @@ -44,6 +37,7 @@ adt_constructor_choice = function()
})
end

---@type Snippet Algebraic data type
data.adt = s({
trig = 'adt',
dscr = 'Algebraic data type',
Expand Down Expand Up @@ -71,6 +65,7 @@ data.adt = s({
})
table.insert(data.all, data.adt)

---@type Snippet newtype
data.newtype = s({
trig = 'new',
dscr = 'newtype',
Expand Down Expand Up @@ -116,6 +111,7 @@ record_field_choice = function()
})
end

---@type Snippet Record
data.rec = s({
trig = 'rec',
dscr = 'Record',
Expand Down Expand Up @@ -160,6 +156,7 @@ data.rec = s({
})
table.insert(data.all, data.rec)

---@type Snippet Typeclass
data.cls = s({
trig = 'cls',
dscr = 'Typeclass',
Expand All @@ -173,6 +170,7 @@ data.cls = s({
})
table.insert(data.all, data.cls)

---@type Snippet Typeclass instance
data.ins = s({
trig = 'ins',
dscr = 'Typeclass instance',
Expand All @@ -188,6 +186,7 @@ data.ins = s({
})
table.insert(data.all, data.ins)

---@type Snippet Typeclass constraint
data.constraint = s({
trig = '=>',
descr = 'Typeclass constraint',
Expand Down
13 changes: 6 additions & 7 deletions lua/haskell-snippets/expressions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
---@brief ]]

---@class ExpressionSnippetCollection
---@field if_expr Snippet if expression
---@field if_expr_multiline Snippet if expression (multi-line)
---@field if_expr_multiway Snippet if expression (multi-way)
---@field case Snippet case expression (pattern match)
---@field lambdacase Snippet lambda case (pattern match)

---@type ExpressionSnippetCollection
local expressions = {
---@type Snippet[] All expression-related snippets
all = {},
}

Expand All @@ -24,6 +18,7 @@ local text = ls.text_node
local insert = ls.insert_node
local dynamic = ls.dynamic_node

---@type Snippet if expression
expressions.if_expr = s({
trig = 'if',
dscr = 'If expression (single line)',
Expand All @@ -37,6 +32,7 @@ expressions.if_expr = s({
})
table.insert(expressions.all, expressions.if_expr)

---@type Snippet if expression (multi-line)
expressions.if_expr_multiline = s({
trig = 'iff',
dscr = 'If expression (multi lines)',
Expand All @@ -50,6 +46,7 @@ expressions.if_expr_multiline = s({
})
table.insert(expressions.all, expressions.if_expr_multiline)

---@type Snippet if expression (multi-way)
expressions.if_expr_multiway = s({
trig = 'ifmw',
dscr = 'If expression (multi-way)',
Expand All @@ -68,6 +65,7 @@ expressions.if_expr_multiway = s({
})
table.insert(expressions.all, expressions.if_expr_multiway)

---@type Snippet case expression (pattern match)
expressions.case = s({
trig = 'case',
dscr = 'Case expression (pattern match)',
Expand All @@ -84,6 +82,7 @@ expressions.case = s({
})
table.insert(expressions.all, expressions.case)

---@type Snippet lambda case (pattern match)
expressions.lambdacase = s({
trig = '\\case',
dscr = 'Lambda (pattern match)',
Expand Down
Loading

0 comments on commit 63d01a7

Please sign in to comment.