Browse Source

vim: ++haskell, pointfree, coc

Maxim Likhachev 3 years ago
parent
commit
a736693f07
  1. 8
      etc/soft/nvim/+plugins/vim-pointfree/Makefile
  2. 24
      etc/soft/nvim/+plugins/vim-pointfree/README.md
  3. 45
      etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree.vim
  4. 19
      etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree/line.vim
  5. 48
      etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree/visual.vim
  6. 27
      etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree/window.vim
  7. 3
      etc/soft/nvim/+plugins/vim-pointfree/tools/init.vim
  8. 35
      etc/soft/nvim/coc-settings.json

8
etc/soft/nvim/+plugins/vim-pointfree/Makefile

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
POINTFREE := $(shell pwd)
TOOLS := $(POINTFREE)/tools
vim:
@vim -u $(TOOLS)/init.vim --cmd "set rtp=$(POINTFREE)"
nvim:
@nvim -u $(TOOLS)/init.vim --cmd "set rtp=$(POINTFREE)"

24
etc/soft/nvim/+plugins/vim-pointfree/README.md

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
use vim to pointfree your haskell functions
---
### Installation
vim-pointfree depends on
[pointfree](https://hackage.haskell.org/package/pointfree), so make sure that
it is installed and available in your $PATH.
To install using vim-plug:
```viml
Plug 'm00qek/vim-pointfree'
```
### Configuration
add something like the following on your vimrc
```viml
nnoremap <silent> <Leader>. :call pointfree#suggestions()<CR>
vnoremap <silent> <Leader>. :call pointfree#selection()<CR>
```

45
etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree.vim

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
function! s:pointfree(expression)
let l:suggestions = system('pointfree --verbose '.shellescape(a:expression))
let l:suggestions = split(l:suggestions, "\n")[3:]
if v:shell_error == 0
return [v:true, insert(l:suggestions, a:expression)]
endif
return [v:false, "Sorry, I couldn't pointfree your expression :("]
endfunction
function! s:pointfree_window(Expression, Writer, coordinates)
let l:current_window = win_getid()
let [l:success, l:suggestions] = s:pointfree(a:Expression(a:coordinates))
if l:success
call pointfree#window#open(l:current_window,
\ l:suggestions,
\ a:Writer(l:current_window, a:coordinates))
else
echoerr l:suggestions
endif
endfunction
function! pointfree#optmized(expression)
let [l:success, l:suggestions] = s:pointfree(a:expression)
if l:success
return l:suggestions[-1]
else
echoerr l:suggestions
endif
endfunction
function! pointfree#selection()
call s:pointfree_window(function('pointfree#visual#expression'),
\ function('pointfree#visual#apply_command'),
\ pointfree#visual#coordinates())
endfunction
function! pointfree#suggestions()
call s:pointfree_window(function('pointfree#line#expression'),
\ function('pointfree#line#apply_command'),
\ pointfree#line#coordinates())
endfunction

19
etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree/line.vim

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
function! pointfree#line#coordinates()
return { 'line': line('.') }
endfunction
function! pointfree#line#apply(pointfree_window, coordinates)
let l:current_line = getline(a:firstline, a:lastline)
call pointfree#window#close(a:pointfree_window)
call setline(a:coordinates.line, l:current_line)
endfunction
function! pointfree#line#apply_command(window, coordinates)
return "pointfree#line#apply(" . a:window . ", " . string(a:coordinates). ")"
endfunction
function! pointfree#line#expression(coordinates)
return join(getline(a:firstline, a:lastline), "\n")
endfunction

48
etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree/visual.vim

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
function! pointfree#visual#coordinates()
let [start_line, start_column] = getpos("'<")[1:2]
let [end_line, end_column] = getpos("'>")[1:2]
return { 'start_line': start_line,
\ 'start_column': start_column,
\ 'end_line': end_line,
\ 'end_column': end_column
\ }
endfunction
function! pointfree#visual#apply(pointfree_window, coordinates)
let l:current_line = getline(a:firstline, a:lastline)[0]
let l:hreg = getreg("h")
call setreg("h", trim(l:current_line))
call pointfree#window#close(a:pointfree_window)
call setpos("'<", [ a:pointfree_window
\ , a:coordinates.start_line
\ , a:coordinates.start_column ])
call setpos("'>", [ a:pointfree_window
\ , a:coordinates.end_line
\ , a:coordinates.end_column ])
normal! gv"hp
call setreg("h", l:hreg)
endfunction
function! pointfree#visual#apply_command(window, coordinates)
return "pointfree#visual#apply(" . a:window . ", " . string(a:coordinates). ")"
endfunction
function! pointfree#visual#expression(coordinates)
let lines = getline(a:coordinates.start_line, a:coordinates.end_line)
if len(lines) == 0
return ''
endif
let l:start = a:coordinates.start_column - 1
let l:end = a:coordinates.end_column - (&selection == 'inclusive' ? 1 : 2)
let lines[0] = lines[0][l:start :]
let lines[-1] = lines[-1][: l:end]
return join(lines, "\n")
endfunction

27
etc/soft/nvim/+plugins/vim-pointfree/autoload/pointfree/window.vim

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
function! s:close_if_pointfree(winnr)
if &l:filetype == 'haskell.pointfree'
silent bdelete!
endif
endfunction
function! s:nmap(key, func)
execute 'nnoremap <silent> <buffer> ' . a:key . ' :call ' . a:func . '<CR>'
endfunction
function! pointfree#window#close(window)
silent windo call s:close_if_pointfree(winnr())
call win_gotoid(a:window)
endfunction
function! pointfree#window#open(current_window, suggestions, writer)
execute 'silent botright 10new'
call setline(1, a:suggestions)
setlocal readonly nomodifiable
setlocal nonumber
let &l:filetype = 'haskell.pointfree'
setlocal syntax=haskell
call s:nmap('<CR>' , a:writer)
call s:nmap('<Esc>', 'pointfree#window#close(' . a:current_window . ")")
endfunction

3
etc/soft/nvim/+plugins/vim-pointfree/tools/init.vim

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
let mapleader = "\<Space>"
nnoremap <silent> <Leader>. :call pointfree#suggestions()<CR>

35
etc/soft/nvim/coc-settings.json

@ -1,8 +1,18 @@ @@ -1,8 +1,18 @@
{
"coc.preferences.formatOnSaveFiletypes": [],
"coc.preferences.formatOnSaveFiletypes": ["haskell", "lhaskell", "hs", "lhs", "terraform", "hcl"],
"coc.preferences.enableMarkdown": true,
"coc.preferences.jumpCommand": "tab drop",
"outline.expandLevel": 3,
"outline.showLineNumber": true,
"outline.keepWindow": false,
"codeLens.position": "eol",
"codeLens.enable": true,
"diagnostic.errorSign": "✖",
"diagnostic.virtualText": false,
"diagnostic.virtualTextCurrentLineOnly": false,
"diagnostic.virtualTextLines": 1,
"suggest.autoTrigger": "none",
"suggest.disableKind": true,
"languageserver": {
"golang": {
"command": "gopls",
@ -21,15 +31,28 @@ @@ -21,15 +31,28 @@
"haskell": {
"command": "haskell-language-server-wrapper",
"args": ["--lsp", "--debug"],
"rootPatterns": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml"],
"filetypes": ["haskell", "lhaskell"],
"rootPatterns": [
"*.cabal",
"cabal.config",
"cabal.project",
"hie.yaml",
"package.yaml",
"stack.yaml"
],
"filetypes": [
"hs",
"lhs",
"haskell",
"lhaskell"
],
"settings": {
"languageServerHaskell": {
"hlintOn": true,
"maxNumberOfProblems": 10,
"maxNumberOfProblems": 20,
"completionSnippetsOn": true,
"formattingProvider": "none"
}
"formattingProvider": "stylish-haskell"
},
"initializationOptions": {}
}
},
"nix": {

Loading…
Cancel
Save