Make sure custom scripts.vim are respected as well

This commit is contained in:
Adam Stankiewicz
2020-10-17 17:40:10 +02:00
parent 0021384259
commit 518d733369
11 changed files with 2376 additions and 89 deletions

View File

@@ -578,6 +578,10 @@ function! go#config#DiagnosticsEnabled() abort
return get(g:, 'go_diagnostics_enabled', 0)
endfunction
function! go#config#DiagnosticsIgnoreWarnings() abort
return get(g:, 'go_diagnostics_ignore_warnings', 0)
endfunction
function! go#config#GoplsOptions() abort
return get(g:, 'go_gopls_options', ['-remote=auto'])
endfunction

View File

@@ -3,7 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
let g:nim_log = []
let s:plugin_path = escape(expand('<sfile>:p:h'), '\')
if !exists("g:nim_caas_enabled")
if !exists('g:nim_caas_enabled')
let g:nim_caas_enabled = 0
endif
@@ -11,27 +11,25 @@ if !executable('nim')
echoerr "the Nim compiler must be in your system's PATH"
endif
if has("python3")
exe 'py3file ' . fnameescape(s:plugin_path) . '/nim_vim.py'
elseif has("python")
exe 'pyfile ' . fnameescape(s:plugin_path) . '/nim_vim.py'
if has('pythonx')
exe 'pyxfile ' . fnameescape(s:plugin_path) . '/nim_vim.py'
endif
fun! nim#init()
let cmd = printf("nim --dump.format:json --verbosity:0 dump %s", s:CurrentNimFile())
fun! nim#init() abort
let cmd = printf('nim --dump.format:json --verbosity:0 dump %s', s:CurrentNimFile())
let raw_dumpdata = system(cmd)
if !v:shell_error && expand("%:e") == "nim"
if !v:shell_error && expand('%:e') ==# 'nim'
let false = 0 " Needed for eval of json
let true = 1 " Needed for eval of json
let dumpdata = eval(substitute(raw_dumpdata, "\n", "", "g"))
let dumpdata = eval(substitute(raw_dumpdata, "\n", '', 'g'))
let b:nim_project_root = dumpdata['project_path']
let b:nim_defined_symbols = dumpdata['defined_symbols']
let b:nim_caas_enabled = g:nim_caas_enabled || index(dumpdata['defined_symbols'], 'forcecaas') != -1
for path in dumpdata['lib_paths']
if finddir(path) == path
let &l:path = path . "," . &l:path
if finddir(path) ==# path
let &l:path = path . ',' . &l:path
endif
endfor
else
@@ -39,7 +37,7 @@ fun! nim#init()
endif
endf
fun! s:UpdateNimLog()
fun! s:UpdateNimLog() abort
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
@@ -56,32 +54,32 @@ endf
augroup NimVim
au!
au BufEnter log://nim call s:UpdateNimLog()
if has("python3") || has("python")
" au QuitPre * :py nimTerminateAll()
au VimLeavePre * :py nimTerminateAll()
if has('pythonx')
" au QuitPre * :pyx nimTerminateAll()
au VimLeavePre * :pyx nimTerminateAll()
endif
augroup END
command! NimLog :e log://nim
command! NimTerminateService
\ :exe printf("py nimTerminateService('%s')", b:nim_project_root)
\ :exe printf("pyx nimTerminateService('%s')", b:nim_project_root)
command! NimRestartService
\ :exe printf("py nimRestartService('%s')", b:nim_project_root)
\ :exe printf("pyx nimRestartService('%s')", b:nim_project_root)
fun! s:CurrentNimFile()
fun! s:CurrentNimFile() abort
let save_cur = getpos('.')
call cursor(0, 0, 0)
let PATTERN = "\\v^\\#\\s*included from \\zs.*\\ze"
let l = search(PATTERN, "n")
let PATTERN = '\v^\#\s*included from \zs.*\ze'
let l = search(PATTERN, 'n')
if l != 0
let f = matchstr(getline(l), PATTERN)
let l:to_check = expand('%:h') . "/" . f
let l:to_check = expand('%:h') . '/' . f
else
let l:to_check = expand("%")
let l:to_check = expand('%')
endif
call setpos('.', save_cur)
@@ -108,42 +106,42 @@ let g:nim_symbol_types = {
\ 'skEnumField': 'v',
\ }
fun! NimExec(op)
let isDirty = getbufvar(bufnr('%'), "&modified")
fun! NimExec(op) abort
let isDirty = getbufvar(bufnr('%'), '&modified')
if isDirty
let tmp = tempname() . bufname("%") . "_dirty.nim"
silent! exe ":w " . tmp
let tmp = tempname() . bufname('%') . '_dirty.nim'
silent! exe ':w ' . tmp
let cmd = printf("idetools %s --trackDirty:\"%s,%s,%d,%d\" \"%s\"",
let cmd = printf('idetools %s --trackDirty:"%s,%s,%d,%d" "%s"',
\ a:op, tmp, expand('%:p'), line('.'), col('.')-1, s:CurrentNimFile())
else
let cmd = printf("idetools %s --track:\"%s,%d,%d\" \"%s\"",
let cmd = printf('idetools %s --track:"%s,%d,%d" "%s"',
\ a:op, expand('%:p'), line('.'), col('.')-1, s:CurrentNimFile())
endif
if b:nim_caas_enabled
exe printf("py nimExecCmd('%s', '%s', False)", b:nim_project_root, cmd)
let output = l:py_res
exe printf("pyx nimExecCmd('%s', '%s', False)", b:nim_project_root, cmd)
let output = get(l:, 'py_res', '')
else
let output = system("nim " . cmd)
let output = system('nim ' . cmd)
endif
call add(g:nim_log, "nim " . cmd . "\n" . output)
call add(g:nim_log, 'nim ' . cmd . "\n" . output)
return output
endf
fun! NimExecAsync(op, Handler)
fun! NimExecAsync(op, Handler) abort
let result = NimExec(a:op)
call a:Handler(result)
endf
fun! NimComplete(findstart, base)
if b:nim_caas_enabled == 0
fun! NimComplete(findstart, base) abort
if b:nim_caas_enabled ==# 0
return -1
endif
if a:findstart
if synIDattr(synIDtrans(synID(line("."),col("."),1)), "name") == 'Comment'
if synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name') ==# 'Comment'
return -1
endif
let line = getline('.')
@@ -154,10 +152,10 @@ fun! NimComplete(findstart, base)
return start
else
let result = []
let sugOut = NimExec("--suggest")
let sugOut = NimExec('--suggest')
for line in split(sugOut, '\n')
let lineData = split(line, '\t')
if len(lineData) > 0 && lineData[0] == "sug"
if len(lineData) > 0 && lineData[0] ==# 'sug'
let word = split(lineData[2], '\.')[-1]
if a:base ==? '' || word =~# '^' . a:base
let kind = get(g:nim_symbol_types, lineData[1], '')
@@ -170,7 +168,7 @@ fun! NimComplete(findstart, base)
endif
endf
if !exists("g:neocomplcache_omni_patterns")
if !exists('g:neocomplcache_omni_patterns')
let g:neocomplcache_omni_patterns = {}
endif
let g:neocomplcache_omni_patterns['nim'] = '[^. *\t]\.\w*'
@@ -182,7 +180,7 @@ let g:neocomplete#sources#omni#input_patterns['nim'] = '[^. *\t]\.\w*'
let g:nim_completion_callbacks = {}
fun! NimAsyncCmdComplete(cmd, output)
fun! NimAsyncCmdComplete(cmd, output) abort
call add(g:nim_log, a:output)
echom g:nim_completion_callbacks
if has_key(g:nim_completion_callbacks, a:cmd)
@@ -190,52 +188,52 @@ fun! NimAsyncCmdComplete(cmd, output)
call Callback(a:output)
" remove(g:nim_completion_callbacks, a:cmd)
else
echom "ERROR, Unknown Command: " . a:cmd
echom 'ERROR, Unknown Command: ' . a:cmd
endif
return 1
endf
fun! GotoDefinition_nim_ready(def_output)
fun! GotoDefinition_nim_ready(def_output) abort
if v:shell_error
echo "nim was unable to locate the definition. exit code: " . v:shell_error
echo 'nim was unable to locate the definition. exit code: ' . v:shell_error
" echoerr a:def_output
return 0
endif
let rawDef = matchstr(a:def_output, 'def\t\([^\n]*\)')
if rawDef == ""
echo "the current cursor position does not match any definitions"
if rawDef == ''
echo 'the current cursor position does not match any definitions'
return 0
endif
let defBits = split(rawDef, '\t')
let file = defBits[4]
let line = defBits[5]
exe printf("e +%d %s", line, file)
exe printf('e +%d %s', line, file)
return 1
endf
fun! GotoDefinition_nim()
call NimExecAsync("--def", function("GotoDefinition_nim_ready"))
fun! GotoDefinition_nim() abort
call NimExecAsync('--def', function('GotoDefinition_nim_ready'))
endf
fun! FindReferences_nim()
setloclist()
fun! FindReferences_nim() abort
"setloclist()
endf
" Syntastic syntax checking
fun! SyntaxCheckers_nim_nim_GetLocList()
fun! SyntaxCheckers_nim_nim_GetLocList() abort
let makeprg = 'nim check --hints:off --listfullpaths ' . s:CurrentNimFile()
let errorformat = &errorformat
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endf
function! SyntaxCheckers_nim_nim_IsAvailable()
return executable("nim")
function! SyntaxCheckers_nim_nim_IsAvailable() abort
return executable('nim')
endfunction
if exists("g:SyntasticRegistry")
if exists('g:SyntasticRegistry')
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'nim',
\ 'name': 'nim'})

View File

@@ -1,12 +1,12 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
if exists("current_compiler")
if exists('current_compiler')
finish
endif
let current_compiler = "nim"
let current_compiler = 'nim'
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
if exists(':CompilerSet') != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif

View File

@@ -1941,6 +1941,14 @@ By default it is disabled.
>
let g:go_diagnostics_enabled = 0
<
*'g:go_diagnostics_ignore_warnings'*
Specifies whether warnings from `gopls` diagnostics are ignored.
By default it is disabled.
>
let g:go_diagnostics_ignore_warnings = 0
<
*'g:go_template_autocreate'*

2257
extras/filetype.vim Normal file

File diff suppressed because it is too large Load Diff

1
filetype.vim Normal file
View File

@@ -0,0 +1 @@
runtime! ftdetect/polyglot.vim

View File

@@ -3431,7 +3431,7 @@ augroup END
" detected filetypes.
if exists("did_load_filetypes") && exists("g:polyglot_disabled")
unlet did_load_filetypes
runtime! $VIMRUNTIME/filetype.vim
runtime! extras/filetype.vim
endif
" Restore 'cpoptions'

View File

@@ -1,7 +1,7 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
@@ -14,7 +14,7 @@ setlocal indentexpr=GetNimIndent(v:lnum)
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif
" Only define the function once.
if exists("*GetNimIndent")
if exists('*GetNimIndent')
finish
endif
@@ -40,7 +40,7 @@ function! GetNimIndent(lnum)
endif
" If the start of the line is in a string don't change the indent.
if has('syntax_items') && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$"
if has('syntax_items') && synIDattr(synID(a:lnum, 1, 1), 'name') =~# 'String$'
return -1
endif
@@ -56,12 +56,12 @@ function! GetNimIndent(lnum)
" If the last character in the line is a comment, do a binary search for
" the start of the comment. synID() is slow, a linear search would take
" too long on a long line.
if synIDattr(synID(plnum, pline_len, 1), "name") =~ "Comment$"
if synIDattr(synID(plnum, pline_len, 1), 'name') =~# 'Comment$'
let min = 1
let max = pline_len
while min < max
let col = (min + max) / 2
if synIDattr(synID(plnum, col, 1), "name") =~ "Comment$"
if synIDattr(synID(plnum, col, 1), 'name') =~# 'Comment$'
let max = col
else
let min = col + 1
@@ -80,16 +80,16 @@ function! GetNimIndent(lnum)
endwhile
endif
if cline =~ '^\s*\(if\|when\|for\|while\|case\|of\|try\)\>'
if cline =~# '^\s*\(if\|when\|for\|while\|case\|of\|try\)\>'
" This is a benign line, do nothing
return -1
endif
" If the current line begins with a keyword that lines up with "try"
if cline =~ '^\s*\(except\|finally\)\>'
if cline =~# '^\s*\(except\|finally\)\>'
let lnum = a:lnum - 1
while lnum >= 1
if getline(lnum) =~ '^\s*\(try\|except\)\>'
if getline(lnum) =~# '^\s*\(try\|except\)\>'
let ind = indent(lnum)
if ind >= clindent
return -1 " indent is already less than this
@@ -102,31 +102,31 @@ function! GetNimIndent(lnum)
endif
" If the current line begins with a header keyword, dedent
if cline =~ '^\s*\(elif\|else\)\>'
if cline =~# '^\s*\(elif\|else\)\>'
return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)')
endif
if pline =~ ':\s*$'
if pline =~# ':\s*$'
"return s:FindStartLine(plnum, '(^\s*\(if\|when\|else\|elif\|case\|of\|try\|except\|finally\)\>)\|\<do\>') + &sw
return s:FindStartLine(plnum, '^\s*\(if\|when\|else\|elif\|for\|while\|case\|of\|try\|except\|finally\)\>') + &sw
endif
if pline =~ '=\s*$'
if pline =~# '=\s*$'
return s:FindStartLine(plnum, '^\s*\(proc\|template\|macro\|iterator\)\>') + &sw
endif
" if we got here, this should be the begging of a multi-line if expression for example
if pline =~ '^\s*\(if\|when\|proc\|iterator\|macro\|template\|for\|while\)[^:]*$'
if pline =~# '^\s*\(if\|when\|proc\|iterator\|macro\|template\|for\|while\)[^:]*$'
return plindent + &sw
endif
if pline =~ '\(type\|import\|const\|var\|let\)\s*$'
\ || pline =~ '=\s*\(object\|enum\|tuple\|concept\)'
if pline =~# '\(type\|import\|const\|var\|let\)\s*$'
\ || pline =~# '=\s*\(object\|enum\|tuple\|concept\)'
return plindent + &sw
endif
" If the previous line was a stop-execution statement...
if pline =~ '^\s*\(break\|continue\|raise\|return\)\>'
if pline =~# '^\s*\(break\|continue\|raise\|return\)\>'
" See if the user has already dedented
if indent(a:lnum) > plindent - &sw
" If not, recommend one dedent

