From c794f186c0a618d2d4cdd5445d9ff20e6f640762 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 8 Jul 2021 11:54:15 +0200 Subject: Update --- autoload/csv.vim | 124 ++++++++++++++++++++++++++----------------- autoload/fsharp.vim | 25 +++++---- autoload/hcl.vim | 20 +++++++ autoload/polyglot/init.vim | 5 +- autoload/polyglot/sleuth.vim | 2 +- autoload/terraform.vim | 11 ---- 6 files changed, 112 insertions(+), 75 deletions(-) create mode 100644 autoload/hcl.vim (limited to 'autoload') diff --git a/autoload/csv.vim b/autoload/csv.vim index 98feee75..36a65dd3 100644 --- a/autoload/csv.vim +++ b/autoload/csv.vim @@ -14,7 +14,7 @@ endif " Some ideas are taken from the wiki http://vim.wikia.com/wiki/VimTip667 " though, implementation differs. -let s:csv_numeric_sort = v:version > 704 || v:version == 704 && has("patch341") +let s:csv_numeric_sort = v:version > 704 || v:version == 704 && has("patch951") if !s:csv_numeric_sort "{{{2 fu! csv#CSVSortValues(i1, i2) "{{{3 return (a:i1+0) == (a:i2+0) ? 0 : (a:i1+0) > (a:i2+0) ? 1 : -1 @@ -222,6 +222,15 @@ fu! csv#LocalSettings(type) "{{{3 endif endfu +fu! csv#RemoveAutoHighlight() "{{{3 + exe "aug CSV_HI".bufnr('') + exe "au! CursorMoved " + aug end + exe "aug! CSV_HI".bufnr('') + " Remove any existing highlighting + HiColumn! +endfu + fu! csv#DoAutoCommands() "{{{3 " Highlight column, on which the cursor is if exists("g:csv_highlight_column") && g:csv_highlight_column =~? 'y' @@ -233,12 +242,7 @@ fu! csv#DoAutoCommands() "{{{3 " Set highlighting for column, on which the cursor is currently HiColumn else - exe "aug CSV_HI".bufnr('') - exe "au! CursorMoved " - aug end - exe "aug! CSV_HI".bufnr('') - " Remove any existing highlighting - HiColumn! + call csv#RemoveAutoHighlight() endif " undo autocommand: let b:undo_ftplugin .= '| exe "sil! au! CSV_HI'.bufnr('').' CursorMoved "' @@ -539,7 +543,7 @@ fu! csv#WColumn(...) "{{{3 let temp=getpos('.')[2] let j=1 let ret = 1 - for i in sort(b:csv_fixed_width_cols, s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues') + for i in sort(b:csv_fixed_width_cols, s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues') if temp >= i let ret = j endif @@ -549,6 +553,9 @@ fu! csv#WColumn(...) "{{{3 call setpos('.',_cur) return ret endfu +fu! csv#ValidComment() "{{{3 + return b:csv_cmt != ['', ''] && !empty(b:csv_cmt[0]) +endfu fu! csv#MaxColumns(...) "{{{3 let this_col = exists("a:1") "return maximum number of columns in first 10 lines @@ -561,8 +568,10 @@ fu! csv#MaxColumns(...) "{{{3 endif " Filter comments out - let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') - call filter(l, 'v:val !~ pat') + if csv#ValidComment() + let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') + call filter(l, 'v:val !~ pat') + endif if !empty(l) || this_col break else @@ -606,8 +615,10 @@ fu! csv#ColWidth(colnr, row, silent) "{{{3 endif endif let b:csv_list=getline(skipfirst+1,last) - let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') - call filter(b:csv_list, 'v:val !~ pat') + if csv#ValidComment() + let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') + call filter(b:csv_list, 'v:val !~ pat') + endif call filter(b:csv_list, '!empty(v:val)') call map(b:csv_list, 'split(v:val, b:col.''\zs'')') endif @@ -898,7 +909,7 @@ fu! csv#Columnize(field) "{{{3 return result else " right align - return printf("%*S", width+1 , a:field) + return printf("%*S", width , a:field) endif endfun fu! csv#GetColPat(colnr, zs_flag) "{{{3 @@ -912,15 +923,15 @@ fu! csv#GetColPat(colnr, zs_flag) "{{{3 let pat='\%' . b:csv_fixed_width_cols[-1] . 'v.*' else let pat='\%' . b:csv_fixed_width_cols[(a:colnr - 1)] . - \ 'c.\{-}\%' . b:csv_fixed_width_cols[a:colnr] . 'v' + \ 'c.*\%<' . (b:csv_fixed_width_cols[a:colnr] + 1) . 'v' endif endif elseif !exists("b:csv_fixed_width_cols") let pat=b:col else - let pat='\%' . b:csv_fixed_width_cols[0] . 'v.\{-}' . + let pat='\%' . b:csv_fixed_width_cols[0] . 'v.*' . \ (len(b:csv_fixed_width_cols) > 1 ? - \ '\%' . b:csv_fixed_width_cols[1] . 'v' : + \ '\%<' . (b:csv_fixed_width_cols[1] + 1) . 'v' : \ '') endif return pat . (a:zs_flag ? '\zs' : '') @@ -1115,7 +1126,12 @@ fu! csv#MoveCol(forward, line, ...) "{{{3 let pat=csv#GetColPat(1, 0) else " Move backwards - let pat=csv#GetColPat(maxcol, 0) + if cpos == 1 && (exists("a:1") && a:1) + " H move to previous line + let pat=csv#GetColPat(maxcol, 0) + else + let pat='\%1v' + endif endif endif else @@ -1149,9 +1165,13 @@ fu! csv#MoveCol(forward, line, ...) "{{{3 " of a field. let epos = getpos('.') if getline('.')[col('.')-1] == ' ' - call search('\S', 'W', line('.')) - if getpos('.')[2] > spos - call setpos('.', epos) + if !exists("b:csv_fixed_width_cols") + call search('\S', 'W', line('.')) + if getpos('.')[2] > spos + call setpos('.', epos) + endif + elseif cpos > b:csv_fixed_width_cols[colnr] + call search('\%'. b:csv_fixed_width_cols[colnr]. 'v', 'W', line('.')) endif endif endif @@ -1246,8 +1266,10 @@ fu! csv#CopyCol(reg, col, cnt) "{{{3 endfor endif " Filter comments out - let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') - call filter(a, 'v:val !~ pat') + if csv#ValidComment() + let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') + call filter(a, 'v:val !~ pat') + endif if !exists("b:csv_fixed_width_cols") call map(a, 'split(v:val, ''^'' . b:col . ''\zs'')[col-1:cnt_cols]') @@ -1288,10 +1310,9 @@ fu! csv#MoveColumn(start, stop, ...) range "{{{3 endif " Swap line by line, instead of reading the whole range into memory - for i in range(a:start, a:stop) let content = getline(i) - if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if b:csv_cmt != ['',''] && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') " skip comments continue endif @@ -1359,13 +1380,9 @@ fu! csv#DupColumn(start, stop, ...) range "{{{3 " skipping comment lines (we could do it with a single :s statement, " but that would fail for the first and last column. - let commentpat = '\%(\%>'.(a:start-1).'l\V'. - \ escape(b:csv_cmt[0], '\\').'\m\)'. '\&\%(\%<'. - \ (a:stop+1). 'l\V'. escape(b:csv_cmt[0], '\\'). '\m\)' - for i in range(a:start, a:stop) let content = getline(i) - if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if csv#ValidComment() && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') " skip comments continue endif @@ -1429,10 +1446,12 @@ fu! csv#AddColumn(start, stop, ...) range "{{{3 " skipping comment lines (we could do it with a single :s statement, " but that would fail for the first and last column. - let commentpat = '\%(\%>'.(a:start-1).'l\V'. - \ escape(b:csv_cmt[0], '\\').'\m\)'. '\&\%(\%<'. - \ (a:stop+1). 'l\V'. escape(b:csv_cmt[0], '\\'). '\m\)' - if search(commentpat) + if b:csv_cmt != ['',''] + let commentpat = '\%(\%>'.(a:start-1).'l\V'. + \ escape(b:csv_cmt[0], '\\').'\m\)'. '\&\%(\%<'. + \ (a:stop+1). 'l\V'. escape(b:csv_cmt[0], '\\'). '\m\)' + endif + if !empty(commentpat) && search(commentpat) for i in range(a:start, a:stop) let content = getline(i) if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') @@ -1611,7 +1630,7 @@ fu! csv#MaxColumn(list) "{{{3 endtry call add(result, str2float(nr)) endfor - let result = sort(result, s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues') + let result = sort(result, s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues') let ind = len(result) > 9 ? 9 : len(result) if has_key(get(s:, 'additional', {}), 'distinct') && s:additional['distinct'] if exists("*uniq") @@ -1672,7 +1691,7 @@ fu! csv#DoForEachColumn(start, stop, bang) range "{{{3 endif let t = g:csv_convert let line = getline(item) - if line =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if b:csv_cmt!=['',''] && line =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') " Filter comments out call add(result, line) continue @@ -1736,7 +1755,7 @@ fu! csv#FoldValue(lnum, filter) "{{{3 for item in values(a:filter) " always fold comments away let content = getline(a:lnum) - if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if b:csv_cmt != ['',''] && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') return 1 elseif eval('content' . (item.match ? '!~' : '=~') . 'item.pat') let result += 1 @@ -1898,7 +1917,7 @@ fu! csv#GetColumn(line, col, strip) "{{{3 " Return Column content at a:line, a:col let a=getline(a:line) " Filter comments out - if a =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if csv#ValidComment() && a =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') return '' endif @@ -1979,7 +1998,7 @@ fu! csv#AnalyzeColumn(...) "{{{3 let res[item]+=1 endfor - let max_items = reverse(sort(values(res), s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues')) + let max_items = reverse(sort(values(res), s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues')) " What about the minimum 5 items? let count_items = keys(res) if len(max_items) > topn @@ -2057,6 +2076,7 @@ fu! csv#InitCSVFixedWidth() "{{{3 endif " Turn off syntax highlighting syn clear + call csv#RemoveAutoHighlight() let max_line = line('$') > 10 ? 10 : line('$') let t = getline(1, max_line) let max_len = max(map(t, 'len(split(v:val, ''\zs''))')) @@ -2118,8 +2138,8 @@ fu! csv#InitCSVFixedWidth() "{{{3 endw let b:csv_fixed_width_cols=[] let tcc=0 - let b:csv_fixed_width_cols = sort(keys(Dict), s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues') - let b:csv_fixed_width = join(sort(keys(Dict), s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues'), ',') + let b:csv_fixed_width_cols = sort(keys(Dict), s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues') + let b:csv_fixed_width = join(sort(keys(Dict), s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues'), ',') call csv#Init(1, line('$')) let &l:cc=_cc @@ -2200,7 +2220,7 @@ fu! csv#CSVMappings() "{{{3 call csv#Map('nnoremap', '', ':call csv#MoveCol(1, line("."))') call csv#Map('nnoremap', 'L', ':call csv#MoveCol(1, line("."))') try - if g:csv_bind_B == 1 + if get(g:, 'csv_bind_B', 0) == 1 call csv#Map('nnoremap', 'B', ':call csv#MoveCol(-1, line("."))') else call csv#Map('nnoremap', 'E', ':call csv#MoveCol(-1, line("."))') @@ -2431,7 +2451,7 @@ fu! csv#NewDelimiter(newdelimiter, firstl, lastl) "{{{3 let line=a:firstl while line <= a:lastl " Don't change delimiter for comments - if getline(line) =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if csv#ValidComment() && getline(line) =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') let line+=1 continue endif @@ -2476,7 +2496,7 @@ fu! csv#DuplicateRows(columnlist) "{{{3 let i = 1 let content = getline(line) " Skip comments - if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') + if csv#ValidComment() && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\') continue endif let cols = split(content, b:col. '\zs') @@ -2532,7 +2552,11 @@ fu! csv#Transpose(line1, line2) "{{{3 let TrailingDelim = getline(1) =~ b:delimiter.'$' endif - let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') + if b:csv_cmt != ['',''] + let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') + else + let pat = '' + endif try let columns = csv#MaxColumns(a:line1) @@ -2544,7 +2568,7 @@ fu! csv#Transpose(line1, line2) "{{{3 let matrix = [] for line in range(a:line1, a:line2) " Filter comments out - if getline(line) =~ pat + if !empty(pat) && getline(line) =~ pat continue endif let r = [] @@ -3033,10 +3057,12 @@ fu! csv#SumCSVRow(line, nr) "{{{3 endif let line=getline(ln) " Filter comments out - let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') - if line =~ pat - call csv#Warn("Invalid count specified") - return + if csv#ValidComment() + let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\') + if line =~ pat + call csv#Warn("Invalid count specified") + return + endif endif let func='csv#SumColumn' let cells=split(line, b:col.'\zs') diff --git a/autoload/fsharp.vim b/autoload/fsharp.vim index 89287042..67f56495 100644 --- a/autoload/fsharp.vim +++ b/autoload/fsharp.vim @@ -122,7 +122,7 @@ function! s:documentationSymbol(xmlSig, assembly, cont) endfunction " FSharpConfigDto from https://github.com/fsharp/FsAutoComplete/blob/master/src/FsAutoComplete/LspHelpers.fs -" +" " * The following options seems not working with workspace/didChangeConfiguration " since the initialization has already completed? " 'AutomaticWorkspaceInit', @@ -153,7 +153,7 @@ let s:config_keys_camel = \ {'key': 'EnableAnalyzers', 'default': 0}, \ {'key': 'AnalyzersPath'}, \ {'key': 'DisableInMemoryProjectReferences', 'default': 0}, - \ {'key': 'LineLens', 'default': {'enabled': 'replaceCodeLens', 'prefix': '//'}}, + \ {'key': 'LineLens', 'default': {'enabled': 'never', 'prefix': ''}}, \ {'key': 'UseSdkScripts', 'default': 1}, \ {'key': 'dotNetRoot'}, \ {'key': 'fsiExtraParameters', 'default': []}, @@ -182,7 +182,7 @@ endfunction function! g:fsharp#getServerConfig() let fsharp = {} - call s:buildConfigKeys() + call s:buildConfigKeys() for key in s:config_keys if exists('g:fsharp#' . key.snake) let fsharp[key.camel] = g:fsharp#{key.snake} @@ -323,11 +323,17 @@ endfunction let s:script_root_dir = expand(':p:h') . "/../" let s:fsac = fnamemodify(s:script_root_dir . "fsac/fsautocomplete.dll", ":p") let g:fsharp#languageserver_command = - \ ['dotnet', s:fsac, + \ ['dotnet', s:fsac, \ '--background-service-enabled' \ ] -function! s:download(branch) +function! s:update_win() + echom "[FSAC] Downloading FSAC. This may take a while..." + let script = s:script_root_dir . "install.ps1" + call system('powershell -ExecutionPolicy Unrestricted ' . script . " update") +endfunction + +function! s:update_unix() echom "[FSAC] Downloading FSAC. This may take a while..." let zip = s:script_root_dir . "fsac.zip" call system( @@ -337,19 +343,18 @@ function! s:download(branch) if v:shell_error == 0 call system('unzip -o -d ' . s:script_root_dir . "/fsac " . zip) call system('find ' . s:script_root_dir . '/fsac' . ' -type f -exec chmod 777 \{\} \;') - echom "[FSAC] Updated FsAutoComplete to version " . a:branch . "" + echom "[FSAC] Updated FsAutoComplete" else echom "[FSAC] Failed to update FsAutoComplete" endif endfunction function! fsharp#updateFSAC(...) - if len(a:000) == 0 - let branch = "master" + if has('win32') && !has('win32unix') + call s:update_win() else - let branch = a:000[0] + call s:update_unix() endif - call s:download(branch) endfunction let s:fsi_buffer = -1 diff --git a/autoload/hcl.vim b/autoload/hcl.vim new file mode 100644 index 00000000..b76def6a --- /dev/null +++ b/autoload/hcl.vim @@ -0,0 +1,20 @@ +if polyglot#init#is_disabled(expand(':p'), 'terraform', 'autoload/hcl.vim') + finish +endif + +let s:cpo_save = &cpoptions +set cpoptions&vim + +function! hcl#align() abort + let p = '^.*=[^>]*$' + if exists(':Tabularize') && getline('.') =~# '^.*=' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) + let column = strlen(substitute(getline('.')[0:col('.')],'[^=]','','g')) + let position = strlen(matchstr(getline('.')[0:col('.')],'.*=\s*\zs.*')) + Tabularize/=.*/l1 + normal! 0 + call search(repeat('[^=]*=',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) + endif +endfunction + +let &cpoptions = s:cpo_save +unlet s:cpo_save diff --git a/autoload/polyglot/init.vim b/autoload/polyglot/init.vim index 7aa94939..04353964 100644 --- a/autoload/polyglot/init.vim +++ b/autoload/polyglot/init.vim @@ -1944,6 +1944,7 @@ endif if !has_key(g:polyglot_is_disabled, 'terraform') au BufNewFile,BufRead *.tf,*.tfvars setf terraform + au BufNewFile,BufRead *.hcl,*.nomad,*.workflow,{.,}terraformrc,Appfile,terraform.rc setf hcl endif if !has_key(g:polyglot_is_disabled, 'tf') @@ -2309,10 +2310,6 @@ if !has_key(g:polyglot_is_disabled, 'hive') au BufNewFile,BufRead *.hql,*.q,*.ql setf hive endif -if !has_key(g:polyglot_is_disabled, 'hcl') - au BufNewFile,BufRead *.hcl,*.nomad,*.workflow,Appfile setf hcl -endif - if !has_key(g:polyglot_is_disabled, 'haxe') au BufNewFile,BufRead *.hx,*.hxsl setf haxe au BufNewFile,BufRead *.hxml setf hxml diff --git a/autoload/polyglot/sleuth.vim b/autoload/polyglot/sleuth.vim index d308561c..bf3166a4 100644 --- a/autoload/polyglot/sleuth.vim +++ b/autoload/polyglot/sleuth.vim @@ -217,7 +217,7 @@ let s:globs = { \ 'hastepreproc': '*.htpp', \ 'haxe': '*.hx,*.hxsl', \ 'hb': '*.hb', - \ 'hcl': '*.hcl,*.nomad,*.workflow,Appfile', + \ 'hcl': '*.hcl,*.nomad,*.workflow,Appfile,.terraformrc,terraform.rc', \ 'helm': '', \ 'help': '', \ 'hercules': '*.vc,*.ev,*.sum,*.errsum', diff --git a/autoload/terraform.vim b/autoload/terraform.vim index 324b978d..852b261f 100644 --- a/autoload/terraform.vim +++ b/autoload/terraform.vim @@ -35,17 +35,6 @@ function! terraform#fmt() abort call winrestview(curw) endfunction -function! terraform#align() abort - let p = '^.*=[^>]*$' - if exists(':Tabularize') && getline('.') =~# '^.*=' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) - let column = strlen(substitute(getline('.')[0:col('.')],'[^=]','','g')) - let position = strlen(matchstr(getline('.')[0:col('.')],'.*=\s*\zs.*')) - Tabularize/=.*/l1 - normal! 0 - call search(repeat('[^=]*=',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) - endif -endfunction - function! terraform#commands(ArgLead, CmdLine, CursorPos) abort let commands = [ \ 'init', -- cgit v1.2.3