Skip to content

Commit

Permalink
seito: Add --vim-config
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Sep 15, 2024
1 parent 6a1b3a7 commit 27edad2
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
ghc: system
steps:
- uses: actions/checkout@v3

- run: vim/run_tests.vim
if: runner.os == 'Linux'

- uses: hspec/setup-haskell@v1
with:
ghc-version: ${{ matrix.ghc }}
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ Add the following to your Vim configuration (e.g.
:set makeprg=seito
```

#### Option 2: Set `makeprg`:

Add the following to `~/.vim/after/ftplugin/haskell.vim`:

```vim
let vim_config = system('seito --vim-config')
execute 'source ' . vim_config
```

### Emacs integration

Similarly, you can use `sensei` to load the result of the last test run into an
Expand Down
12 changes: 9 additions & 3 deletions driver/seito.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import System.Environment
import Control.Monad
import qualified Data.ByteString.Lazy as L

import Paths_sensei (getDataFileName)

import Client

main :: IO ()
main = do
(success, output) <- getArgs >>= client ""
L.putStr output
unless success exitFailure
getArgs >>= \ case
["--vim-config"] -> do
getDataFileName "vim/sensei.vim" >>= putStr
args -> do
(success, output) <- client "" args
L.putStr output
unless success exitFailure
4 changes: 4 additions & 0 deletions foo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# ghc -fno-diagnostics-show-caret $1 &> ${1%.*}.ghc-$(ghc --numeric-version).errors
ghc -fno-diagnostics-show-caret $1 &> ${1%.*}.ghc-$(ghc --numeric-version).errors
21 changes: 21 additions & 0 deletions hspe-foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Ok, 53 modules reloaded.
RELOADING SUCCEEDED

Command
kebabCase
converts a list of words to kebab-case [✘]

Failures:

test/CommandSpec.hs:31:39:
1) Command.kebabCase converts a list of words to kebab-case
expected: "oo-bar-baz"
but got: "foo-bar-baz"

To rerun use: --match "/Command/kebabCase/converts a list of words to kebab-case/" --seed 1821211779

Randomized with seed 1821211779

Finished in 0.0002 seconds
1 example, 1 failure
Summary {summaryExamples = 1, summaryFailures = 1}
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ default-extensions:
- RecordWildCards
- ViewPatterns

other-extensions:
- NoFieldSelectors
data-files: vim/sensei.vim

dependencies:
- base >= 4.11 && < 5
Expand Down Expand Up @@ -62,6 +61,7 @@ executables:

seito:
source-dirs: driver
generated-other-modules: Paths_sensei
main: seito.hs

tests:
Expand Down
17 changes: 7 additions & 10 deletions sensei.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions vim/run_tests.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/env -S vim -u NONE -S

set t_ti=
set t_te=

highlight red ctermfg=red
highlight green ctermfg=green

command! -nargs=* FAILURE echohl red | echo <args> | echohl none
command! -nargs=* SUCCESS echohl green | echo <args> | echohl none

try
source vim/tests.vim
catch
FAILURE substitute(v:throwpoint, "^command line..script ", "", "")
echo "\n"
FAILURE v:exception
cquit
endtry

echo "\n"

if !empty(v:errors)
FAILURE "FAILURES:\n"
for error in v:errors
echo "\n"
FAILURE substitute(substitute(substitute(error, "^command line..script ", "", ""), " Expected ", "\n\nexpected: ", ""), " but got", "\n but got:", "")
endfor
cquit
else
SUCCESS "SUCCESS"
quit
endif
10 changes: 10 additions & 0 deletions vim/sensei.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set makeprg=seito

" GHC
set errorformat=%A%f:%l:%c:\ %t%*[^:]:\ [GHC-%n]
set errorformat^=%+C\ %.%#
set errorformat^=%Z
set errorformat^=%-G\ \ \ \ Suggested\ fix:%.%#

" Hspec
set errorformat^=\ \ %f:%l:%c:\ .%#
11 changes: 11 additions & 0 deletions vim/test/assets/type-signature-lacks-binding.ghc-9.10.1.errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[1 of 2] Compiling Main ( vim/test/assets/type-signature-lacks-binding.hs, vim/test/assets/type-signature-lacks-binding.o )
vim/test/assets/type-signature-lacks-binding.hs:1:1: error: [GHC-44432]
The type signature for ‘foo’ lacks an accompanying binding
Suggested fix:
Perhaps use ‘foo_’ (Defined at vim/test/assets/type-signature-lacks-binding.hs:2:1)

vim/test/assets/type-signature-lacks-binding.hs:4:1: error: [GHC-44432]
The type signature for ‘bar’ lacks an accompanying binding
Suggested fix:
Perhaps use ‘bar_’ (Defined at vim/test/assets/type-signature-lacks-binding.hs:5:1)

5 changes: 5 additions & 0 deletions vim/test/assets/type-signature-lacks-binding.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
foo :: Int
foo_ = 23

bar :: Int
bar_ = 23
25 changes: 25 additions & 0 deletions vim/tests.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
source vim/sensei.vim

cgetfile vim/test/assets/type-signature-lacks-binding.ghc-9.10.1.errors

let errors = filter(getqflist(), 'v:val.valid')

let err1 = errors[0]
call assert_equal("vim/test/assets/type-signature-lacks-binding.hs", bufname(err1.bufnr))
call assert_equal(1, err1.lnum)
call assert_equal(1, err1.col)
call assert_equal(0, err1.end_lnum)
call assert_equal(0, err1.end_col)
call assert_equal('e', err1.type)
call assert_equal(44432, err1.nr)
call assert_equal("\n The type signature for ‘foo’ lacks an accompanying binding", err1.text)

let err2 = errors[1]
call assert_equal("vim/test/assets/type-signature-lacks-binding.hs", bufname(err2.bufnr))
call assert_equal(4, err2.lnum)
call assert_equal(1, err2.col)
call assert_equal(0, err2.end_lnum)
call assert_equal(0, err2.end_col)
call assert_equal('e', err2.type)
call assert_equal(44432, err2.nr)
call assert_equal("\n The type signature for ‘bar’ lacks an accompanying binding", err2.text)
6 changes: 6 additions & 0 deletions watch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
while true; do
echo
inotifywait -e modify -e attrib -e close_write -e move -e create -e delete -r vim/
./vim/run_tests.vim
done

0 comments on commit 27edad2

Please sign in to comment.