View File

@@ -1,3 +1,9 @@
if !exists("did_load_polyglot")
" Turn on filetype plugins (:help filetype-plugin).
if has('autocmd') && !(exists("did_load_filetypes") && exists("did_indent_on"))
filetype plugin indent on
endif
" Enable syntax highlighting.
if has('syntax') && !exists('g:syntax_on')
syntax enable
endif

View File

@@ -257,9 +257,8 @@ def parse_remote(remote)
[match[:repo], match[:branch] || "master", match[:path], dir]
end
def copy_file(package, src, dest)
def copy_file(name, src, dest)
FileUtils.mkdir_p(File.dirname(dest))
name = package.fetch("name")
if dest.end_with?(".vim")
header = '" Polyglot metafile'
@@ -509,11 +508,11 @@ def extract(packages)
globs.each do |glob|
Dir.glob("#{subdir}/#{glob}", base: subtree).each do |p|
next unless File.file?("#{subtree}#{p}")
copy_file(package, "#{subtree}#{p}", p)
copy_file(package["name"], "#{subtree}#{p}", p)
end
end
elsif File.exist?(subpath)
copy_file(package, subpath, subdir)
copy_file(package["name"], subpath, subdir)
end
end
@@ -889,6 +888,19 @@ def show_warnings(all_filetypes, expected_filetypes)
end
end
def generate_fallback
filetype_content = File.read('tmp/vim/vim/runtime/filetype.vim')
filetype_content.gsub!('runtime! ftdetect/*.vim', '')
filetype_content.gsub!(/^au BufNewFile,BufRead \*\n.+?runtime!.+?endif/m) {}
filetype_content.gsub!(/^au StdinReadPost \* .+?runtime!.+?endif/m) {}
filetype_content.gsub!(/^au filetypedetect BufNewFile,BufRead,StdinReadPost \*\n.+?endif/m) {}
File.write('extras/filetype.vim', filetype_content)
autoload_content = File.read('tmp/vim/vim/runtime/autoload/dist/ft.vim')
autoload_content.gsub!('dist#ft#', 'polyglot#ft#')
File.write('autoload/polyglot/ft.vim', autoload_content)
end
if __FILE__ == $0
if !ENV["DEV"]
@@ -900,6 +912,7 @@ if __FILE__ == $0
packages, heuristics = load_data()
download(packages)
extract(packages)
generate_fallback()
generate_ftdetect(packages, heuristics)
generate_plugins(packages)
generate_tests(packages)

