8 changed files with 262 additions and 65 deletions
@ -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)"
|
@ -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> |
||||||
|
``` |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -0,0 +1,3 @@ |
|||||||
|
let mapleader = "\<Space>" |
||||||
|
|
||||||
|
nnoremap <silent> <Leader>. :call pointfree#suggestions()<CR> |
@ -1,67 +1,90 @@ |
|||||||
{ |
{ |
||||||
"coc.preferences.formatOnSaveFiletypes": [], |
"coc.preferences.formatOnSaveFiletypes": ["haskell", "lhaskell", "hs", "lhs", "terraform", "hcl"], |
||||||
"codeLens.enable": true, |
"coc.preferences.enableMarkdown": true, |
||||||
"diagnostic.errorSign": "✖", |
"coc.preferences.jumpCommand": "tab drop", |
||||||
"suggest.autoTrigger": "none", |
"outline.expandLevel": 3, |
||||||
"languageserver": { |
"outline.showLineNumber": true, |
||||||
"golang": { |
"outline.keepWindow": false, |
||||||
"command": "gopls", |
"codeLens.position": "eol", |
||||||
"rootPatterns": ["go.mod", ".vim/", ".git/"], |
"codeLens.enable": true, |
||||||
"filetypes": ["go"], |
"diagnostic.errorSign": "✖", |
||||||
"initializationOptions": { |
"diagnostic.virtualText": false, |
||||||
"usePlaceholders": true |
"diagnostic.virtualTextCurrentLineOnly": false, |
||||||
} |
"diagnostic.virtualTextLines": 1, |
||||||
}, |
"suggest.autoTrigger": "none", |
||||||
"bash": { |
"suggest.disableKind": true, |
||||||
"command": "bash-language-server", |
"languageserver": { |
||||||
"args": ["start"], |
"golang": { |
||||||
"filetypes": ["sh"], |
"command": "gopls", |
||||||
"ignoredRootPaths": ["~"] |
"rootPatterns": ["go.mod", ".vim/", ".git/"], |
||||||
}, |
"filetypes": ["go"], |
||||||
"haskell": { |
"initializationOptions": { |
||||||
"command": "haskell-language-server-wrapper", |
"usePlaceholders": true |
||||||
"args": ["--lsp", "--debug"], |
} |
||||||
"rootPatterns": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml"], |
}, |
||||||
"filetypes": ["haskell", "lhaskell"], |
"bash": { |
||||||
"settings": { |
"command": "bash-language-server", |
||||||
"languageServerHaskell": { |
"args": ["start"], |
||||||
"hlintOn": true, |
"filetypes": ["sh"], |
||||||
"maxNumberOfProblems": 10, |
"ignoredRootPaths": ["~"] |
||||||
"completionSnippetsOn": true, |
}, |
||||||
"formattingProvider": "none" |
"haskell": { |
||||||
} |
"command": "haskell-language-server-wrapper", |
||||||
} |
"args": ["--lsp", "--debug"], |
||||||
}, |
"rootPatterns": [ |
||||||
"nix": { |
"*.cabal", |
||||||
"command": "rnix-lsp", |
"cabal.config", |
||||||
"filetypes": ["nix"] |
"cabal.project", |
||||||
}, |
"hie.yaml", |
||||||
"python": { |
"package.yaml", |
||||||
"command": "pylsp", |
"stack.yaml" |
||||||
"filetypes": ["python"], |
], |
||||||
"ignoredRootPaths": ["~"] |
"filetypes": [ |
||||||
}, |
"hs", |
||||||
"racket": { |
"lhs", |
||||||
"command": "racket", |
"haskell", |
||||||
"args": [ |
"lhaskell" |
||||||
"--lib", |
], |
||||||
"racket-langserver" |
"settings": { |
||||||
], |
"languageServerHaskell": { |
||||||
"filetypes": [ |
"hlintOn": true, |
||||||
"scheme", |
"maxNumberOfProblems": 20, |
||||||
"racket" |
"completionSnippetsOn": true, |
||||||
] |
"formattingProvider": "stylish-haskell" |
||||||
}, |
}, |
||||||
"terraform": { |
"initializationOptions": {} |
||||||
"command": "terraform-ls", |
} |
||||||
"args": ["serve"], |
}, |
||||||
//"command": "terraform-lsp", |
"nix": { |
||||||
"filetypes": [ |
"command": "rnix-lsp", |
||||||
"terraform", |
"filetypes": ["nix"] |
||||||
"tf" |
}, |
||||||
], |
"python": { |
||||||
"initializationOptions": {}, |
"command": "pylsp", |
||||||
"settings": {} |
"filetypes": ["python"], |
||||||
} |
"ignoredRootPaths": ["~"] |
||||||
} |
}, |
||||||
|
"racket": { |
||||||
|
"command": "racket", |
||||||
|
"args": [ |
||||||
|
"--lib", |
||||||
|
"racket-langserver" |
||||||
|
], |
||||||
|
"filetypes": [ |
||||||
|
"scheme", |
||||||
|
"racket" |
||||||
|
] |
||||||
|
}, |
||||||
|
"terraform": { |
||||||
|
"command": "terraform-ls", |
||||||
|
"args": ["serve"], |
||||||
|
//"command": "terraform-lsp", |
||||||
|
"filetypes": [ |
||||||
|
"terraform", |
||||||
|
"tf" |
||||||
|
], |
||||||
|
"initializationOptions": {}, |
||||||
|
"settings": {} |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue