Skip to content

Commit

Permalink
feat(repl): add Ex commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Sep 14, 2023
1 parent 1125e21 commit e3f2455
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Health: Check for conflicting `lspconfig.hls` configuration.
- New commands: `:HlsEvalAll`
- New commands: `HlsEvalAll`, `HtReplToggle`, `HtReplQuit`, `HtReplLoad`, `HtReplReload`

### Fixed
- Builtin repl: Broken toggle
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ ht.hoogle.hoogle_signature()

#### Repl

| Command | Description | Arguments |
| --------------- | ----------------------------------- | ------------------- |
| `:HtReplToggle` | Toggle a GHCi repl | filepath (optional) |
| `:HtReplQuit` | Quit the current repl | |
| `:HtReplLoad` | Load a file into the current repl | filepath (required) |
| `:HtReplReoad` | Reload the current repl | |

```lua
local ht = require('haskell-tools')
--- Toggle a GHCi repl for the current project
Expand Down
8 changes: 8 additions & 0 deletions doc/haskell-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ haskell-language-server LSP client tools *haskell-tools.lsp*
* `:HlsStart` - Start the LSP client.
* `:HlsStop` - Stop the LSP client.
* `:HlsRestart` - Restart the LSP client.
* `:HlsEvalAll` - Evaluate all code snippets in comments.

LoadHlsSettingsOpts *LoadHlsSettingsOpts*

Expand Down Expand Up @@ -326,6 +327,13 @@ HoogleTools.hoogle_signature({options}) *HoogleTools.hoogle_signature*
==============================================================================
haskell-tools GHCi REPL module *haskell-tools.repl*

The following commands are available:

* `:HtReplToggle` - Toggle a GHCi repl.
* `:HtReplQuit` - Quit the current repl.
* `:HtReplLoad` - Load a Haskell file into the repl.
* `:HtReplReload` - Reload the current repl.

HsReplTools *HsReplTools*


Expand Down
1 change: 1 addition & 0 deletions lua/haskell-tools/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local uv = vim.uv
--- * `:HlsStart` - Start the LSP client.
--- * `:HlsStop` - Stop the LSP client.
--- * `:HlsRestart` - Restart the LSP client.
--- * `:HlsEvalAll` - Evaluate all code snippets in comments.
---@brief ]]

---To minimise the risk of this occurring, we attempt to shut down hls cleanly before exiting neovim.
Expand Down
50 changes: 50 additions & 0 deletions lua/haskell-tools/repl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
---Tools for interaction with a GHCi REPL
---@bruief ]]

---@brief [[
--- The following commands are available:
---
--- * `:HtReplToggle` - Toggle a GHCi repl.
--- * `:HtReplQuit` - Quit the current repl.
--- * `:HtReplLoad` - Load a Haskell file into the repl.
--- * `:HtReplReload` - Reload the current repl.
---@brief ]]

local log = require('haskell-tools.log.internal')
local Types = require('haskell-tools.types.internal')

Expand Down Expand Up @@ -237,4 +246,45 @@ end

vim.keymap.set('n', 'ghc', HsReplTools.operator, { noremap = true })

local commands = {
{
'HtReplToggle',
---@param tbl table
function(tbl)
local filepath = tbl.args ~= '' and vim.fn.expand(tbl.args)
---@cast filepath string
HsReplTools.toggle(filepath)
end,
{ nargs = '?' },
},
{
'HtReplLoad',
---@param tbl table
function(tbl)
local filepath = vim.fn.expand(tbl.args)
---@cast filepath string
HsReplTools.load_file(filepath)
end,
{ nargs = 1 },
},
{
'HtReplQuit',
function()
HsReplTools.quit()
end,
{},
},
{
'HtReplReload',
function()
HsReplTools.reload()
end,
{},
},
}

for _, command in ipairs(commands) do
vim.api.nvim_create_user_command(unpack(command))
end

return HsReplTools

0 comments on commit e3f2455

Please sign in to comment.