View File

@@ -2,30 +2,30 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
if v:version < 600
syntax clear
elseif exists("b:current_syntax")
elseif exists('b:current_syntax')
finish
endif
" Keep user-supplied options
if !exists("nim_highlight_numbers")
if !exists('nim_highlight_numbers')
let nim_highlight_numbers = 1
endif
if !exists("nim_highlight_builtins")
if !exists('nim_highlight_builtins')
let nim_highlight_builtins = 1
endif
if !exists("nim_highlight_exceptions")
if !exists('nim_highlight_exceptions')
let nim_highlight_exceptions = 1
endif
if !exists("nim_highlight_space_errors")
if !exists('nim_highlight_space_errors')
let nim_highlight_space_errors = 1
endif
if !exists("nim_highlight_special_vars")
if !exists('nim_highlight_special_vars')
let nim_highlight_special_vars = 1
endif
if exists("nim_highlight_all")
if exists('nim_highlight_all')
let nim_highlight_numbers = 1
let nim_highlight_builtins = 1
let nim_highlight_exceptions = 1
@@ -158,8 +158,8 @@ syn sync match nimSync grouphere NONE "):$"
syn sync maxlines=200
syn sync minlines=2000
if version >= 508 || !exists("did_nim_syn_inits")
if version <= 508
if v:version >= 508 || !exists('did_nim_syn_inits')
if v:version <= 508
let did_nim_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
@@ -202,7 +202,7 @@ if version >= 508 || !exists("did_nim_syn_inits")
delcommand HiLink
endif
let b:current_syntax = "nim"
let b:current_syntax = 'nim'
endif