mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/vim-go/autoload/go/list.vim

174 lines
5.0 KiB
VimL
Raw Normal View History

2018-12-17 06:28:27 -05:00
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
2016-02-20 08:13:10 -05:00
" Window opens the list with the given height up to 10 lines maximum.
" Otherwise g:go_loclist_height is used.
2017-09-02 06:43:18 -04:00
"
" If no or zero height is given it closes the window by default.
2017-09-02 06:43:18 -04:00
" To prevent this, set g:go_list_autoclose = 0
2016-12-27 09:46:49 -05:00
function! go#list#Window(listtype, ...) abort
2016-06-26 07:12:36 -04:00
" we don't use lwindow to close the location list as we need also the
" ability to resize the window. So, we are going to use lopen and lclose
" for a better user experience. If the number of errors in a current
" location list increases/decreases, cwindow will not resize when a new
" updated height is passed. lopen in the other hand resizes the screen.
if !a:0 || a:1 == 0
2018-03-31 10:56:26 -04:00
call go#list#Close(a:listtype)
2016-06-26 07:12:36 -04:00
return
endif
2015-12-08 08:20:04 -05:00
2018-06-14 06:31:12 -04:00
let height = go#config#ListHeight()
2016-06-26 07:12:36 -04:00
if height == 0
" prevent creating a large location height for a large set of numbers
if a:1 > 10
let height = 10
2016-02-20 08:13:10 -05:00
else
2016-06-26 07:12:36 -04:00
let height = a:1
2016-02-20 08:13:10 -05:00
endif
2016-06-26 07:12:36 -04:00
endif
if a:listtype == "locationlist"
2016-06-26 07:12:36 -04:00
exe 'lopen ' . height
else
exe 'copen ' . height
endif
2015-12-08 08:20:04 -05:00
endfunction
" Get returns the current items from the list
2016-12-27 09:46:49 -05:00
function! go#list#Get(listtype) abort
if a:listtype == "locationlist"
2016-06-26 07:12:36 -04:00
return getloclist(0)
else
return getqflist()
endif
2015-12-08 08:20:04 -05:00
endfunction
" Populate populate the list with the given items
2016-12-27 09:46:49 -05:00
function! go#list#Populate(listtype, items, title) abort
if a:listtype == "locationlist"
2016-06-26 07:12:36 -04:00
call setloclist(0, a:items, 'r')
2019-11-16 10:28:42 -05:00
call setloclist(0, [], 'a', {'title': a:title})
2016-06-26 07:12:36 -04:00
else
call setqflist(a:items, 'r')
2019-11-16 10:28:42 -05:00
call setqflist([], 'a', {'title': a:title})
2016-06-26 07:12:36 -04:00
endif
2015-12-08 08:20:04 -05:00
endfunction
2017-07-06 08:57:35 -04:00
" Parse parses the given items based on the specified errorformat and
" populates the list.
2016-12-27 09:46:49 -05:00
function! go#list#ParseFormat(listtype, errformat, items, title) abort
2016-06-26 07:12:36 -04:00
" backup users errorformat, will be restored once we are finished
let old_errorformat = &errorformat
2015-12-08 08:20:04 -05:00
2016-06-26 07:12:36 -04:00
" parse and populate the location list
let &errorformat = a:errformat
2018-02-04 06:35:08 -05:00
try
2018-03-31 10:56:26 -04:00
call go#list#Parse(a:listtype, a:items, a:title)
2018-02-04 06:35:08 -05:00
finally
"restore back
let &errorformat = old_errorformat
endtry
2015-12-08 08:20:04 -05:00
endfunction
2016-02-20 08:13:10 -05:00
" Parse parses the given items based on the global errorformat and
" populates the list.
2018-03-31 10:56:26 -04:00
function! go#list#Parse(listtype, items, title) abort
if a:listtype == "locationlist"
2016-06-26 07:12:36 -04:00
lgetexpr a:items
2019-11-16 10:28:42 -05:00
call setloclist(0, [], 'a', {'title': a:title})
2016-06-26 07:12:36 -04:00
else
cgetexpr a:items
2019-11-16 10:28:42 -05:00
call setqflist([], 'a', {'title': a:title})
2016-06-26 07:12:36 -04:00
endif
2015-12-08 08:20:04 -05:00
endfunction
" JumpToFirst jumps to the first item in the location list
2016-12-27 09:46:49 -05:00
function! go#list#JumpToFirst(listtype) abort
if a:listtype == "locationlist"
2016-06-26 07:12:36 -04:00
ll 1
else
cc 1
endif
2015-12-08 08:20:04 -05:00
endfunction
2018-03-31 10:56:26 -04:00
" Clean cleans and closes the location list
2016-12-27 09:46:49 -05:00
function! go#list#Clean(listtype) abort
if a:listtype == "locationlist"
2016-06-26 07:12:36 -04:00
lex []
else
cex []
endif
2018-03-31 10:56:26 -04:00
call go#list#Close(a:listtype)
endfunction
" Close closes the location list
function! go#list#Close(listtype) abort
2018-06-14 06:31:12 -04:00
let autoclose_window = go#config#ListAutoclose()
2018-03-31 10:56:26 -04:00
if !autoclose_window
return
endif
if a:listtype == "locationlist"
lclose
else
cclose
endif
2015-12-08 08:20:04 -05:00
endfunction
2016-02-20 08:13:10 -05:00
function! s:listtype(listtype) abort
2018-06-14 06:31:12 -04:00
let listtype = go#config#ListType()
if empty(listtype)
return a:listtype
2016-06-26 07:12:36 -04:00
endif
2018-06-14 06:31:12 -04:00
return listtype
endfunction
" s:default_list_type_commands is the defaults that will be used for each of
" the supported commands (see documentation for g:go_list_type_commands). When
" defining a default, quickfix should be used if the command operates on
" multiple files, while locationlist should be used if the command operates on a
" single file or buffer. Keys that begin with an underscore are not supported
" in g:go_list_type_commands.
let s:default_list_type_commands = {
2018-02-04 06:35:08 -05:00
\ "GoBuild": "quickfix",
2019-01-08 05:11:54 -05:00
\ "GoDebug": "quickfix",
2018-02-04 06:35:08 -05:00
\ "GoErrCheck": "quickfix",
\ "GoFmt": "locationlist",
\ "GoGenerate": "quickfix",
\ "GoInstall": "quickfix",
\ "GoLint": "quickfix",
\ "GoMetaLinter": "quickfix",
\ "GoMetaLinterAutoSave": "locationlist",
2018-09-24 20:40:17 -04:00
\ "GoModFmt": "locationlist",
2018-02-04 06:35:08 -05:00
\ "GoModifyTags": "locationlist",
\ "GoRename": "quickfix",
\ "GoRun": "quickfix",
\ "GoTest": "quickfix",
\ "GoVet": "quickfix",
\ "_guru": "locationlist",
\ "_term": "locationlist",
\ "_job": "locationlist",
\ }
function! go#list#Type(for) abort
let l:listtype = s:listtype(get(s:default_list_type_commands, a:for))
if l:listtype == "0"
call go#util#EchoError(printf(
\ "unknown list type command value found ('%s'). Please open a bug report in the vim-go repo.",
\ a:for))
let l:listtype = "quickfix"
endif
2018-06-14 06:31:12 -04:00
return get(go#config#ListTypeCommands(), a:for, l:listtype)
2016-02-20 08:13:10 -05:00
endfunction
2018-12-17 06:28:27 -05:00
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et