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 19, 2024
1 parent aa2c6aa commit 445c2e6
Show file tree
Hide file tree
Showing 44 changed files with 510 additions and 27 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
Expand All @@ -30,7 +31,8 @@ jobs:
- os: macos-12
ghc: system
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: hspec/setup-haskell@v1
with:
ghc-version: ${{ matrix.ghc }}
Expand All @@ -47,7 +49,7 @@ jobs:
# https://github.com/actions/runner-images/blob/macOS-12/20230416.1/images/macos/macos-12-Readme.md#tools
#
# (on Linux this is a noop)
run: ghcup install cabal 3.10 --set
run: ghcup install cabal latest --set

- shell: bash
run: git config --global init.defaultBranch main
Expand All @@ -66,6 +68,23 @@ jobs:
env:
HSPEC_OPTIONS: --color

- run: vim/test/run.vim
if: ${{ runner.os == 'Linux' && matrix.ghc != '9.4' }}

- run: vim/test/assets/generate.sh
if: runner.os == 'Linux'

- run: git diff --exit-code

- shell: bash
run: |
untracked=$(git ls-files --others --exclude-standard)
if [ -n "$untracked" ]; then
echo "Untracked files:"
echo "$untracked"
exit 1
fi
success:
needs: build
runs-on: ubuntu-latest
Expand All @@ -75,6 +94,6 @@ jobs:
- run: false
if: needs.build.result != 'success'

- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Check for trailing whitespace
run: '! git grep -I "\s\+$"'
run: "! git grep -nI '[[:blank:]]$' -- . ':!vim/test/assets'"
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ instead:

### Vim integration

You can use `sensei` to load the result of the last test run into your quickfix
You can use `seito` to load the results of the last test run into your quickfix
list by executing `:make` in Vim.

For this to work, you can either create a `Makefile` or set `makeprg` to a
custom value.
For this to work, you can choose one out of three options:

(In both cases, `sed` is used to strip ANSI color sequences.)
1. Create a `Makefile`
2. Set `makeprg` to a custom value
3. Use [`sensei.vim`](vim/sensei.vim)

#### Option 1: Create a `Makefile`

