Last active
March 2, 2021 21:10
-
-
Save sago35/4181c9d7ca26b2a3fe0ef2d2ededb931 to your computer and use it in GitHub Desktop.
tinygo integration for vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:ChangeTinygoTargetTo(target) | |
let info = split(system('tinygo info -target ' . a:target), "\n") | |
for i in info | |
let data = split(i) | |
if len(data) > 2 && data[0] == "build" && data[1] == "tags:" | |
let s:goflags = "-tags=" . join(data[2:-1], ",") | |
elseif len(data) > 2 && data[0] == "cached" && data[1] == "GOROOT:" | |
let s:goroot = join(data[2:-1], ",") | |
endif | |
endfor | |
if exists("s:goroot") && exists("s:goflags") | |
if exists($GOROOT) | |
let s:org_goroot = $GOROOT | |
unlet $GOROOT | |
endif | |
if exists($GOFLAGS) | |
let s:org_goflags = $GOFLAGS | |
unlet $GOFLAGS | |
endif | |
let $GOROOT = s:goroot | |
let $GOFLAGS = s:goflags | |
call execute("LspStopServer") | |
call execute("sleep 100m") | |
call execute("edit") | |
if exists("s:org_goroot") | |
let $GOROOT = s:org_goroot | |
unlet s:org_goroot | |
else | |
unlet $GOROOT | |
endif | |
if exists("s:org_goflags") | |
let $GOFLAGS = s:org_goflags | |
unlet s:org_goflags | |
else | |
unlet $GOFLAGS | |
endif | |
else | |
echo "some problem with `tinygo info -target " . a:target . "` execution" | |
endif | |
endfunction | |
function! s:ChangeTinygoTarget() | |
30vnew | |
setlocal winfixwidth | |
setlocal bufhidden=wipe | |
setlocal buftype=nofile | |
setlocal nonu | |
let targets = split(system('tinygo targets')) | |
for target in targets | |
put=target | |
endfor | |
call execute('global/^$/d') | |
nmap <buffer> <Enter> :let target = getline('.')<CR>:quit<CR>:execute 'TinygoTarget ' . target<CR> | |
endfunction | |
function! s:TinygoTarget(...) | |
if !executable('tinygo') | |
echo '"tinygo": executable file not found in $PATH' | |
return | |
endif | |
if a:0 >= 1 | |
call s:ChangeTinygoTargetTo(a:1) | |
else | |
call s:ChangeTinygoTarget() | |
end | |
endfunction | |
function! s:TinygoTargets(A, L, P) | |
if !executable('tinygo') | |
return ['"tinygo": executable file not found in $PATH'] | |
endif | |
let s:targets = split(system('tinygo targets'), "\n") | |
return filter(s:targets, 'v:val =~? "^' . a:A . '"') | |
endfunction | |
command! -complete=customlist,s:TinygoTargets -nargs=? TinygoTarget :cal s:TinygoTarget(<f-args>) | |
" https://gist.github.com/mattn/1321853/ae54510366d7999ebdeb2f91b7416bf78fff32bd | |
" fun! s:SelectColorS() | |
" 30vnew | |
" setlocal bufhidden=wipe | |
" setlocal buftype=nofile | |
" setlocal nonu | |
" let files = split(glob(expand('~/.vim/colors/').'*')) | |
" for file in files | |
" let name = matchstr( file , '\w\+\(\.vim\)\@=' ) | |
" put=name | |
" endfor | |
" com! -buffer SetColor :exec 'colors ' . getline('.') | |
" nmap <buffer> <Enter> :SetColor<CR> | |
" endf | |
" com! SelectColorS :cal s:SelectColorS() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment