Updated plugins
This commit is contained in:
parent
a6de243fca
commit
fe46dfbbe6
141 changed files with 2790 additions and 1630 deletions
|
@ -303,7 +303,6 @@ fu! s:match_window_opts()
|
|||
let s:mw_res =
|
||||
\ s:mw =~ 'results:[^,]\+' ? str2nr(matchstr(s:mw, 'results:\zs\d\+'))
|
||||
\ : min([s:mw_max, &lines])
|
||||
let s:mw_res = max([s:mw_res, 1])
|
||||
endf
|
||||
"}}}1
|
||||
" * Open & Close {{{1
|
||||
|
@ -1995,9 +1994,14 @@ fu! s:bufnrfilpath(line)
|
|||
en
|
||||
let filpath = fnamemodify(filpath, ':p')
|
||||
let bufnr = bufnr('^'.filpath.'$')
|
||||
if (a:line =~ '[\/]\?\[\d\+\*No Name\]$' && !filereadable(filpath) && bufnr < 1)
|
||||
let bufnr = str2nr(matchstr(a:line, '[\/]\?\[\zs\d\+\ze\*No Name\]$'))
|
||||
let filpath = bufnr
|
||||
if (!filereadable(filpath) && bufnr < 1)
|
||||
if (a:line =~ '[\/]\?\[\d\+\*No Name\]$')
|
||||
let bufnr = str2nr(matchstr(a:line, '[\/]\?\[\zs\d\+\ze\*No Name\]$'))
|
||||
let filpath = bufnr
|
||||
else
|
||||
let bufnr = bufnr(a:line)
|
||||
retu [bufnr, a:line]
|
||||
en
|
||||
en
|
||||
retu [bufnr, filpath]
|
||||
endf
|
||||
|
|
|
@ -137,8 +137,8 @@ fu! ctrlp#tag#id()
|
|||
endf
|
||||
|
||||
fu! ctrlp#tag#enter()
|
||||
let tfs = tagfiles()
|
||||
let s:tagfiles = tfs != [] ? filter(map(tfs, 'fnamemodify(v:val, ":p")'),
|
||||
let tfs = get(g:, 'ctrlp_custom_tag_files', tagfiles())
|
||||
let s:tagfiles = type(tfs) == 3 && tfs != [] ? filter(map(tfs, 'fnamemodify(v:val, ":p")'),
|
||||
\ 'filereadable(v:val)') : []
|
||||
endf
|
||||
"}}}
|
||||
|
|
|
@ -148,6 +148,7 @@ The minimum and maximum heights:
|
|||
|
||||
The maximum number of results:
|
||||
results:{n} - list maximum {n} results (default: sync with max height).
|
||||
0 mean no-limit.
|
||||
|
||||
Note: When a setting isn't set, its default value will be used.
|
||||
|
||||
|
@ -1497,6 +1498,9 @@ Special thanks:~
|
|||
===============================================================================
|
||||
CHANGELOG *ctrlp-changelog*
|
||||
|
||||
* New option |g:ctrlp_custom_tag_files| to specify custom tag files.
|
||||
* Accept 0 for g:ctrlp_match_window no-limited window size.
|
||||
|
||||
Before 2016/11/28~
|
||||
|
||||
+ New command: |YankLine()| to yank current line.
|
||||
|
|
|
@ -122,7 +122,7 @@ function! s:tranquilize()
|
|||
endfunction
|
||||
|
||||
function! s:hide_statusline()
|
||||
let &l:statusline = repeat(' ', winwidth(0))
|
||||
setlocal statusline=\
|
||||
endfunction
|
||||
|
||||
function! s:hide_linenr()
|
||||
|
@ -239,7 +239,7 @@ function! s:goyo_on(dim)
|
|||
set showtabline=0
|
||||
set noruler
|
||||
set fillchars+=vert:\
|
||||
set fillchars+=stl:.
|
||||
set fillchars+=stl:\
|
||||
set fillchars+=stlnc:\
|
||||
set sidescroll=1
|
||||
set sidescrolloff=0
|
||||
|
|
|
@ -301,10 +301,10 @@ endfunction
|
|||
"FUNCTION: Path._escChars() {{{1
|
||||
function! s:Path._escChars()
|
||||
if nerdtree#runningWindows()
|
||||
return " `\|\"#%&,?()\*^<>"
|
||||
return " `\|\"#%&,?()\*^<>$"
|
||||
endif
|
||||
|
||||
return " \\`\|\"#%&,?()\*^<>[]"
|
||||
return " \\`\|\"#%&,?()\*^<>[]$"
|
||||
endfunction
|
||||
|
||||
"FUNCTION: Path.getDir() {{{1
|
||||
|
|
|
@ -3226,7 +3226,7 @@ accepts the standard options described at |syntastic-config-makeprg|.
|
|||
|
||||
Notes~
|
||||
|
||||
Syntastic requires "Flow" version 0.18.1 or later.
|
||||
Syntastic requires "Flow" version 0.34.0 or later.
|
||||
|
||||
To use "Flow" with your projects, you must:
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ if has('reltime')
|
|||
lockvar! g:_SYNTASTIC_START
|
||||
endif
|
||||
|
||||
let g:_SYNTASTIC_VERSION = '3.8.0-10'
|
||||
let g:_SYNTASTIC_VERSION = '3.8.0-21'
|
||||
lockvar g:_SYNTASTIC_VERSION
|
||||
|
||||
" Sanity checks {{{1
|
||||
|
@ -67,6 +67,15 @@ else
|
|||
endif
|
||||
lockvar g:_SYNTASTIC_UNAME
|
||||
|
||||
" XXX Ugly hack to make g:_SYNTASTIC_UNAME available to :SyntasticInfo without
|
||||
" polluting session namespaces
|
||||
let g:syntastic_version =
|
||||
\ g:_SYNTASTIC_VERSION .
|
||||
\ ' (Vim ' . v:version . (has('nvim') ? ', Neovim' : '') . ', ' .
|
||||
\ g:_SYNTASTIC_UNAME .
|
||||
\ (has('gui') ? ', GUI' : '') . ')'
|
||||
lockvar g:syntastic_version
|
||||
|
||||
" }}}1
|
||||
|
||||
" Defaults {{{1
|
||||
|
@ -344,13 +353,6 @@ function! s:BufWinEnterHook(fname) abort " {{{2
|
|||
endfunction " }}}2
|
||||
|
||||
function! s:VimEnterHook() abort " {{{2
|
||||
let g:syntastic_version =
|
||||
\ g:_SYNTASTIC_VERSION .
|
||||
\ ' (Vim ' . v:version . (has('nvim') ? ', Neovim' : '') . ', ' .
|
||||
\ g:_SYNTASTIC_UNAME .
|
||||
\ (has('gui') ? ', GUI' : '') . ')'
|
||||
lockvar g:syntastic_version
|
||||
|
||||
let buf = bufnr('')
|
||||
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_AUTOCOMMANDS,
|
||||
\ 'autocmd: VimEnter, buffer ' . buf . ' = ' . string(bufname(buf)) . ', &buftype = ' . string(&buftype))
|
||||
|
|
|
@ -13,28 +13,58 @@ main([File]) ->
|
|||
%% `rebar.config` is looked for,
|
||||
%% but it is not necessarily the one in the project root.
|
||||
%% I.e. it may be one deeper in the project file hierarchy.
|
||||
RebarFile = rebar_file(Dir),
|
||||
%% `rebar.config` might contain relative paths.
|
||||
%% They are relative to the file! Not to the project root.
|
||||
RebarOpts = rebar_opts(Dir ++ "/" ++ RebarFile),
|
||||
Profile = which_compile_opts_profile(filename:absname(File)),
|
||||
CompileOpts = case which_build_tool(Dir, Profile) of
|
||||
{rebar, RebarFile} ->
|
||||
%% `rebar.config` might contain relative paths.
|
||||
%% They are relative to the file! Not to the project root.
|
||||
%% rebar specific begin
|
||||
rebar_opts(RebarFile);
|
||||
%% rebar specific end
|
||||
{erlangmk, ErlangMkDir} ->
|
||||
%% Erlang.mk specific begin
|
||||
erlangmk_opts(ErlangMkDir, Profile);
|
||||
%% Erlang.mk specific end
|
||||
undefined ->
|
||||
fallback_opts()
|
||||
end,
|
||||
code:add_patha(filename:absname("ebin")),
|
||||
%% `compile:file/2` requires the `{i, Path}` to be relative
|
||||
%% to CWD - no surprise here.
|
||||
compile:file(File, Defs ++ translate_paths(Dir, RebarOpts));
|
||||
compile:file(File, Defs ++ translate_paths(Dir, CompileOpts));
|
||||
|
||||
main(_) ->
|
||||
io:format("Usage: ~s <file>~n", [escript:script_name()]),
|
||||
halt(1).
|
||||
|
||||
rebar_file(Dir) ->
|
||||
DirList = filename:split(Dir),
|
||||
case lists:last(DirList) of
|
||||
"test" ->
|
||||
"rebar.test.config";
|
||||
_ ->
|
||||
"rebar.config"
|
||||
which_compile_opts_profile(File) ->
|
||||
case filename:basename(filename:dirname(File)) of
|
||||
"test" -> test;
|
||||
_ -> normal
|
||||
end.
|
||||
|
||||
which_build_tool(Dir, Profile) ->
|
||||
%% rebar specific begin
|
||||
RebarFile = rebar_file(Dir, Profile),
|
||||
%% rebar specific end
|
||||
case filelib:is_file(RebarFile) of
|
||||
true ->
|
||||
{rebar, RebarFile};
|
||||
false ->
|
||||
%% Erlang.mk specific begin
|
||||
ErlangMk = erlangmk_file(Dir),
|
||||
%% Erlang.mk specific end
|
||||
case filelib:is_file(ErlangMk) of
|
||||
true -> {erlangmk, Dir};
|
||||
false -> undefined
|
||||
end
|
||||
end.
|
||||
|
||||
rebar_file(Dir, normal) -> filename:join(Dir, "rebar.config");
|
||||
rebar_file(Dir, test) -> filename:join(Dir, "rebar.test.config").
|
||||
|
||||
erlangmk_file(Dir) -> filename:join(Dir, "erlang.mk").
|
||||
|
||||
rebar_opts(RebarFile) ->
|
||||
Dir = get_root(filename:dirname(RebarFile)),
|
||||
case file:consult(RebarFile) of
|
||||
|
@ -54,6 +84,165 @@ rebar_opts(RebarFile) ->
|
|||
rebar_opts("rebar.config")
|
||||
end.
|
||||
|
||||
erlangmk_opts(BaseDir, Profile) ->
|
||||
Make =
|
||||
case os:getenv("MAKE") of
|
||||
false ->
|
||||
case os:find_executable("gmake") of
|
||||
false -> "make";
|
||||
Path -> Path
|
||||
end;
|
||||
Cmd ->
|
||||
case (lists:member($/, Cmd) orelse lists:member($\\, Cmd)) of
|
||||
true -> Cmd;
|
||||
false -> os:find_executable(Cmd)
|
||||
end
|
||||
end,
|
||||
ERLC_OPTS_Target =
|
||||
case Profile of
|
||||
normal -> "show-ERLC_OPTS";
|
||||
test -> "show-TEST_ERLC_OPTS"
|
||||
end,
|
||||
Args = [
|
||||
"--no-print-directory",
|
||||
"-C", BaseDir,
|
||||
"show-ERL_LIBS",
|
||||
ERLC_OPTS_Target
|
||||
],
|
||||
try
|
||||
Port = erlang:open_port({spawn_executable, Make}, [
|
||||
{args, Args},
|
||||
exit_status, use_stdio, stderr_to_stdout]),
|
||||
case erlangmk_port_receive_loop(Port, "", BaseDir) of
|
||||
{error, _} ->
|
||||
fallback_opts();
|
||||
{ok, {ErlLibs, ErlcOpts}} ->
|
||||
[code:add_pathsa(filelib:wildcard(
|
||||
filename:join([ErlLib, "*", "ebin"])))
|
||||
|| ErlLib <- ErlLibs],
|
||||
ErlcOpts
|
||||
end
|
||||
catch
|
||||
error:_ ->
|
||||
fallback_opts()
|
||||
end.
|
||||
|
||||
erlangmk_port_receive_loop(Port, Stdout, BaseDir) ->
|
||||
receive
|
||||
{Port, {exit_status, 0}} ->
|
||||
erlangmk_format_opts(Stdout, BaseDir);
|
||||
{Port, {exit_status, _}} ->
|
||||
{error, {erlangmk, make_target_failure}};
|
||||
{Port, {data, Out}} ->
|
||||
erlangmk_port_receive_loop(Port, Stdout ++ Out, BaseDir)
|
||||
end.
|
||||
|
||||
erlangmk_format_opts(Stdout, BaseDir) ->
|
||||
case string:tokens(Stdout, "\n") of
|
||||
[ErlLibsLine | ErlcOptsLines] ->
|
||||
ErlLibs = erlangmk_format_erl_libs(ErlLibsLine),
|
||||
ErlcOpts = erlangmk_format_erlc_opts(ErlcOptsLines, BaseDir),
|
||||
{ok, {ErlLibs, ErlcOpts}};
|
||||
_ ->
|
||||
{error, {erlangmk, incorrect_output}}
|
||||
end.
|
||||
|
||||
erlangmk_format_erl_libs(ErlLibsLine) ->
|
||||
case os:type() of
|
||||
{win32, _} -> string:tokens(ErlLibsLine, ";");
|
||||
_ -> string:tokens(ErlLibsLine, ":")
|
||||
end.
|
||||
|
||||
erlangmk_format_erlc_opts(ErlcOptsLines, BaseDir) ->
|
||||
erlangmk_format_erlc_opts(ErlcOptsLines, [], BaseDir).
|
||||
|
||||
erlangmk_format_erlc_opts(["+" ++ Option | Rest], Opts, BaseDir) ->
|
||||
case make_term(Option) of
|
||||
{error, _} -> erlangmk_format_erlc_opts(Rest, Opts, BaseDir);
|
||||
Opt -> erlangmk_format_erlc_opts(Rest, [Opt | Opts], BaseDir)
|
||||
end;
|
||||
erlangmk_format_erlc_opts(["-I" ++ Opt | Rest], Opts, BaseDir)
|
||||
when Opt =/= "" ->
|
||||
erlangmk_format_erlc_opts(["-I", Opt | Rest], Opts, BaseDir);
|
||||
erlangmk_format_erlc_opts(["-I", [C | _] = Dir | Rest], Opts, BaseDir)
|
||||
when C =/= $- andalso C =/= $+ ->
|
||||
AbsDir = filename:absname(Dir, BaseDir),
|
||||
erlangmk_format_erlc_opts(Rest, [{i, AbsDir} | Opts], BaseDir);
|
||||
erlangmk_format_erlc_opts(["-W" ++ Warn | Rest], Opts, BaseDir)
|
||||
when Warn =/= "" ->
|
||||
erlangmk_format_erlc_opts(["-W", Warn | Rest], Opts, BaseDir);
|
||||
erlangmk_format_erlc_opts(["-W", Warn | Rest], Opts, BaseDir) ->
|
||||
case Warn of
|
||||
"all" ->
|
||||
erlangmk_format_erlc_opts(Rest, [{warn_format, 999} | Opts],
|
||||
BaseDir);
|
||||
"error" ->
|
||||
erlangmk_format_erlc_opts(Rest, [warnings_as_errors | Opts],
|
||||
BaseDir);
|
||||
"" ->
|
||||
erlangmk_format_erlc_opts(Rest, [{warn_format, 1} | Opts],
|
||||
BaseDir);
|
||||
_ ->
|
||||
try list_to_integer(Warn) of
|
||||
Level ->
|
||||
erlangmk_format_erlc_opts(Rest,
|
||||
[{warn_format, Level} | Opts], BaseDir)
|
||||
catch
|
||||
error:badarg ->
|
||||
erlangmk_format_erlc_opts(Rest, Opts, BaseDir)
|
||||
end
|
||||
end;
|
||||
erlangmk_format_erlc_opts(["-D" ++ Opt | Rest], Opts, BaseDir)
|
||||
when Opt =/= "" ->
|
||||
erlangmk_format_erlc_opts(["-D", Opt | Rest], Opts, BaseDir);
|
||||
erlangmk_format_erlc_opts(["-D", [C | _] = Val0 | Rest], Opts, BaseDir)
|
||||
when C =/= $- andalso C =/= $+ ->
|
||||
{Key0, Val1} = split_at_equals(Val0, []),
|
||||
Key = list_to_atom(Key0),
|
||||
case Val1 of
|
||||
[] ->
|
||||
erlangmk_format_erlc_opts(Rest, [{d, Key} | Opts], BaseDir);
|
||||
Val2 ->
|
||||
case make_term(Val2) of
|
||||
{error, _} ->
|
||||
erlangmk_format_erlc_opts(Rest, Opts, BaseDir);
|
||||
Val ->
|
||||
erlangmk_format_erlc_opts(Rest, [{d, Key, Val} | Opts], BaseDir)
|
||||
end
|
||||
end;
|
||||
erlangmk_format_erlc_opts([PathFlag, [_ | _] = Dir | Rest], Opts, BaseDir)
|
||||
when PathFlag =:= "-pa" orelse PathFlag =:= "-pz" ->
|
||||
AbsDir = filename:absname(Dir, BaseDir),
|
||||
case PathFlag of
|
||||
"-pa" -> code:add_patha(AbsDir);
|
||||
"-pz" -> code:add_pathz(AbsDir)
|
||||
end,
|
||||
erlangmk_format_erlc_opts(Rest, Opts, BaseDir);
|
||||
erlangmk_format_erlc_opts([_ | Rest], Opts, BaseDir) ->
|
||||
erlangmk_format_erlc_opts(Rest, Opts, BaseDir);
|
||||
erlangmk_format_erlc_opts([], Opts, _) ->
|
||||
lists:reverse(Opts).
|
||||
|
||||
%% Function imported from erl_compile.erl from Erlang 19.1.
|
||||
make_term(Str) ->
|
||||
case erl_scan:string(Str) of
|
||||
{ok, Tokens, _} ->
|
||||
case erl_parse:parse_term(Tokens ++ [{dot, 1}]) of
|
||||
{ok, Term} -> Term;
|
||||
{error, Reason} -> {error, Reason}
|
||||
end;
|
||||
{error, Reason, _} ->
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
%% Function imported from erl_compile.erl from Erlang 19.1.
|
||||
split_at_equals([$=|T], Acc) ->
|
||||
{lists:reverse(Acc),T};
|
||||
split_at_equals([H|T], Acc) ->
|
||||
split_at_equals(T, [H|Acc]);
|
||||
split_at_equals([], Acc) ->
|
||||
{lists:reverse(Acc),[]}.
|
||||
|
||||
fallback_opts() ->
|
||||
code:add_pathsa(filelib:wildcard("deps/*/ebin")),
|
||||
code:add_pathsa(nested_app_ebins()),
|
||||
|
|
|
@ -32,9 +32,12 @@ function! SyntaxCheckers_haxe_haxe_GetLocList() dict
|
|||
|
||||
if hxml !=# ''
|
||||
let makeprg = self.makeprgBuild({
|
||||
\ 'fname': syntastic#util#shescape(fnamemodify(hxml, ':t')) })
|
||||
\ 'fname': syntastic#util#shescape(fnamemodify(hxml, ':t')),
|
||||
\ 'args_after' : ['--no-output'] })
|
||||
|
||||
let errorformat = '%E%f:%l: characters %c-%n : %m'
|
||||
let errorformat =
|
||||
\ '%W%f:%l: characters %c-%n : Warning : %m,' .
|
||||
\ '%E%f:%l: characters %c-%n : %m'
|
||||
|
||||
let loclist = SyntasticMake({
|
||||
\ 'makeprg': makeprg,
|
||||
|
|
|
@ -25,7 +25,7 @@ function! SyntaxCheckers_javascript_flow_IsAvailable() dict
|
|||
if !executable(self.getExec())
|
||||
return 0
|
||||
endif
|
||||
return syntastic#util#versionIsAtLeast(self.getVersion(self.getExecEscaped() . ' version'), [0, 18, 1])
|
||||
return syntastic#util#versionIsAtLeast(self.getVersion(self.getExecEscaped() . ' version'), [0, 34])
|
||||
endfunction
|
||||
|
||||
function! SyntaxCheckers_javascript_flow_GetLocList() dict
|
||||
|
@ -34,8 +34,8 @@ function! SyntaxCheckers_javascript_flow_GetLocList() dict
|
|||
endif
|
||||
|
||||
let makeprg = self.makeprgBuild({
|
||||
\ 'exe': self.getExecEscaped() . ' check',
|
||||
\ 'args_after': '--show-all-errors --json' })
|
||||
\ 'exe': self.getExecEscaped() . ' status',
|
||||
\ 'args_after': '--quiet --show-all-errors --json' })
|
||||
|
||||
let errorformat =
|
||||
\ '%f:%l:%c:%n: %m,' .
|
||||
|
|
|
@ -24,9 +24,12 @@ function! SyntaxCheckers_vala_valac_GetHighlightRegex(pos) " {{{1
|
|||
endfunction " }}}1
|
||||
|
||||
function! SyntaxCheckers_vala_valac_GetLocList() dict " {{{1
|
||||
let vala_pkg_args = join(map(s:GetValaModules(), '"--pkg ".v:val'), ' ')
|
||||
let vala_vapi_args = join(map(s:GetValaVapiDirs(), '"--vapidir ".v:val'), ' ')
|
||||
let makeprg = self.makeprgBuild({ 'args': '-C ' . vala_pkg_args . ' ' . vala_vapi_args })
|
||||
let buf = bufnr('')
|
||||
let makeprg = self.makeprgBuild({
|
||||
\ 'args': '-C ' .
|
||||
\ s:GetValaOpts(buf, 'modules', 'modules', '--pkg') . ' ' .
|
||||
\ s:GetValaOpts(buf, 'vapi_dirs', 'vapidirs', '--vapidir'),
|
||||
\ })
|
||||
|
||||
let errorformat =
|
||||
\ '%A%f:%l.%c-%\d%\+.%\d%\+: %t%[a-z]%\+: %m,'.
|
||||
|
@ -40,38 +43,27 @@ endfunction " }}}1
|
|||
|
||||
" Utilities {{{1
|
||||
|
||||
function! s:GetValaModules() " {{{2
|
||||
if exists('g:syntastic_vala_modules') || exists('b:syntastic_vala_modules')
|
||||
let modules = syntastic#util#var('vala_modules')
|
||||
if type(modules) == type('')
|
||||
return split(modules, '\m\s\+')
|
||||
elseif type(modules) == type([])
|
||||
return copy(modules)
|
||||
function! s:GetValaOpts(buf, name, comment, cmd) " {{{2
|
||||
let var = syntastic#util#var('vala_' . a:name)
|
||||
if type(var) == type([])
|
||||
let opts = map(copy(var), 'syntastic#util#shescape(v:val)')
|
||||
elseif type(var) == type('')
|
||||
if var !=# ''
|
||||
let opts = split(var, '\s\+')
|
||||
else
|
||||
echoerr 'syntastic_vala_modules must be either list or string: fallback to in file modules string'
|
||||
let opts = []
|
||||
for line in filter(getbufline(a:buf, 1, 100), 'v:val =~# ' . string('\m^//\s\+' . a:comment . ':\s*'))
|
||||
call extend(opts, split( matchstr(line, '\m^//\s\+' . a:comment . ':\s*\zs.*'), '\s\+' ))
|
||||
endfor
|
||||
|
||||
call map( filter(opts, 'v:val !=# ""'), 'syntastic#util#shescape(v:val)' )
|
||||
endif
|
||||
else
|
||||
call syntastic#log#error('syntastic_vala_' . a:name . ' must be either a list, or a string')
|
||||
return ''
|
||||
endif
|
||||
|
||||
let modules_line = search('^// modules: ', 'n')
|
||||
let modules_str = getline(modules_line)
|
||||
return split(strpart(modules_str, 12), '\m\s\+')
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:GetValaVapiDirs() " {{{2
|
||||
if exists('g:syntastic_vala_vapi_dirs') || exists('b:syntastic_vala_vapi_dirs')
|
||||
let vapi_dirs = syntastic#util#var('vala_vapi_dirs')
|
||||
if type(vapi_dirs) == type('')
|
||||
return split(vapi_dirs, '\m\s\+')
|
||||
elseif type(vapi_dirs) == type([])
|
||||
return copy(vapi_dirs)
|
||||
else
|
||||
echoerr 'syntastic_vala_vapi_dirs must be either a list, or a string: fallback to in-file modules string'
|
||||
endif
|
||||
endif
|
||||
|
||||
let vapi_line = search('^//\s*vapidirs:\s*','n')
|
||||
let vapi_str = getline(vapi_line)
|
||||
return split( substitute( vapi_str, '\m^//\s*vapidirs:\s*', '', 'g' ), '\m\s\+' )
|
||||
return join(map(opts, string(a:cmd . ' ') . ' . v:val'))
|
||||
endfunction " }}}2
|
||||
|
||||
" }}}1
|
||||
|
|
|
@ -18,7 +18,7 @@ setlocal indentexpr=GetCoffeeHtmlIndent(v:lnum)
|
|||
|
||||
function! GetCoffeeHtmlIndent(curlinenum)
|
||||
" See if we're inside a coffeescript block.
|
||||
let scriptlnum = searchpair('<script [^>]*type="text/coffeescript"[^>]*>', '',
|
||||
let scriptlnum = searchpair('<script [^>]*type=[''"]\?text/coffeescript[''"]\?[^>]*>', '',
|
||||
\ '</script>', 'bWn')
|
||||
let prevlnum = prevnonblank(a:curlinenum)
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ endif
|
|||
|
||||
" Syntax highlighting for text/coffeescript script tags
|
||||
syn include @htmlCoffeeScript syntax/coffee.vim
|
||||
syn region coffeeScript start=#<script [^>]*type="text/coffeescript"[^>]*>#
|
||||
syn region coffeeScript start=#<script [^>]*type=['"]\?text/coffeescript['"]\?[^>]*>#
|
||||
\ end=#</script>#me=s-1 keepend
|
||||
\ contains=@htmlCoffeeScript,htmlScriptTag,@htmlPreproc
|
||||
\ containedin=htmlHead
|
||||
|
|
|
@ -4,4 +4,14 @@
|
|||
def: 42
|
||||
}
|
||||
</script>
|
||||
<script type='text/coffeescript'>
|
||||
abc = {
|
||||
def: 42
|
||||
}
|
||||
</script>
|
||||
<script type=text/coffeescript>
|
||||
abc = {
|
||||
def: 42
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
@ -195,7 +195,7 @@ function! fugitive#detect(path) abort
|
|||
nnoremap <buffer> <silent> y<C-G> :call setreg(v:register, <SID>recall())<CR>
|
||||
endif
|
||||
let buffer = fugitive#buffer()
|
||||
if expand('%:p') =~# '//'
|
||||
if expand('%:p') =~# '://'
|
||||
call buffer.setvar('&path', s:sub(buffer.getvar('&path'), '^\.%(,|$)', ''))
|
||||
endif
|
||||
if stridx(buffer.getvar('&tags'), escape(b:git_dir, ', ')) == -1
|
||||
|
@ -700,7 +700,11 @@ function! s:Git(bang, args) abort
|
|||
let args = matchstr(a:args,'\v\C.{-}%($|\\@<!%(\\\\)*\|)@=')
|
||||
if exists(':terminal')
|
||||
let dir = s:repo().tree()
|
||||
-tabedit %
|
||||
if expand('%') != ''
|
||||
-tabedit %
|
||||
else
|
||||
-tabnew
|
||||
endif
|
||||
execute 'lcd' fnameescape(dir)
|
||||
execute 'terminal' git args
|
||||
else
|
||||
|
@ -2295,9 +2299,9 @@ function! s:Browse(bang,line1,count,...) abort
|
|||
|
||||
if empty(remote)
|
||||
let remote = '.'
|
||||
let raw = s:repo().git_chomp('config','remote.origin.url')
|
||||
let raw = s:repo().git_chomp('remote','get-url','origin')
|
||||
else
|
||||
let raw = s:repo().git_chomp('config','remote.'.remote.'.url')
|
||||
let raw = s:repo().git_chomp('remote','get-url',remote)
|
||||
endif
|
||||
if raw ==# ''
|
||||
let raw = remote
|
||||
|
|
4
sources_non_forked/vim-go/.gitignore
vendored
4
sources_non_forked/vim-go/.gitignore
vendored
|
@ -1,2 +1,6 @@
|
|||
doc/tags
|
||||
.DS_Store
|
||||
|
||||
# Test specific files
|
||||
FAILED
|
||||
test.log
|
||||
|
|
22
sources_non_forked/vim-go/.travis.yml
Normal file
22
sources_non_forked/vim-go/.travis.yml
Normal file
|
@ -0,0 +1,22 @@
|
|||
language: go
|
||||
|
||||
env:
|
||||
global:
|
||||
- DEPS=$HOME/deps
|
||||
- PATH=$DEPS/bin:$PATH
|
||||
- PATCH="v8.0.0134"
|
||||
|
||||
install: |
|
||||
git config --global user.email "you@example.com"
|
||||
git config --global user.name "Your Name"
|
||||
|
||||
# check out if we can pre-compiled Vim releases somehow,
|
||||
git clone --branch $PATCH --depth 1 https://github.com/vim/vim
|
||||
cd vim
|
||||
./configure --prefix=$DEPS --with-features=huge --disable-gui
|
||||
make
|
||||
make install
|
||||
cd -
|
||||
|
||||
script: ./scripts/test.sh
|
||||
|
|
@ -1,7 +1,33 @@
|
|||
## 1.11 - Unplanned
|
||||
## unplanned
|
||||
|
||||
FEATURES:
|
||||
|
||||
* Add new `errl` snippet that expands to [gh-1185]:
|
||||
|
||||
```
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
```
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
* Lowercase `<Leader>` in mappings examples for consisten documentation across the README [gh-1192]
|
||||
* All of files should be written in utf-8 if the file will be passed to external command. [gh-1184]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
* Honor `g:go_echo_command_info` when dispatching builds in neovim [gh-1176]
|
||||
* Fix `:GoBuild` error in neovim due to invalid jobcontrol handler function signatures (`s:on_stdout`, `s:on_stderr`)[gh-1176]
|
||||
* Update statusline before and after `go#jobcontrol#Spawn` command is executed [gh-1176]
|
||||
* Correctly report the value of the 'g:go_guru_tags' variable [gh-1177]
|
||||
* Ensure no trailing `:` exist in GOPATH detection if initial GOPATH is not set [gh-1194]
|
||||
|
||||
## 1.11 - (January 9, 2017)
|
||||
|
||||
FEATURES:
|
||||
|
||||
* Travis test integration has been added. Now any file that is added as `<name>_test.vim` will be automatically tested in for every Pull Request (just like how we add tests to Go with `_test.go`). Going forward this will tremendously increase the stability and decrease the maintaince burden of vim-go. [gh-1157]
|
||||
* Add new `g:go_updatetime` setting to change the default updatetime (which was hardcoded previously) [gh-1055]
|
||||
* Add new `g:go_template_use_pkg` setting to enable to use cwd as package name instead of basic template file [gh-1124]
|
||||
|
||||
|
@ -9,6 +35,8 @@ IMPROVEMENTS:
|
|||
|
||||
* Add `statusline` support for `:GoMetaLinter` [gh-1120]
|
||||
* Quickfix and Location lists contain now a descriptive title (requires at least Vim `7.4.2200`)[gh-1004]
|
||||
* Check `go env GOPATH` as well for `:GoInstallBinaries` as Go has now a default path for GOPATH ("~/go")starting with 1.8 [gh-1152]
|
||||
* `:GoDocBrowser` now also works on import paths [gh-1174]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
|
@ -24,6 +52,22 @@ BUG FIXES:
|
|||
* Fix referencing a non defined variable for async commands when bang (!) was used
|
||||
* Fix `:GoDef` failing for a modified buffer if `hidden` was not set [gh-1132]
|
||||
* Fix `:GoDefStack` to allow popping from jump list when buffer is modified [gh-1133]
|
||||
* Improve internal defining of functions and referencing them for async operations [gh-1155]
|
||||
* Fix `:GoMetaLinter` failing if `go_metalinter_command` is set. [gh-1160]
|
||||
* Fix `:GoMetaLinter`'s `go_metalinter_deadline` setting for async mode [gh-1146]
|
||||
|
||||
BACKWARDS INCOMPATIBILITIES:
|
||||
|
||||
* The following syntax options are now disabled by default. If you're using them be sure to set them in your .vimrc [gh-1167]
|
||||
|
||||
```viml
|
||||
g:go_highlight_array_whitespace_error
|
||||
g:go_highlight_chan_whitespace_error
|
||||
g:go_highlight_extra_types
|
||||
g:go_highlight_space_tab_error
|
||||
g:go_highlight_trailing_whitespace_error
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 1.10 (November 24, 2016)
|
||||
|
|
7
sources_non_forked/vim-go/Makefile
Normal file
7
sources_non_forked/vim-go/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
all: test
|
||||
|
||||
test:
|
||||
@echo "==> Running tests"
|
||||
@./scripts/test.sh
|
||||
|
||||
.PHONY: all test
|
|
@ -1,4 +1,4 @@
|
|||
# vim-go
|
||||
# vim-go [![Build Status](http://img.shields.io/travis/fatih/vim-go.svg?style=flat-square)](https://travis-ci.org/fatih/vim-go)
|
||||
|
||||
<p align="center">
|
||||
<img style="float: right;" src="assets/vim-go.png" alt="Vim-go logo"/>
|
||||
|
@ -137,43 +137,43 @@ current buffer. You can also open the definition/declaration, in a new vertical,
|
|||
horizontal, or tab, for the word under your cursor:
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>ds <Plug>(go-def-split)
|
||||
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
|
||||
au FileType go nmap <Leader>dt <Plug>(go-def-tab)
|
||||
au FileType go nmap <leader>ds <Plug>(go-def-split)
|
||||
au FileType go nmap <leader>dv <Plug>(go-def-vertical)
|
||||
au FileType go nmap <leader>dt <Plug>(go-def-tab)
|
||||
```
|
||||
|
||||
Open the relevant Godoc for the word under the cursor with `<leader>gd` or open
|
||||
it vertically with `<leader>gv`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gd <Plug>(go-doc)
|
||||
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
|
||||
au FileType go nmap <leader>gd <Plug>(go-doc)
|
||||
au FileType go nmap <leader>gv <Plug>(go-doc-vertical)
|
||||
```
|
||||
|
||||
Or open the Godoc in browser
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
|
||||
au FileType go nmap <leader>gb <Plug>(go-doc-browser)
|
||||
```
|
||||
|
||||
Show a list of interfaces which is implemented by the type under your cursor
|
||||
with `<leader>s`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>s <Plug>(go-implements)
|
||||
au FileType go nmap <leader>s <Plug>(go-implements)
|
||||
```
|
||||
|
||||
Show type info for the word under your cursor with `<leader>i` (useful if you
|
||||
have disabled auto showing type info via `g:go_auto_type_info`)
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>i <Plug>(go-info)
|
||||
au FileType go nmap <leader>i <Plug>(go-info)
|
||||
```
|
||||
|
||||
Rename the identifier under the cursor to a new name
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>e <Plug>(go-rename)
|
||||
au FileType go nmap <leader>e <Plug>(go-rename)
|
||||
```
|
||||
|
||||
More `<Plug>` mappings can be seen with `:he go-mappings`. Also these are just
|
||||
|
@ -245,8 +245,8 @@ Run `:GoRun` in a new tab, horizontal split or vertical split terminal
|
|||
|
||||
```vim
|
||||
au FileType go nmap <leader>rt <Plug>(go-run-tab)
|
||||
au FileType go nmap <Leader>rs <Plug>(go-run-split)
|
||||
au FileType go nmap <Leader>rv <Plug>(go-run-vertical)
|
||||
au FileType go nmap <leader>rs <Plug>(go-run-split)
|
||||
au FileType go nmap <leader>rv <Plug>(go-run-vertical)
|
||||
```
|
||||
|
||||
By default new terminals are opened in a vertical split. To change it
|
||||
|
@ -288,6 +288,31 @@ information. It includes
|
|||
section](https://github.com/fatih/vim-go/wiki/FAQ-Troubleshooting), and many
|
||||
other [various pieces](https://github.com/fatih/vim-go/wiki) of information.
|
||||
|
||||
## Development & Testing
|
||||
|
||||
vim-go supports now test files. Please check `autoload` folder for examples. If
|
||||
you add a new feature be sure you also include the `_test.vim` file next to the
|
||||
script. Test functions should be starting with `Test_`, example:
|
||||
|
||||
|
||||
```viml
|
||||
function Test_run_fmt()
|
||||
call assert_equal(expected, actual)
|
||||
...
|
||||
endfunction
|
||||
```
|
||||
|
||||
You can locally test it by running:
|
||||
|
||||
```
|
||||
make
|
||||
```
|
||||
|
||||
This will run all tests and print either `PASS` or `FAIL` to indicate the final
|
||||
status of all tests.
|
||||
|
||||
Additionally, each new pull request will trigger a new Travis-ci job.
|
||||
|
||||
## Donation
|
||||
|
||||
People have asked for this for a long time, now you can be a fully supporter by
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#!/usr/bin/env rake
|
||||
|
||||
task :ci => [:dump, :test]
|
||||
|
||||
task :dump do
|
||||
sh 'vim --version'
|
||||
end
|
||||
|
||||
# Firstly, `bundle install; bundle install --deployment`
|
||||
# Then, `rake test`
|
||||
task :test do
|
||||
sh 'bundle exec vim-flavor test'
|
||||
end
|
|
@ -25,7 +25,7 @@ function! go#asmfmt#Format() abort
|
|||
|
||||
" Write the current buffer to a tempfile.
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
|
||||
" Run asmfmt.
|
||||
let path = go#path#CheckBinPath("asmfmt")
|
||||
|
|
|
@ -32,8 +32,11 @@ function! go#cmd#Build(bang, ...) abort
|
|||
\})
|
||||
return
|
||||
elseif has('nvim')
|
||||
if get(g:, 'go_echo_command_info', 1)
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
endif
|
||||
|
||||
" if we have nvim, call it asynchronously and return early ;)
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
call go#jobcontrol#Spawn(a:bang, "build", args)
|
||||
return
|
||||
endif
|
||||
|
@ -419,7 +422,7 @@ function s:cmd_job(args) abort
|
|||
call go#statusline#Update(status_dir, status)
|
||||
endfunction
|
||||
|
||||
let a:args.error_info_cb = function('s:error_info_cb')
|
||||
let a:args.error_info_cb = funcref('s:error_info_cb')
|
||||
let callbacks = go#job#Spawn(a:args)
|
||||
|
||||
let start_options = {
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
let s:sock_type = (has('win32') || has('win64')) ? 'tcp' : 'unix'
|
||||
|
||||
function! s:gocodeCurrentBuffer() abort
|
||||
let buf = getline(1, '$')
|
||||
if &encoding != 'utf-8'
|
||||
let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")')
|
||||
endif
|
||||
if &l:fileformat == 'dos'
|
||||
" XXX: line2byte() depend on 'fileformat' option.
|
||||
" so if fileformat is 'dos', 'buf' must include '\r'.
|
||||
let buf = map(buf, 'v:val."\r"')
|
||||
endif
|
||||
let file = tempname()
|
||||
call writefile(buf, file)
|
||||
|
||||
call writefile(go#util#GetLines(), file)
|
||||
return file
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ function s:coverage_job(args)
|
|||
call go#statusline#Update(status_dir, status)
|
||||
endfunction
|
||||
|
||||
let a:args.error_info_cb = function('s:error_info_cb')
|
||||
let a:args.error_info_cb = funcref('s:error_info_cb')
|
||||
let callbacks = go#job#Spawn(a:args)
|
||||
|
||||
let start_options = {
|
||||
|
|
|
@ -16,7 +16,7 @@ function! go#def#Jump(mode) abort
|
|||
if &modified
|
||||
" Write current unsaved buffer to a temp file and use the modified content
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
let fname = l:tmpname
|
||||
endif
|
||||
|
||||
|
@ -41,8 +41,7 @@ function! go#def#Jump(mode) abort
|
|||
let stdin_content = ""
|
||||
|
||||
if &modified
|
||||
let sep = go#util#LineEnding()
|
||||
let content = join(getline(1, '$'), sep)
|
||||
let content = join(go#util#GetLines(), "\n")
|
||||
let stdin_content = fname . "\n" . strlen(content) . "\n" . content
|
||||
call add(cmd, "-modified")
|
||||
endif
|
||||
|
@ -87,7 +86,7 @@ function! go#def#Jump(mode) abort
|
|||
return
|
||||
endif
|
||||
|
||||
call s:jump_to_declaration(out, a:mode, bin_name)
|
||||
call go#def#jump_to_declaration(out, a:mode, bin_name)
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
|
@ -96,10 +95,10 @@ function! s:jump_to_declaration_cb(mode, bin_name, job, exit_status, data) abort
|
|||
return
|
||||
endif
|
||||
|
||||
call s:jump_to_declaration(a:data[0], a:mode, a:bin_name)
|
||||
call go#def#jump_to_declaration(a:data[0], a:mode, a:bin_name)
|
||||
endfunction
|
||||
|
||||
function! s:jump_to_declaration(out, mode, bin_name) abort
|
||||
function! go#def#jump_to_declaration(out, mode, bin_name) abort
|
||||
let final_out = a:out
|
||||
if a:bin_name == "godef"
|
||||
" append the type information to the same line so our we can parse it.
|
||||
|
@ -299,7 +298,7 @@ function s:def_job(args) abort
|
|||
" do not print anything during async definition search&jump
|
||||
endfunction
|
||||
|
||||
let a:args.error_info_cb = function('s:error_info_cb')
|
||||
let a:args.error_info_cb = funcref('s:error_info_cb')
|
||||
let callbacks = go#job#Spawn(a:args)
|
||||
|
||||
let start_options = {
|
||||
|
|
32
sources_non_forked/vim-go/autoload/go/def_test.vim
Normal file
32
sources_non_forked/vim-go/autoload/go/def_test.vim
Normal file
|
@ -0,0 +1,32 @@
|
|||
func Test_jump_to_declaration_guru()
|
||||
let file_name = "test-fixtures/def/jump.go"
|
||||
let lnum = 5
|
||||
let col = 6
|
||||
|
||||
let out = printf("%s:%d:%d: defined here as func main", file_name, lnum, col)
|
||||
let bin_name = "guru"
|
||||
|
||||
call go#def#jump_to_declaration(out, "", bin_name)
|
||||
|
||||
call assert_equal(file_name, bufname("%"))
|
||||
call assert_equal(lnum, getcurpos()[1])
|
||||
call assert_equal(col, getcurpos()[2])
|
||||
endfunc
|
||||
|
||||
func Test_jump_to_declaration_godef()
|
||||
let file_name = "test-fixtures/def/jump.go"
|
||||
let lnum = 5
|
||||
let col = 6
|
||||
|
||||
" note that the output of godef has two lines
|
||||
let out = printf("%s:%d:%d\ndefined here as func main", file_name, lnum, col)
|
||||
let bin_name = "godef"
|
||||
|
||||
call go#def#jump_to_declaration(out, "", bin_name)
|
||||
|
||||
call assert_equal(file_name, bufname("%"))
|
||||
call assert_equal(lnum, getcurpos()[1])
|
||||
call assert_equal(col, getcurpos()[2])
|
||||
endfunc
|
||||
|
||||
" vim: sw=2 ts=2 et
|
|
@ -31,12 +31,11 @@ function! go#doc#OpenBrowser(...) abort
|
|||
|
||||
let import = out["import"]
|
||||
let name = out["name"]
|
||||
|
||||
" if import is empty, it means we selected a package name
|
||||
if import ==# ""
|
||||
let godoc_url = "https://godoc.org/" . name
|
||||
else
|
||||
let godoc_url = "https://godoc.org/" . import . "#" . name
|
||||
let decl = out["decl"]
|
||||
|
||||
let godoc_url = "https://godoc.org/" . import
|
||||
if decl !~ "^package"
|
||||
let godoc_url .= "#" . name
|
||||
endif
|
||||
|
||||
echo godoc_url
|
||||
|
@ -153,8 +152,7 @@ function! s:gogetdoc(json) abort
|
|||
" file size followed by newline
|
||||
" file contents
|
||||
let in = ""
|
||||
let sep = go#util#LineEnding()
|
||||
let content = join(getline(1, '$'), sep)
|
||||
let content = join(go#util#GetLines(), "\n")
|
||||
let in = fname . "\n" . strlen(content) . "\n" . content
|
||||
let command .= " -modified"
|
||||
let out = go#util#System(command, in)
|
||||
|
|
|
@ -2,26 +2,8 @@
|
|||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" fmt.vim: Vim command to format Go files with gofmt.
|
||||
"
|
||||
" This filetype plugin add a new commands for go buffers:
|
||||
"
|
||||
" :Fmt
|
||||
"
|
||||
" Filter the current Go buffer through gofmt.
|
||||
" It tries to preserve cursor position and avoids
|
||||
" replacing the buffer with stderr output.
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_fmt_command [default="gofmt"]
|
||||
"
|
||||
" Flag naming the gofmt executable to use.
|
||||
"
|
||||
" g:go_fmt_autosave [default=1]
|
||||
"
|
||||
" Flag to auto call :Fmt when saved file
|
||||
"
|
||||
" fmt.vim: Vim command to format Go files with gofmt (and gofmt compatible
|
||||
" toorls, such as goimports).
|
||||
|
||||
if !exists("g:go_fmt_command")
|
||||
let g:go_fmt_command = "gofmt"
|
||||
|
@ -67,6 +49,13 @@ function! go#fmt#Format(withGoimport) abort
|
|||
catch
|
||||
let l:curw = winsaveview()
|
||||
endtry
|
||||
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
" prevent an additional undo jump due to BufWritePre auto command and also
|
||||
" restore 'redo' history because it's getting being destroyed every
|
||||
" BufWritePre
|
||||
let tmpundofile = tempname()
|
||||
exe 'wundo! ' . tmpundofile
|
||||
else
|
||||
" Save cursor position and many other things.
|
||||
let l:curw = winsaveview()
|
||||
|
@ -74,135 +63,32 @@ function! go#fmt#Format(withGoimport) abort
|
|||
|
||||
" Write current unsaved buffer to a temp file
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
" prevent an additional undo jump due to BufWritePre auto command and also
|
||||
" restore 'redo' history because it's getting being destroyed every
|
||||
" BufWritePre
|
||||
let tmpundofile = tempname()
|
||||
exe 'wundo! ' . tmpundofile
|
||||
endif
|
||||
|
||||
" get the command first so we can test it
|
||||
let bin_name = g:go_fmt_command
|
||||
if a:withGoimport == 1
|
||||
let bin_name = g:go_goimports_bin
|
||||
endif
|
||||
|
||||
" check if the user has installed command binary.
|
||||
" For example if it's goimports, let us check if it's installed,
|
||||
" if not the user get's a warning via go#path#CheckBinPath()
|
||||
let bin_path = go#path#CheckBinPath(bin_name)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if bin_name != "gofmt"
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
endif
|
||||
|
||||
" populate the final command with user based fmt options
|
||||
let command = bin_path . ' -w '
|
||||
if a:withGoimport != 1
|
||||
let command = command . g:go_fmt_options
|
||||
endif
|
||||
|
||||
if bin_name == "goimports"
|
||||
if !exists('b:goimports_vendor_compatible')
|
||||
let out = go#util#System(bin_path . " --help")
|
||||
if out !~ "-srcdir"
|
||||
call go#util#EchoWarning(printf("vim-go: goimports (%s) does not support srcdir. Update with: :GoUpdateBinaries", bin_path))
|
||||
else
|
||||
let b:goimports_vendor_compatible = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
let command = command . '-srcdir ' . shellescape(expand("%:p"))
|
||||
let &shellslash = ssl_save
|
||||
endif
|
||||
endif
|
||||
|
||||
" execute our command...
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
if go#util#IsWin()
|
||||
let l:tmpname = tr(l:tmpname, '\', '/')
|
||||
endif
|
||||
let out = go#util#System(command . " " . l:tmpname)
|
||||
|
||||
if bin_name != "gofmt"
|
||||
let $GOPATH = old_gopath
|
||||
let bin_name = g:go_fmt_command
|
||||
if a:withGoimport == 1
|
||||
let bin_name = g:go_goimports_bin
|
||||
endif
|
||||
|
||||
let l:listtype = "locationlist"
|
||||
"if there is no error on the temp file replace the output with the current
|
||||
"file (if this fails, we can always check the outputs first line with:
|
||||
"splitted =~ 'package \w\+')
|
||||
let out = go#fmt#run(bin_name, l:tmpname, expand('%'))
|
||||
if go#util#ShellError() == 0
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" Replace current file with temp file, then reload buffer
|
||||
let old_fileformat = &fileformat
|
||||
if exists("*getfperm")
|
||||
" save old file permissions
|
||||
let original_fperm = getfperm(expand('%'))
|
||||
endif
|
||||
call rename(l:tmpname, expand('%'))
|
||||
" restore old file permissions
|
||||
if exists("*setfperm") && original_fperm != ''
|
||||
call setfperm(expand('%'), original_fperm)
|
||||
endif
|
||||
silent edit!
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
|
||||
" clean up previous location list, but only if it's due to fmt
|
||||
if exists('b:got_fmt_error') && b:got_fmt_error
|
||||
let b:got_fmt_error = 0
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
endif
|
||||
call go#fmt#update_file(l:tmpname, expand('%'))
|
||||
elseif g:go_fmt_fail_silently == 0
|
||||
let splitted = split(out, '\n')
|
||||
"otherwise get the errors and put them to location list
|
||||
let errors = []
|
||||
for line in splitted
|
||||
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": @%,
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
endif
|
||||
endfor
|
||||
if empty(errors)
|
||||
% | " Couldn't detect gofmt error format, output errors
|
||||
endif
|
||||
if !empty(errors)
|
||||
call go#list#Populate(l:listtype, errors, 'Format')
|
||||
echohl Error | echomsg "Gofmt returned error" | echohl None
|
||||
endif
|
||||
|
||||
let b:got_fmt_error = 1
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
|
||||
" We didn't use the temp file, so clean up
|
||||
call delete(l:tmpname)
|
||||
let errors = s:parse_errors(out)
|
||||
call s:show_errors(errors)
|
||||
endif
|
||||
|
||||
" We didn't use the temp file, so clean up
|
||||
call delete(l:tmpname)
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" restore our undo history
|
||||
silent! exe 'rundo ' . tmpundofile
|
||||
call delete(tmpundofile)
|
||||
endif
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" Restore our cursor/windows positions, folds, etc.
|
||||
if empty(l:curw)
|
||||
silent! loadview
|
||||
|
@ -215,6 +101,134 @@ function! go#fmt#Format(withGoimport) abort
|
|||
endif
|
||||
endfunction
|
||||
|
||||
" update_file updates the target file with the given formatted source
|
||||
function! go#fmt#update_file(source, target)
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
let old_fileformat = &fileformat
|
||||
if exists("*getfperm")
|
||||
" save file permissions
|
||||
let original_fperm = getfperm(a:target)
|
||||
endif
|
||||
|
||||
call rename(a:source, a:target)
|
||||
|
||||
" restore file permissions
|
||||
if exists("*setfperm") && original_fperm != ''
|
||||
call setfperm(a:target , original_fperm)
|
||||
endif
|
||||
|
||||
" reload buffer to reflect latest changes
|
||||
silent! edit!
|
||||
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
|
||||
" clean up previous location list
|
||||
let l:listtype = "locationlist"
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
endfunction
|
||||
|
||||
" run runs the gofmt/goimport command for the given source file and returns
|
||||
" the the output of the executed command. Target is the real file to be
|
||||
" formated.
|
||||
function! go#fmt#run(bin_name, source, target)
|
||||
let cmd = s:fmt_cmd(a:bin_name, a:source, a:target)
|
||||
if cmd[0] == "goimports"
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
endif
|
||||
|
||||
let command = join(cmd, " ")
|
||||
|
||||
" execute our command...
|
||||
let out = go#util#System(command)
|
||||
|
||||
if cmd[0] == "goimports"
|
||||
let $GOPATH = old_gopath
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction
|
||||
|
||||
" fmt_cmd returns a dict that contains the command to execute gofmt (or
|
||||
" goimports). args is dict with
|
||||
function! s:fmt_cmd(bin_name, source, target)
|
||||
" check if the user has installed command binary.
|
||||
" For example if it's goimports, let us check if it's installed,
|
||||
" if not the user get's a warning via go#path#CheckBinPath()
|
||||
let bin_path = go#path#CheckBinPath(a:bin_name)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
" start constructing the command
|
||||
let cmd = [bin_path]
|
||||
call add(cmd, "-w")
|
||||
|
||||
if a:bin_name != "goimports"
|
||||
call extend(cmd, split(g:go_fmt_options, " "))
|
||||
else
|
||||
" lazy check if goimports support `-srcdir`. We should eventually remove
|
||||
" this in the future
|
||||
if !exists('b:goimports_vendor_compatible')
|
||||
let out = go#util#System(bin_path . " --help")
|
||||
if out !~ "-srcdir"
|
||||
call go#util#EchoWarning(printf("vim-go: goimports (%s) does not support srcdir. Update with: :GoUpdateBinaries", bin_path))
|
||||
else
|
||||
let b:goimports_vendor_compatible = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
call extend(cmd, ["-srcdir", shellescape(fnamemodify(a:target, ":p"))])
|
||||
let &shellslash = ssl_save
|
||||
endif
|
||||
endif
|
||||
|
||||
call add(cmd, a:source)
|
||||
return cmd
|
||||
endfunction
|
||||
|
||||
" parse_errors parses the given errors and returns a list of parsed errors
|
||||
function! s:parse_errors(content) abort
|
||||
let splitted = split(a:content, '\n')
|
||||
|
||||
" list of errors to be put into location list
|
||||
let errors = []
|
||||