Expand All @@ -78,6 +79,15 @@ Add the following to your Vim configuration (e.g.
:set makeprg=seito
```

#### Option 3: Use `sensei.vim`:

Add the following to your Vim configuration (e.g.
`~/.vim/after/ftplugin/haskell.vim`):

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

### Emacs integration

Similarly, you can use `sensei` to load the result of the last test run into an
Expand Down
4 changes: 3 additions & 1 deletion driver/seito.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ 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 ""
(success, output) <- getArgs >>= client getDataFileName ""
L.putStr output
unless success exitFailure
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.

5 changes: 3 additions & 2 deletions src/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import qualified Data.ByteString.Lazy as L

import HTTP (newSocket, socketName)

client :: FilePath -> [String] -> IO (Bool, L.ByteString)
client dir args = case args of
client :: (FilePath -> IO FilePath) -> FilePath -> [String] -> IO (Bool, L.ByteString)
client getDataFileName dir args = case args of
[] -> hIsTerminalDevice stdout >>= run
["--no-color"] -> run False
["--color"] -> run True
["--vim-config"] -> (,) True . fromString <$> getDataFileName "vim/sensei.vim"
_ -> do
hPutStrLn stderr $ "Usage: seito [ --color | --no-color ]"
return (False, "")
Expand Down
12 changes: 8 additions & 4 deletions test/ClientSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ spec = do
describe "client" $ do
it "accepts --color" $ do
withSuccess $ \ dir -> do
client dir ["--color"] `shouldReturn` (True, fromString $ withColor Green "success")
client return dir ["--color"] `shouldReturn` (True, fromString $ withColor Green "success")

it "accepts --no-color" $ do
withSuccess $ \ dir -> do
client dir ["--no-color"] `shouldReturn` (True, "success")
client return dir ["--no-color"] `shouldReturn` (True, "success")

it "indicates failure" $ do
withFailure $ \ dir -> do
client dir [] `shouldReturn` (False, "failure")
client return dir [] `shouldReturn` (False, "failure")

context "when server socket is missing" $ do
it "reports error" $ do
withTempDirectory $ \ dir -> do
client dir [] `shouldReturn` (False, "could not connect to " <> fromString (socketName dir) <> "\n")
client return dir [] `shouldReturn` (False, "could not connect to " <> fromString (socketName dir) <> "\n")

context "with --vim-config" $ do
it "returns a path to Vim support files" $ do
client return undefined ["--vim-config"] `shouldReturn` (True, "vim/sensei.vim")
165 changes: 165 additions & 0 deletions vim/sensei.test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
source vim/sensei.vim

function Require(actual, required)
for i in range(len(a:required))
if a:actual[i] > a:required[i]
return 1
elseif a:actual[i] < a:required[i]
return 0
endif
endfor
return 1
endfunction

function GhcVersion(name)
return matchlist(a:name, '\vghc-(\d+)\.(\d+)\.(\d+)\.errors')[1:3]
endfunction

function PopulateQuickFixList(name)
SUCCESS a:name
execute "cgetfile " . a:name
return filter(getqflist(), 'v:val.valid')
endfunction

function GhcErrorsFor(name)
let errors = glob("vim/test/assets/" . a:name . ".*.errors", v:true, v:true)
call ShouldBe(len(errors), 5)
return errors
endfunction

for name in GhcErrorsFor("lexical-error.hs")
let errors = PopulateQuickFixList(name)
call ShouldBe(len(errors), 1)

let err = errors[0]
call ShouldBe(bufname(err.bufnr), "lexical-error.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 11)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call ShouldBe(err.nr, 21231)
else
call ShouldBe(err.nr, -1)
endif
call ShouldBe(err.text, "\n lexical error in string/character literal at character '\\n'")
endfor

for name in GhcErrorsFor("parse-error.hs")
let errors = PopulateQuickFixList(name)
call ShouldBe(len(errors), 1)

let err = errors[0]
call ShouldBe(bufname(err.bufnr), "parse-error.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,8])
call ShouldBe(err.nr, 25277)
else
call ShouldBe(err.nr, -1)
endif
call ShouldBe(err.text, "\n Parse error: module header, import declaration\n or top-level declaration expected.")
endfor

for name in GhcErrorsFor("type-error.hs")
let errors = PopulateQuickFixList(name)
call ShouldBe(len(errors), 1)

let err = errors[0]
call ShouldBe(bufname(err.bufnr), "type-error.hs")
call ShouldBe(err.lnum, 2)
call ShouldBe(err.col, 7)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call ShouldBe(err.nr, 83865)
call ShouldBe(err.text, "\n Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int")
else
call ShouldBe(err.nr, -1)
call ShouldBe(err.text, "\n • Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int\n • In the expression: 23 :: Int\n In an equation for ‘foo’: foo = 23 :: Int")
endif
endfor

for name in GhcErrorsFor("suggested-fix.hs")
let errors = PopulateQuickFixList(name)
call ShouldBe(len(errors), 2)

let err = errors[0]
call ShouldBe(bufname(err.bufnr), "suggested-fix.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call ShouldBe(err.nr, 44432)
else
call ShouldBe(err.nr, -1)
endif
call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding")

let err = errors[1]
call ShouldBe(bufname(err.bufnr), "suggested-fix.hs")
call ShouldBe(err.lnum, 4)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call ShouldBe(err.nr, 44432)
else
call ShouldBe(err.nr, -1)
endif
call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding")
endfor

for name in GhcErrorsFor("suggested-fix-multiline.hs")
let errors = PopulateQuickFixList(name)
call ShouldBe(len(errors), 2)

let err = errors[0]
call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call ShouldBe(err.nr, 44432)
else
call ShouldBe(err.nr, -1)
endif
call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding")

let err = errors[1]
call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs")
call ShouldBe(err.lnum, 4)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call ShouldBe(err.nr, 44432)
else
call ShouldBe(err.nr, -1)
endif
call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding")
endfor

let errors = PopulateQuickFixList("vim/test/assets/hspec.hs.errors")
call ShouldBe(len(errors), 1)

let err = errors[0]
call ShouldBe(bufname(err.bufnr), "vim/test/assets/hspec.hs")
call ShouldBe(err.lnum, 6)
call ShouldBe(err.col, 11)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, '')
call ShouldBe(err.nr, -1)
call ShouldBe(err.text, "")
Loading

0 comments on commit 445c2e6

Please sign in to comment.