diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2021-09-09 12:05:33 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2021-09-09 12:05:33 +0200 |
commit | 7f98e949d4922ba2109304bd4cabe9578a8062fb (patch) | |
tree | e1b08f862397c14ab799e8f277c6fc39ec48b3b6 /autoload | |
parent | ce31cd1d2f4e8eee9fd91325e4599f15cb9566fd (diff) | |
download | vim-polyglot-7f98e949d4922ba2109304bd4cabe9578a8062fb.tar.gz vim-polyglot-7f98e949d4922ba2109304bd4cabe9578a8062fb.zip |
Update
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/dart.vim | 24 | ||||
-rw-r--r-- | autoload/elixir/indent.vim | 110 | ||||
-rw-r--r-- | autoload/fsharp.vim | 102 | ||||
-rw-r--r-- | autoload/polyglot/ft.vim | 19 | ||||
-rw-r--r-- | autoload/polyglot/init.vim | 2 | ||||
-rw-r--r-- | autoload/polyglot/sleuth.vim | 2 |
6 files changed, 248 insertions, 11 deletions
diff --git a/autoload/dart.vim b/autoload/dart.vim index 959b67ca..a5733d03 100644 --- a/autoload/dart.vim +++ b/autoload/dart.vim @@ -31,9 +31,9 @@ endfunction function! dart#fmt(...) abort let l:dartfmt = s:FindDartFmt() - if type(l:dartfmt) != type('') | return | endif + if empty(l:dartfmt) | return | endif let buffer_content = getline(1, '$') - let l:cmd = [l:dartfmt, '--stdin-name', shellescape(expand('%'))] + let l:cmd = extend(l:dartfmt, ['--stdin-name', shellescape(expand('%'))]) if exists('g:dartfmt_options') call extend(l:cmd, g:dartfmt_options) endif @@ -64,14 +64,30 @@ function! dart#fmt(...) abort endfunction function! s:FindDartFmt() abort - if executable('dartfmt') | return 'dartfmt' | endif + if executable('dart') + let l:version_text = system('dart --version') + let l:match = matchlist(l:version_text, + \ '\vDart SDK version: (\d+)\.(\d+)\.\d+.*') + if empty(l:match) + call s:error('Unable to determine dart version') + return [] + endif + let l:major = l:match[1] + let l:minor = l:match[2] + if l:major > 2 || l:major == 2 && l:minor >= 14 + return ['dart', 'format'] + endif + endif + " Legacy fallback for Dart SDK pre 2.14 + if executable('dartfmt') | return ['dartfmt'] | endif if executable('flutter') let l:flutter_cmd = resolve(exepath('flutter')) let l:bin = fnamemodify(l:flutter_cmd, ':h') let l:dartfmt = l:bin.'/cache/dart-sdk/bin/dartfmt' - if executable(l:dartfmt) | return l:dartfmt | endif + if executable(l:dartfmt) | return [l:dartfmt] | endif endif call s:error('Cannot find a `dartfmt` command') + return [] endfunction function! dart#analyzer(q_args) abort diff --git a/autoload/elixir/indent.vim b/autoload/elixir/indent.vim index c9adcd0a..ccf388b7 100644 --- a/autoload/elixir/indent.vim +++ b/autoload/elixir/indent.vim @@ -24,6 +24,7 @@ function! elixir#indent#indent(lnum) call cursor(lnum, 0) let handlers = [ + \'inside_embedded_view', \'top_of_file', \'starts_with_string_continuation', \'following_trailing_binary_operator', @@ -69,6 +70,17 @@ function! s:prev_starts_with(context, expr) return s:_starts_with(a:context.prev_nb_text, a:expr, a:context.prev_nb_lnum) endfunction +function! s:in_embedded_view() + let groups = map(synstack(line('.'), col('.')), "synIDattr(v:val, 'name')") + for group in ['elixirPhoenixESigil', 'elixirLiveViewSigil', 'elixirSurfaceSigil'] + if index(groups, group) >= 0 + return 1 + endif + endfor + + return 0 +endfunction + " Returns 0 or 1 based on whether or not the text starts with the given " expression and is not a string or comment function! s:_starts_with(text, expr, lnum) @@ -160,6 +172,104 @@ function! s:find_last_pos(lnum, text, match) return -1 endfunction +function! elixir#indent#handle_inside_embedded_view(context) + if !s:in_embedded_view() + return -1 + endif + + " Multi-line Surface data delimiters + let pair_lnum = searchpair('{{', '', '}}', 'bW', "line('.') == ".a:context.lnum." || s:is_string_or_comment(line('.'), col('.'))", max([0, a:context.lnum - g:elixir_indent_max_lookbehind])) + if pair_lnum + if a:context.text =~ '}}$' + return indent(pair_lnum) + elseif a:context.text =~ '}}*>$' + return -1 + elseif s:prev_ends_with(a:context, '[\|%{') + return indent(a:context.prev_nb_lnum) + s:sw() + elseif a:context.prev_nb_text =~ ',$' + return indent(a:context.prev_nb_lnum) + else + return indent(pair_lnum) + s:sw() + endif + endif + + " Multi-line opening tag -- >, />, or %> are on a different line that their opening < + let pair_lnum = searchpair('^\s\+<.*[^>]$', '', '^[^<]*[/%}]\?>$', 'bW', "line('.') == ".a:context.lnum." || s:is_string_or_comment(line('.'), col('.'))", max([0, a:context.lnum - g:elixir_indent_max_lookbehind])) + if pair_lnum + if a:context.text =~ '^\s\+\%\(>\|\/>\|%>\|}}>\)$' + call s:debug("current line is a lone >, />, or %>") + return indent(pair_lnum) + elseif a:context.text =~ '\%\(>\|\/>\|%>\|}}>\)$' + call s:debug("current line ends in >, />, or %>") + if s:prev_ends_with(a:context, ',') + return indent(a:context.prev_nb_lnum) + else + return -1 + endif + else + call s:debug("in the body of a multi-line opening tag") + return indent(pair_lnum) + s:sw() + endif + endif + + " Special cases + if s:prev_ends_with(a:context, '^[^<]*do\s%>') + call s:debug("prev line closes a multi-line do block") + return indent(a:context.prev_nb_lnum) + elseif a:context.prev_nb_text =~ 'do\s*%>$' + call s:debug("prev line opens a do block") + return indent(a:context.prev_nb_lnum) + s:sw() + elseif a:context.text =~ '^\s\+<\/[a-zA-Z0-9\.\-_]\+>\|<% end %>' + call s:debug("a single closing tag") + if a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>.*<\/[a-zA-Z0-9\.\-_]\+>$' + call s:debug("opening and closing tags are on the same line") + return indent(a:context.prev_nb_lnum) - s:sw() + elseif a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>\|\s\+>' + call s:debug("prev line is opening html tag or single >") + return indent(a:context.prev_nb_lnum) + elseif s:prev_ends_with(a:context, '^[^<]*\%\(do\s\)\@<!%>') + call s:debug("prev line closes a multi-line eex tag") + return indent(a:context.prev_nb_lnum) - 2 * s:sw() + else + return indent(a:context.prev_nb_lnum) - s:sw() + endif + elseif a:context.text =~ '^\s*<%\s*\%(end\|else\|catch\|rescue\)\>.*%>' + call s:debug("eex middle or closing eex tag") + return indent(a:context.prev_nb_lnum) - s:sw() + elseif a:context.prev_nb_text =~ '\s*<\/\|<% end %>$' + call s:debug("prev is closing tag") + return indent(a:context.prev_nb_lnum) + elseif a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>.*<\/[a-zA-Z0-9\.\-_]\+>$' + call s:debug("opening and closing tags are on the same line") + return indent(a:context.prev_nb_lnum) + elseif s:prev_ends_with(a:context, '\s\+\/>') + call s:debug("prev ends with a single \>") + return indent(a:context.prev_nb_lnum) + elseif s:prev_ends_with(a:context, '^[^<]*\/>') + call s:debug("prev line is closing a multi-line self-closing tag") + return indent(a:context.prev_nb_lnum) - s:sw() + elseif s:prev_ends_with(a:context, '^\s\+<.*\/>') + call s:debug("prev line is closing self-closing tag") + return indent(a:context.prev_nb_lnum) + elseif a:context.prev_nb_text =~ '^\s\+%\?>$' + call s:debug("prev line is a single > or %>") + return indent(a:context.prev_nb_lnum) + s:sw() + endif + + " Simple HTML (ie, opening tag is not split across lines) + let pair_lnum = searchpair('^\s\+<[^%\/].*[^\/>]>$', '', '^\s\+<\/\w\+>$', 'bW', "line('.') == ".a:context.lnum." || s:is_string_or_comment(line('.'), col('.'))", max([0, a:context.lnum - g:elixir_indent_max_lookbehind])) + if pair_lnum + call s:debug("simple HTML") + if a:context.text =~ '^\s\+<\/\w\+>$' + return indent(pair_lnum) + else + return indent(pair_lnum) + s:sw() + endif + endif + + return -1 +endfunction + function! elixir#indent#handle_top_of_file(context) if a:context.prev_nb_lnum == 0 return 0 diff --git a/autoload/fsharp.vim b/autoload/fsharp.vim index 8567a037..d18f2bbc 100644 --- a/autoload/fsharp.vim +++ b/autoload/fsharp.vim @@ -233,6 +233,107 @@ function! fsharp#updateServerConfig() call s:notify('workspace/didChangeConfiguration', settings) endfunction +function! fsharp#loadConfig() + if exists('s:config_is_loaded') + return + endif + + if !exists('g:fsharp#fsautocomplete_command') + let s:fsac = fnamemodify(s:script_root_dir . "fsac/fsautocomplete.dll", ":p") + + " check if FSAC exists + if empty(glob(s:fsac)) + echoerr "FSAC not found. :FSharpUpdateFSAC to download." + let &cpo = s:cpo_save + finish + endif + + let g:fsharp#fsautocomplete_command = + \ ['dotnet', s:fsac, + \ '--background-service-enabled' + \ ] + endif + if !exists('g:fsharp#use_recommended_server_config') + let g:fsharp#use_recommended_server_config = 1 + endif + call fsharp#getServerConfig() + if !exists('g:fsharp#automatic_workspace_init') + let g:fsharp#automatic_workspace_init = 1 + endif + if !exists('g:fsharp#automatic_reload_workspace') + let g:fsharp#automatic_reload_workspace = 1 + endif + if !exists('g:fsharp#show_signature_on_cursor_move') + let g:fsharp#show_signature_on_cursor_move = 1 + endif + if !exists('g:fsharp#fsi_command') + let g:fsharp#fsi_command = "dotnet fsi" + endif + if !exists('g:fsharp#fsi_keymap') + let g:fsharp#fsi_keymap = "vscode" + endif + if !exists('g:fsharp#fsi_window_command') + let g:fsharp#fsi_window_command = "botright 10new" + endif + if !exists('g:fsharp#fsi_focus_on_send') + let g:fsharp#fsi_focus_on_send = 0 + endif + if !exists('g:fsharp#backend') + if has('nvim-0.5') + if exists('g:LanguageClient_loaded') + let g:fsharp#backend = "languageclient-neovim" + else + let g:fsharp#backend = "nvim" + endif + else + let g:fsharp#backend = "languageclient-neovim" + endif + endif + + " backend configuration + if g:fsharp#backend == 'languageclient-neovim' + if !exists('g:LanguageClient_serverCommands') + let g:LanguageClient_serverCommands = {} + endif + if !has_key(g:LanguageClient_serverCommands, 'fsharp') + let g:LanguageClient_serverCommands.fsharp = { + \ 'name': 'fsautocomplete', + \ 'command': g:fsharp#fsautocomplete_command, + \ 'initializationOptions': {}, + \} + if g:fsharp#automatic_workspace_init + let g:LanguageClient_serverCommands.fsharp.initializationOptions = { + \ 'AutomaticWorkspaceInit': v:true, + \} + endif + endif + + if !exists('g:LanguageClient_rootMarkers') + let g:LanguageClient_rootMarkers = {} + endif + if !has_key(g:LanguageClient_rootMarkers, 'fsharp') + let g:LanguageClient_rootMarkers.fsharp = ['*.sln', '*.fsproj', '.git'] + endif + elseif g:fsharp#backend == 'nvim' + if !exists('g:fsharp#lsp_auto_setup') + let g:fsharp#lsp_auto_setup = 1 + endif + if !exists('g:fsharp#lsp_recommended_colorscheme') + let g:fsharp#lsp_recommended_colorscheme = 1 + endif + if !exists('g:fsharp#lsp_codelens') + let g:fsharp#lsp_codelens = 1 + endif + + else + if g:fsharp#backend != 'disable' + echoerr "[FSAC] Invalid backend: " . g:fsharp#backend + endif + endif + + let s:config_is_loaded = 1 +endfunction + " handlers for notifications @@ -617,7 +718,6 @@ function! fsharp#sendAllToFsi() return fsharp#sendFsi(text) endfunction - let &cpo = s:cpo_save unlet s:cpo_save diff --git a/autoload/polyglot/ft.vim b/autoload/polyglot/ft.vim index 2e4c1f69..e4c32415 100644 --- a/autoload/polyglot/ft.vim +++ b/autoload/polyglot/ft.vim @@ -264,6 +264,13 @@ func polyglot#ft#ProtoCheck(default) endfunc func polyglot#ft#FTm() + if exists("g:filetype_m") + exe "setf " . g:filetype_m + return + endif + + let octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|for\|function\|if\|methods\|parfor\|properties\|switch\|while\)\>' + let n = 1 let saw_comment = 0 " Whether we've seen a multiline comment leader. while n < 100 @@ -278,6 +285,13 @@ func polyglot#ft#FTm() setf objc return endif + if line =~ '^\s*\%(#\|%!\|[#%]{\=\s*$\)' || + \ line =~ '^\s*unwind_protect\>' || + \ line =~ '\%(^\|;\)\s*' .. octave_block_terminators + setf octave + return + endif + " TODO: could be Matlab or Octave if line =~ '^\s*%' setf matlab return @@ -298,11 +312,8 @@ func polyglot#ft#FTm() " or Murphi based on the comment leader. Assume the former as it is more " common. setf objc - elseif exists("g:filetype_m") - " Use user specified default filetype for .m - exe "setf " . g:filetype_m else - " Default is matlab + " Default is Matlab setf matlab endif endfunc diff --git a/autoload/polyglot/init.vim b/autoload/polyglot/init.vim index 04353964..d739ae7b 100644 --- a/autoload/polyglot/init.vim +++ b/autoload/polyglot/init.vim @@ -2265,7 +2265,7 @@ if !has_key(g:polyglot_is_disabled, 'jsonnet') endif if !has_key(g:polyglot_is_disabled, 'json') - au BufNewFile,BufRead *.JSON-tmLanguage,*.avsc,*.geojson,*.gltf,*.har,*.ice,*.json,*.jsonl,*.jsonp,*.mcmeta,*.template,*.tfstate,*.tfstate.backup,*.topojson,*.webapp,*.webmanifest,*.yy,*.yyp,{.,}arcconfig,{.,}htmlhintrc,{.,}imgbotconfig,{.,}tern-config,{.,}tern-project,{.,}watchmanconfig,Pipfile.lock,composer.lock,mcmod.info setf json + au BufNewFile,BufRead *.JSON-tmLanguage,*.avsc,*.geojson,*.gltf,*.har,*.ice,*.json,*.jsonl,*.jsonp,*.mcmeta,*.template,*.tfstate,*.tfstate.backup,*.topojson,*.webapp,*.webmanifest,*.yy,*.yyp,{.,}arcconfig,{.,}auto-changelog,{.,}c8rc,{.,}htmlhintrc,{.,}imgbotconfig,{.,}nycrc,{.,}tern-config,{.,}tern-project,{.,}watchmanconfig,Pipfile.lock,composer.lock,mcmod.info setf json endif if !has_key(g:polyglot_is_disabled, 'json5') diff --git a/autoload/polyglot/sleuth.vim b/autoload/polyglot/sleuth.vim index bf3166a4..a7a5b86a 100644 --- a/autoload/polyglot/sleuth.vim +++ b/autoload/polyglot/sleuth.vim @@ -264,7 +264,7 @@ let s:globs = { \ 'jovial': '*.jov,*.j73,*.jovial', \ 'jproperties': '*.properties,*.properties_??,*.properties_??_??,*.properties_??_??_*', \ 'jq': '*.jq,.jqrc,.jqrc*', - \ 'json': '*.json,*.avsc,*.geojson,*.gltf,*.har,*.ice,*.JSON-tmLanguage,*.jsonl,*.mcmeta,*.tfstate,*.tfstate.backup,*.topojson,*.webapp,*.webmanifest,*.yy,*.yyp,*.jsonp,*.template,.arcconfig,.htmlhintrc,.imgbotconfig,.tern-config,.tern-project,.watchmanconfig,Pipfile.lock,composer.lock,mcmod.info', + \ 'json': '*.json,*.avsc,*.geojson,*.gltf,*.har,*.ice,*.JSON-tmLanguage,*.jsonl,*.mcmeta,*.tfstate,*.tfstate.backup,*.topojson,*.webapp,*.webmanifest,*.yy,*.yyp,*.jsonp,*.template,.arcconfig,.auto-changelog,.c8rc,.htmlhintrc,.imgbotconfig,.nycrc,.tern-config,.tern-project,.watchmanconfig,Pipfile.lock,composer.lock,mcmod.info', \ 'json5': '*.json5', \ 'jsonc': '*.cjson,*.jsonc,coc-settings.json,.eslintrc.json,.babelrc,.jshintrc,.jslintrc,.mocharc.json,coffeelint.json,tsconfig.json,jsconfig.json', \ 'jsonnet': '*.jsonnet,*.libsonnet', |