From 6a9b01def5e53eebfbaf8ca0d0b6da2a3ddbba09 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Mon, 15 Feb 2021 15:14:24 +0800 Subject: [PATCH] Add lang#reason & lang#rescript layer (#4089) --- autoload/SpaceVim/api/language.vim | 2 +- autoload/SpaceVim/api/vim/regex.vim | 2 +- autoload/SpaceVim/layers/lang/povray.vim | 2 +- autoload/SpaceVim/layers/lang/reason.vim | 52 ++++ autoload/SpaceVim/layers/lang/rescript.vim | 45 ++++ autoload/SpaceVim/layers/lsp.vim | 5 +- autoload/SpaceVim/plugins/scrollbar.vim | 2 +- bundle/git.vim/autoload/git.vim | 2 +- .../git.vim/autoload/git/branch/manager.vim | 2 +- bundle/git.vim/autoload/git/push.vim | 2 +- bundle/git.vim/plugin/git.vim | 2 +- bundle/gtags.vim/autoload/ctags.vim | 2 +- bundle/vim-povray/ftplugin/povray.vim | 2 +- bundle/vim-reason/ftdetect/reason.vim | 2 + bundle/vim-reason/indent/reason.vim | 220 +++++++++++++++++ bundle/vim-reason/syntax/reason.vim | 223 ++++++++++++++++++ bundle/vim-rescript/ftdetect/rescript.vim | 2 + bundle/vim-rescript/indent/rescript.vim | 69 ++++++ bundle/vim-rescript/syntax/rescript.vim | 111 +++++++++ docs/cn/layers/language-server-protocol.md | 1 + docs/layers.md | 11 +- docs/layers/core/banner.md | 2 +- docs/layers/lang/reason.md | 53 +++++ docs/layers/lang/rescript.md | 39 +++ docs/layers/language-server-protocol.md | 3 +- wiki/en/programming-languages.md | 2 + 26 files changed, 842 insertions(+), 18 deletions(-) create mode 100644 autoload/SpaceVim/layers/lang/reason.vim create mode 100644 autoload/SpaceVim/layers/lang/rescript.vim create mode 100644 bundle/vim-reason/ftdetect/reason.vim create mode 100644 bundle/vim-reason/indent/reason.vim create mode 100644 bundle/vim-reason/syntax/reason.vim create mode 100644 bundle/vim-rescript/ftdetect/rescript.vim create mode 100644 bundle/vim-rescript/indent/rescript.vim create mode 100644 bundle/vim-rescript/syntax/rescript.vim create mode 100644 docs/layers/lang/reason.md create mode 100644 docs/layers/lang/rescript.md diff --git a/autoload/SpaceVim/api/language.vim b/autoload/SpaceVim/api/language.vim index a60475314..f4195b7f7 100644 --- a/autoload/SpaceVim/api/language.vim +++ b/autoload/SpaceVim/api/language.vim @@ -1,6 +1,6 @@ "============================================================================= " language.vim --- programming language information layer -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/autoload/SpaceVim/api/vim/regex.vim b/autoload/SpaceVim/api/vim/regex.vim index d1c09e280..3b33d1fd7 100644 --- a/autoload/SpaceVim/api/vim/regex.vim +++ b/autoload/SpaceVim/api/vim/regex.vim @@ -1,6 +1,6 @@ "============================================================================= " regex.vim --- regex parser for vim -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/autoload/SpaceVim/layers/lang/povray.vim b/autoload/SpaceVim/layers/lang/povray.vim index 77a48d044..5b6663869 100644 --- a/autoload/SpaceVim/layers/lang/povray.vim +++ b/autoload/SpaceVim/layers/lang/povray.vim @@ -1,6 +1,6 @@ "============================================================================= " povray.vim --- POV-Ray language support -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/autoload/SpaceVim/layers/lang/reason.vim b/autoload/SpaceVim/layers/lang/reason.vim new file mode 100644 index 000000000..a5d3c33aa --- /dev/null +++ b/autoload/SpaceVim/layers/lang/reason.vim @@ -0,0 +1,52 @@ +"============================================================================= +" reason.vim --- Reason programming language layer +" Copyright (c) 2016-2021 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg@outlook.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + + +if exists('s:JSON') + finish +endif + +let s:JSON = SpaceVim#api#import('data#json') + +function! SpaceVim#layers#lang#reason#plugins() abort + let plugins = [] + call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-reason', {'merged' : 0}]) + return plugins +endfunction + + +function! SpaceVim#layers#lang#reason#config() abort + call SpaceVim#plugins#tasks#reg_provider(funcref('s:reasonml_tasks')) + call SpaceVim#mapping#space#regesit_lang_mappings('python', function('s:language_specified_mappings')) +endfunction + +function! s:language_specified_mappings() abort + if SpaceVim#layers#lsp#check_filetype('reason') + nnoremap K :call SpaceVim#lsp#show_doc() + + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], + \ 'call SpaceVim#lsp#show_doc()', 'show_document', 1) + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], + \ 'call SpaceVim#lsp#rename()', 'rename symbol', 1) + endif +endfunction +function! s:reasonml_tasks() abort + let detect_task = {} + let conf = {} + if filereadable('package.json') + let conf = s:JSON.json_decode(join(readfile('package.json', ''), '')) + endif + if has_key(conf, 'scripts') + for task_name in keys(conf.scripts) + call extend(detect_task, { + \ task_name : {'command' : conf.scripts[task_name], 'isDetected' : 1, 'detectedName' : 'esy:'} + \ }) + endfor + endif + return detect_task +endfunction diff --git a/autoload/SpaceVim/layers/lang/rescript.vim b/autoload/SpaceVim/layers/lang/rescript.vim new file mode 100644 index 000000000..77dad5c4e --- /dev/null +++ b/autoload/SpaceVim/layers/lang/rescript.vim @@ -0,0 +1,45 @@ +"============================================================================= +" rescript.vim --- ReScript programming language layer +" Copyright (c) 2016-2021 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg@outlook.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + + +if exists('s:JSON') + finish +endif + +let s:JSON = SpaceVim#api#import('data#json') + +function! SpaceVim#layers#lang#rescript#plugins() abort + let plugins = [] + call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-rescript', {'merged' : 0}]) + return plugins +endfunction + + +function! SpaceVim#layers#lang#rescript#config() abort + call SpaceVim#plugins#tasks#reg_provider(funcref('s:rescript_tasks')) + if index(g:spacevim_project_rooter_patterns, 'package.json') ==# -1 + call add(g:spacevim_project_rooter_patterns, 'package.json') + endif +endfunction + +function! s:rescript_tasks() abort + let detect_task = {} + let conf = {} + if filereadable('package.json') + let conf = s:JSON.json_decode(join(readfile('package.json', ''), '')) + endif + if has_key(conf, 'scripts') + for task_name in keys(conf.scripts) + call extend(detect_task, { + \ task_name : {'command' : conf.scripts[task_name], 'isDetected' : 1, 'detectedName' : 'bsb:'} + \ }) + endfor + endif + return detect_task +endfunction + diff --git a/autoload/SpaceVim/layers/lsp.vim b/autoload/SpaceVim/layers/lsp.vim index d0a479be3..18748d910 100644 --- a/autoload/SpaceVim/layers/lsp.vim +++ b/autoload/SpaceVim/layers/lsp.vim @@ -124,6 +124,7 @@ let s:lsp_servers = { \ 'ada' : ['ada_language_server'], \ 'c' : ['clangd'], \ 'cpp' : ['clangd'], + \ 'crystal' : ['scry'], \ 'css' : ['css-languageserver', '--stdio'], \ 'dart' : ['dart_language_server'], \ 'dockerfile' : ['docker-langserver', '--stdio'], @@ -137,12 +138,12 @@ let s:lsp_servers = { \ 'php' : ['php', g:spacevim_plugin_bundle_dir . 'repos/github.com/phpactor/phpactor/bin/phpactor', 'language-server'], \ 'purescript' : ['purescript-language-server', '--stdio'], \ 'python' : ['pyls'], - \ 'crystal' : ['scry'], + \ 'reason' : ['ocaml-language-server'], + \ 'ruby' : ['solargraph', 'stdio'], \ 'rust' : ['rustup', 'run', 'nightly', 'rls'], \ 'scala' : ['metals-vim'], \ 'sh' : ['bash-language-server', 'start'], \ 'typescript' : ['typescript-language-server', '--stdio'], - \ 'ruby' : ['solargraph', 'stdio'], \ 'vue' : ['vls'] \ } diff --git a/autoload/SpaceVim/plugins/scrollbar.vim b/autoload/SpaceVim/plugins/scrollbar.vim index 0f6c4bffb..9d1332056 100644 --- a/autoload/SpaceVim/plugins/scrollbar.vim +++ b/autoload/SpaceVim/plugins/scrollbar.vim @@ -1,6 +1,6 @@ "============================================================================= " scrollbar.vim --- scrollbar support for SpaceVim -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/bundle/git.vim/autoload/git.vim b/bundle/git.vim/autoload/git.vim index 9afc1f5ad..b71792622 100644 --- a/bundle/git.vim/autoload/git.vim +++ b/bundle/git.vim/autoload/git.vim @@ -1,6 +1,6 @@ "============================================================================= " git.vim -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/bundle/git.vim/autoload/git/branch/manager.vim b/bundle/git.vim/autoload/git/branch/manager.vim index 269551edc..1bb163fd3 100644 --- a/bundle/git.vim/autoload/git/branch/manager.vim +++ b/bundle/git.vim/autoload/git/branch/manager.vim @@ -1,6 +1,6 @@ "============================================================================= " manager.vim --- Git branch manager -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/bundle/git.vim/autoload/git/push.vim b/bundle/git.vim/autoload/git/push.vim index 62d6866a3..2b26b0edb 100644 --- a/bundle/git.vim/autoload/git/push.vim +++ b/bundle/git.vim/autoload/git/push.vim @@ -1,6 +1,6 @@ "============================================================================= " push.vim --- push command for git.vim -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " License: GPLv3 "============================================================================= diff --git a/bundle/git.vim/plugin/git.vim b/bundle/git.vim/plugin/git.vim index 8252573cc..fc1df49c7 100644 --- a/bundle/git.vim/plugin/git.vim +++ b/bundle/git.vim/plugin/git.vim @@ -1,6 +1,6 @@ "============================================================================= " git.vim --- git plugin for spacevim -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/bundle/gtags.vim/autoload/ctags.vim b/bundle/gtags.vim/autoload/ctags.vim index 101dc844d..45553855f 100644 --- a/bundle/gtags.vim/autoload/ctags.vim +++ b/bundle/gtags.vim/autoload/ctags.vim @@ -1,6 +1,6 @@ "============================================================================= " ctags.vim --- ctags generator -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/bundle/vim-povray/ftplugin/povray.vim b/bundle/vim-povray/ftplugin/povray.vim index 8eea94efd..a7949239d 100644 --- a/bundle/vim-povray/ftplugin/povray.vim +++ b/bundle/vim-povray/ftplugin/povray.vim @@ -1,6 +1,6 @@ "============================================================================= " povray.vim --- povray ftplugin -" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 diff --git a/bundle/vim-reason/ftdetect/reason.vim b/bundle/vim-reason/ftdetect/reason.vim new file mode 100644 index 000000000..20cdc9de0 --- /dev/null +++ b/bundle/vim-reason/ftdetect/reason.vim @@ -0,0 +1,2 @@ +au BufRead,BufNewFile *.re set filetype=reason +au BufRead,BufNewFile *.rei set filetype=reason diff --git a/bundle/vim-reason/indent/reason.vim b/bundle/vim-reason/indent/reason.vim new file mode 100644 index 000000000..f3cd444c1 --- /dev/null +++ b/bundle/vim-reason/indent/reason.vim @@ -0,0 +1,220 @@ +"============================================================================= +" reason.vim --- reason indent file +" Copyright (c) 2016-2021 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg@outlook.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + +" Only load this indent file when no other was loaded. +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +" m1 is needed to make parens line up correct: +" +" let result = callSomething ( +" 1, +" 2 +" ); +" +" fN (See the docs) - additional indentation *w.r.t the "prevailing indent" only applies to blocks +" *not* in nested braces! We want it to match the blocks *inside* nested braces - and be zero, but +" the problem is that the "prevailing indent" not inside of braces is different than inside braces. +setlocal cinoptions=L0,(0,Ws,J1,j1,m1,{0,f0s +" cinkeys is ignored if indentexpr is activated so this setting is useless. See indentkeys below. +setlocal cinkeys=0{,0},0),!^F,o,O,0[,0] +" Don't think cinwords will actually do anything at all... never mind +setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fun,let,extern + +" Some preliminary settings +setlocal nolisp " Make sure lisp indenting doesn't supersede us +setlocal autoindent " indentexpr isn't much help otherwise +" Also do indentkeys, otherwise # gets shoved to column 0 :-/ +setlocal indentkeys=0{,0},0),!^F,o,O,0[,0] + + +setlocal indentexpr=GetReasonIndent(v:lnum) + +" Only define the function once. +if exists("*GetReasonIndent") + finish +endif + +" Come here when loading the script the first time. + +function! s:get_line_trimmed(lnum) + " Get the line and remove a trailing comment. + " Use syntax highlighting attributes when possible. + " NOTE: this is not accurate; /* */ or a line continuation could trick it + let line = getline(a:lnum) + let line_len = strlen(line) + if has('syntax_items') + " 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(a:lnum, line_len, 1), 'name') =~# 'Comment\|Todo' + let min = 1 + let max = line_len + while min < max + let col = (min + max) / 2 + if synIDattr(synID(a:lnum, col, 1), 'name') =~# 'Comment\|Todo' + let max = col + else + let min = col + 1 + endif + endwhile + let line = strpart(line, 0, min - 1) + endif + return substitute(line, "\s*$", '', '') + else + " Sorry, this is not complete, nor fully correct (e.g. string "//"). + " Such is life. + return substitute(line, "\s*//.*$", "", "") + endif +endfunction + +function! s:is_string_comment(lnum, col) + if has('syntax_items') + for id in synstack(a:lnum, a:col) + let synname = synIDattr(id, "name") + if synname == "rustString" || synname =~ "^rustComment" + return 1 + endif + endfor + else + " without syntax, let's not even try + return 0 + endif +endfunction + +function GetReasonIndent(lnum) + + " Starting assumption: cindent (called at the end) will do it right + " normally. We just want to fix up a few cases. + + let line = getline(a:lnum) + + if has('syntax_items') + let synname = synIDattr(synID(a:lnum, 1, 1), "name") + if synname == "rustString" + " If the start of the line is in a string, don't change the indent + return -1 + elseif synname =~ '\(Comment\|Todo\)' + \ && line !~ '^\s*/\*' " not /* opening line + if synname =~ "CommentML" " multi-line + if line !~ '^\s*\*' && getline(a:lnum - 1) =~ '^\s*/\*' + " This is (hopefully) the line after a /*, and it has no + " leader, so the correct indentation is that of the + " previous line. + return GetReasonIndent(a:lnum - 1) + endif + endif + " If it's in a comment, let cindent take care of it now. This is + " for cases like "/*" where the next line should start " * ", not + " "* " as the code below would otherwise cause for module scope + " Fun fact: " /*\n*\n*/" takes two calls to get right! + return cindent(a:lnum) + endif + endif + + " cindent gets second and subsequent match patterns/struct members wrong, + " as it treats the comma as indicating an unfinished statement:: + " + " switch a { + " | b => c + " | d => e + " | f => g + " }; + + " Search backwards for the previous non-empty line. + let prevlinenum = prevnonblank(a:lnum - 1) + let prevline = s:get_line_trimmed(prevlinenum) + while prevlinenum > 1 && prevline !~ '[^[:blank:]]' + let prevlinenum = prevnonblank(prevlinenum - 1) + let prevline = s:get_line_trimmed(prevlinenum) + endwhile + + " Handle where clauses nicely: subsequent values should line up nicely. + if prevline[len(prevline) - 1] == "," + \ && prevline =~# '^\s*where\s' + return indent(prevlinenum) + 6 + endif + + if prevline =~ "\s*|.*[{(\[]$" + " \ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]' + " \ && prevline !~ '^\s*fun\s' + " \ && prevline !~ '([^()]\+,$' + " Oh ho! The previous line ended in a comma! I bet cindent will try to + " take this too far... For now, let's normally use the previous line's + " indent. + + " One case where this doesn't work out is where *this* line contains + " square or curly brackets; then we normally *do* want to be indenting + " further. + " + " Another case where we don't want to is one like a function + " definition with arguments spread over multiple lines: + " + " fun foo(baz: Baz, + " baz: Baz) // <-- cindent gets this right by itself + " + " Another case is similar to the previous, except calling a function + " instead of defining it, or any conditional expression that leaves + " an open paren: + " + " foo(baz, + " baz); + " + " if baz && (foo || + " bar) { + " + " There are probably other cases where we don't want to do this as + " well. Add them as needed. + return indent(prevlinenum) + &shiftwidth + endif + if prevline =~ "\s*|" + return indent(prevlinenum) + endif + + if !has("patch-7.4.355") + " cindent before 7.4.355 doesn't do the module scope well at all; e.g.:: + " + " static FOO : &'static [bool] = [ + " true, + " false, + " false, + " true, + " ]; + " + " uh oh, next statement is indented further! + + " Note that this does *not* apply the line continuation pattern properly; + " that's too hard to do correctly for my liking at present, so I'll just + " start with these two main cases (square brackets and not returning to + " column zero) + + call cursor(a:lnum, 1) + if searchpair('{\|(', '', '}\|)', 'nbW', + \ 's:is_string_comment(line("."), col("."))') == 0 + if searchpair('\[', '', '\]', 'nbW', + \ 's:is_string_comment(line("."), col("."))') == 0 + " Global scope, should be zero + return 0 + else + " At the module scope, inside square brackets only + "if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum + if line =~ "^\\s*]" + " It's the closing line, dedent it + return 0 + else + return &shiftwidth + endif + endif + endif + endif + + " Fall back on cindent, which does it mostly right + return cindent(a:lnum) +endfunction diff --git a/bundle/vim-reason/syntax/reason.vim b/bundle/vim-reason/syntax/reason.vim new file mode 100644 index 000000000..1d6a1651a --- /dev/null +++ b/bundle/vim-reason/syntax/reason.vim @@ -0,0 +1,223 @@ +" Vim syntax file +" Language: Reason (Forked from Rust) +" Maintainer: (Jordan - for Reason changes) Patrick Walton +" Maintainer: Ben Blum +" Maintainer: Chris Morgan +" Last Change: January 29, 2015 +" Portions Copyright (c) 2015-present, Facebook, Inc. All rights reserved. + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Syntax definitions {{{1 +" Basic keywords {{{2 +syn keyword reasonConditional try switch if else for while +syn keyword reasonOperator as to downto + +" syn keyword reasonKeyword fun nextgroup=reasonFuncName skipwhite skipempty +syn match reasonAssert "\" +" Polymorphic variants +syn match reasonConstructor "`\w\(\w\|'\)*\>" + +syn match reasonModPath "\<\u\(\w\|'\)* *\."he=e-1 +syn match reasonModPath "\(\\|<\|%\)=\?" +" This one isn't *quite* right, as we could have binary-& with a reference + +" This isn't actually correct; a closure with no arguments can be `|| { }`. +" Last, because the & in && isn't a sigil +syn match reasonOperator display "&&\|||" +" This is reasonArrowCharacter rather than reasonArrow for the sake of matchparen, +" so it skips the ->; see http://stackoverflow.com/a/30309949 for details. +syn match reasonArrowCharacter display "=>" + +syn match reasonEscapeError display contained /\\./ +syn match reasonEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/ +syn match reasonEscapeUnicode display contained /\\\(u\x\{4}\|U\x\{8}\)/ +syn match reasonEscapeUnicode display contained /\\u{\x\{1,6}}/ +syn match reasonStringContinuation display contained /\\\n\s*/ +syn region reasonString start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=reasonEscape,reasonEscapeError,reasonStringContinuation +syn region reasonString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=reasonEscape,reasonEscapeUnicode,reasonEscapeError,reasonStringContinuation,@Spell +syn region reasonString start='b\?r\z(#*\)"' end='"\z1' contains=@Spell + +syn region reasonMultilineString start=+b{|+ skip=+\\\\\|\\"+ end=+|}+ contains=reasonEscape,reasonEscapeError,reasonStringContinuation +syn region reasonMultilineString start=+{|+ end=+|}+ contains=reasonEscape,reasonEscapeUnicode,reasonEscapeError,reasonStringContinuation,@Spell + + +" https://github.com/pangloss/vim-javascript/blob/master/syntax/javascript.vim +" lc=1 means leading context, for "not backslashed" +syntax region reasonTemplateExpression contained matchgroup=reasonTemplateBraces start=+\(^\|[^\\]\)${+lc=1 end=+}+ contains=@interpolation keepend +syntax region reasonTemplateString start=+`\($\| \)+ skip=+\\`+ end=+`+ contains=reasonTemplateExpression,jsSpecial,@Spell extend +syntax match reasonTaggedTemplate /\<\K\k*\ze`/ nextgroup=reasonTemplateString + + +syn region reasonAttribute start="#!\?\[" end="\]" contains=reasonString,reasonDerive +" This list comes from src/libsyntax/ext/deriving/mod.rs +" Some are deprecated (Encodable, Decodable) or to be removed after a new snapshot (Show). + +" Number literals +syn match reasonDecNumber display "\<[0-9][0-9_]*\%([iu]\%(size\|8\|16\|32\|64\)\)\=" +syn match reasonHexNumber display "\<0x[a-fA-F0-9_]\+\%([iu]\%(size\|8\|16\|32\|64\)\)\=" +syn match reasonOctNumber display "\<0o[0-7_]\+\%([iu]\%(size\|8\|16\|32\|64\)\)\=" +syn match reasonBinNumber display "\<0b[01_]\+\%([iu]\%(size\|8\|16\|32\|64\)\)\=" + +" Special case for numbers of the form "1." which are float literals, unless followed by +" an identifier, which makes them integer literals with a method call or field access, +" or by another ".", which makes them integer literals followed by the ".." token. +" (This must go first so the others take precedence.) +syn match reasonFloat display "\<[0-9][0-9_]*\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\|\.\)\@!" +" To mark a number as a normal float, it must have at least one of the three things integral values don't have: +" a decimal point and more numbers; an exponent; and a type suffix. +syn match reasonFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)\=" +syn match reasonFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\(f32\|f64\)\=" +syn match reasonFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)" + +" For the benefit of delimitMate + +syn match reasonCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/ +" The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII). +syn match reasonCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/ +syn match reasonCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=reasonEscape,reasonEscapeError,reasonCharacterInvalid,reasonCharacterInvalidUnicode +syn match reasonCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\|u{\x\{1,6}}\)\)'/ contains=reasonEscape,reasonEscapeUnicode,reasonEscapeError,reasonCharacterInvalid + +syn match reasonShebang /\%^#![^[].*/ +syn region reasonCommentLine start="//" end="$" contains=reasonTodo,@Spell +" syn region reasonCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=reasonTodo,@Spell +syn region reasonCommentBlock matchgroup=reasonCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=reasonTodo,reasonCommentBlockNest,@Spell +syn region reasonCommentBlockDoc matchgroup=reasonCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=reasonTodo,reasonCommentBlockDocNest,@Spell +syn region reasonCommentBlockNest matchgroup=reasonCommentBlock start="/\*" end="\*/" contains=reasonTodo,reasonCommentBlockNest,@Spell contained transparent +syn region reasonCommentBlockDocNest matchgroup=reasonCommentBlockDoc start="/\*" end="\*/" contains=reasonTodo,reasonCommentBlockDocNest,@Spell contained transparent +" FIXME: this is a really ugly and not fully correct implementation. Most +" importantly, a case like ``/* */*`` should have the final ``*`` not being in +" a comment, but in practice at present it leaves comments open two levels +" deep. But as long as you stay away from that particular case, I *believe* +" the highlighting is correct. Due to the way Vim's syntax engine works +" (greedy for start matches, unlike Zust's tokeniser which is searching for +" the earliest-starting match, start or end), I believe this cannot be solved. +" Oh you who would fix it, don't bother with things like duplicating the Block +" rules and putting ``\*\@ +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + + +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +setlocal nolisp + +setlocal indentexpr=RescriptIndent(v:lnum) + +if exists('*RescriptIndent') + finish +endif + +function! s:SkipRescriptBlanksAndComments(startline) + let lnum = a:startline + while lnum > 1 + let lnum = prevnonblank(lnum) + if getline(lnum) =~# '\*/\s*$' + while getline(lnum) !~ '/\*' && lnum > 1 + let lnum = lnum - 1 + endwhile + if getline(lnum) =~# '^\s*/\*' + let lnum = lnum - 1 + else + break + endif + elseif getline(lnum) =~# '^\s*//' + let lnum = lnum - 1 + else + break + endif + endwhile + return lnum +endfunction + +function! RescriptIndent(lnum) + let l:prevlnum = s:SkipRescriptBlanksAndComments(a:lnum-1) + if l:prevlnum == 0 " We're at top of file + return 0 + endif + + " Prev and current line with line-comments removed + let l:prevl = substitute(getline(l:prevlnum), '//.*$', '', '') + let l:thisl = substitute(getline(a:lnum), '//.*$', '', '') + let l:previ = indent(l:prevlnum) + + let l:ind = l:previ + + if l:prevl =~# '\v(\(|\{|\[|\=|\=\>)\s*$' + " Opened a block, assignment, fat arrow + let l:ind += shiftwidth() + endif + + if l:thisl =~# '^\s*[)}\]]' + " Closed a blocked + let l:ind -= shiftwidth() + endif + + return l:ind +endfunction diff --git a/bundle/vim-rescript/syntax/rescript.vim b/bundle/vim-rescript/syntax/rescript.vim new file mode 100644 index 000000000..1aa1aa8f2 --- /dev/null +++ b/bundle/vim-rescript/syntax/rescript.vim @@ -0,0 +1,111 @@ +if exists('b:current_syntax') + finish +endif + +" See https://github.com/rescript-lang/vim-rescript/issues/14 +syntax sync minlines=600 + +" Boolean +syntax keyword resBoolean true false + +" Keywords +syntax keyword resKeyword let rec type external mutable lazy private of with +syntax keyword resKeyword if else switch when +syntax keyword resKeyword and as open include module in constraint import export +syntax keyword resKeyword for to downto while +syntax keyword resKeyword try catch exception assert + +" Types +syntax keyword resType bool int float char string unit +syntax keyword resType list array option ref exn format + +" Operators +syntax keyword resOperator mod land lor lxor lsl lsr asr +syntax keyword resOperator or + +syntax match resOperator "\v\=" + +syntax match resOperator "\v\*" +syntax match resOperator "\v/" +syntax match resOperator "\v\+" +syntax match resOperator "\v-" + +syntax match resOperator "\v\*\." +syntax match resOperator "\v/\." +syntax match resOperator "\v\+\." +syntax match resOperator "\v-\." + +syntax match resOperator "\v\<" +syntax match resOperator "\v\<\=" +syntax match resOperator "\v\>" +syntax match resOperator "\v\>\=" + +syntax match resOperator "\v\@" + +syntax match resOperator "\v\!" +syntax match resOperator "\v\|" +syntax match resOperator "\v\&" + +" Refs +syntax match resOperator "\v\:\=" + +" Arrows / Pipes +syntax match resArrowPipe "\v\=\>" +syntax match resArrowPipe "\v\-\>" +syntax match resArrowPipe "\v\|\>" +syntax match resArrowPipe "\v\@\@" + +" Comment +syntax region resSingleLineComment start="//" end="$" contains=resTodo,@Spell +syntax region resMultiLineComment start="/\*\s*" end="\*/" contains=@Spell,resTodo,resMultiLineComment + +syntax keyword resTodo contained TODO FIXME XXX NOTE + +" Char +syntax match resChar "\v'\\.'|'.'" + +syntax match resNumber "-\=\<\d\(_\|\d\)*[l|L|n]\?\>" +syntax match resNumber "-\=\<0[x|X]\(\x\|_\)\+[l|L|n]\?\>" +syntax match resNumber "-\=\<0[o|O]\(\o\|_\)\+[l|L|n]\?\>" +syntax match resNumber "-\=\<0[b|B]\([01]\|_\)\+[l|L|n]\?\>" +syntax match resFloat "-\=\<\d\(_\|\d\)*\.\?\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" + +" Module / Constructor +syntax match resModuleOrVariant "\v<[A-Z][A-Za-z0-9_'$]*" +syntax match resPolyVariant "\v#[A-za-z][A-Za-z0-9_'$]*" +syntax match resModuleChain "\v<[A-Z][A-Za-z0-9_'$]*\." + +" Attribute +syntax match resAttribute "\v\@([a-zA-z][A-Za-z0-9_']*)(\.([a-zA-z])[A-Za-z0-9_']*)*" + +" String +syntax match resUnicodeChar "\v\\u[A-Fa-f0-9]\{4}" contained +syntax match resEscapedChar "\v\\[\\"'ntbrf]" contained +syntax region resString start="\v\"" end="\v\"" contains=resEscapedQuote,resEscapedChar,resUnicodeChar + +syntax match resInterpolationVariable "\v\$[a-z_][A-Za-z0-0_'$]*" contained +syntax region resString start="\v`" end="\v`" contains=resInterpolationVariable +syntax region resString start="\v[a-z]`" end="\v`" contains=resInterpolationVariable + + +highlight default link resBoolean Boolean +highlight default link resKeyword Keyword +highlight default link resType Type +highlight default link resOperator Operator +highlight default link resArrowPipe Operator +highlight default link resSingleLineComment Comment +highlight default link resMultiLineComment Comment +highlight default link resTodo TODO +highlight default link resChar Character +highlight default link resNumber Number +highlight default link resFloat Float +highlight default link resModuleOrVariant Function +highlight default link resPolyVariant Function +highlight default link resModuleChain Macro +highlight default link resUnicodeChar Character +highlight default link resEscapedChar Character +highlight default link resString String +highlight default link resInterpolationVariable Macro +highlight default link resAttribute PreProc + +let b:current_syntax = 'rescript' diff --git a/docs/cn/layers/language-server-protocol.md b/docs/cn/layers/language-server-protocol.md index c26bd6d8c..7814f93e8 100644 --- a/docs/cn/layers/language-server-protocol.md +++ b/docs/cn/layers/language-server-protocol.md @@ -146,6 +146,7 @@ gem install solargraph | `purescript` | `['purescript-language-server', '--stdio']` | | `python` | `['pyls']` | | `ruby` | `['solargraph', 'stdio']` +| `reason` | `['ocaml-language-server']` | | `rust` | `['rustup', 'run', 'nightly', 'rls']` | | `sh` | `['bash-language-server', 'start']` | | `typescript` | `['typescript-language-server', '--stdio']` | diff --git a/docs/layers.md b/docs/layers.md index 0033fe82d..26a66bc50 100644 --- a/docs/layers.md +++ b/docs/layers.md @@ -71,7 +71,7 @@ Some layers are enabled by default. The following example shows how to disable ` | [checkers](checkers/) | Syntax checking automatically within SpaceVim, display error on the sign column and statusline. | | [chinese](chinese/) | Layer for chinese users, include chinese docs and runtime messages | | [colorscheme](colorscheme/) | colorscheme provides a list of colorscheme for SpaceVim, default colorscheme is gruvbox with dark theme. | -| [core#banner](core/banner/) | This layer provides many default banner on welcome page. | +| [core#banner](core/banner/) | This layer provides many default banners on welcome page. | | [core#statusline](core/statusline/) | This layer provides default statusline for SpaceVim | | [core#tabline](core/tabline/) | SpaceVim core#tabline layer provides a better tabline for SpaceVim | | [core](core/) | SpaceVim core layer provides many default key bindings and features. | @@ -88,7 +88,7 @@ Some layers are enabled by default. The following example shows how to disable ` | [fzf](fzf/) | This layers provide a heavily customized fzf centric work-flow | | [git](git/) | This layers adds extensive support for git | | [github](github/) | This layer provides GitHub integration for SpaceVim | -| [gtags](gtags/) | This layer provide gtags manager for project | +| [gtags](gtags/) | This layer provides gtags manager for project | | [japanese](japanese/) | Layer for japanese users, include japanese docs and runtime messages | | [lang#WebAssembly](lang/WebAssembly/) | This layer adds WebAssembly support to SpaceVim | | [lang#actionscript](lang/actionscript/) | This layer is for actionscript syntax highlighting | @@ -135,7 +135,7 @@ Some layers are enabled by default. The following example shows how to disable ` | [lang#kotlin](lang/kotlin/) | This layer adds Kotlin language support to SpaceVim, including syntax highlighting, code runner and REPL support. | | [lang#lasso](lang/lasso/) | Lasso language support, include syntax highlighting. | | [lang#latex](lang/latex/) | This layer provides support for writing LaTeX documents, including syntax highlighting, code completion, formatting etc. | -| [lang#lisp](lang/lisp/) | This layer is for Lisp development, provide autocompletion, syntax checking, code format for Lisp file. | +| [lang#lisp](lang/lisp/) | This layer is for Common Lisp development, provide autocompletion, syntax checking, code format for Common Lisp file. | | [lang#livescript](lang/livescript/) | This layer is for livescript development, provide syntax checking, code runner and repl support for livescript file. | | [lang#lua](lang/lua/) | This layer is for Lua development, provide autocompletion, syntax checking, code format for Lua file. | | [lang#markdown](lang/markdown/) | Edit markdown within vim, autopreview markdown in the default browser, with this layer you can also format markdown file. | @@ -159,8 +159,11 @@ Some layers are enabled by default. The following example shows how to disable ` | [lang#python](lang/python/) | This layer is for Python development, provide autocompletion, syntax checking, code format for Python file. | | [lang#r](lang/r/) | This layer is for R development, provide autocompletion, syntax checking and code format. | | [lang#racket](lang/racket/) | This layer adds racket language support to SpaceVim, including syntax highlighting, code runner and REPL support. | +| [lang#reason](lang/reason/) | This layer is for reason development, provide syntax checking, code runner and repl support for reason file. | | [lang#red](lang/red/) | This layer is for Red development, provide autocompletion, syntax checking and code format. | +| [lang#rescript](lang/rescript/) | This layer is for ReScript development, provide syntax checking, code runner and repl support for ReScript file. | | [lang#ring](lang/ring/) | This layer is for ring development, provide syntax checking, code runner and repl support for ring file. | +| [lang#rst](lang/rst/) | Take Notes in reStructuredText, autopreview in the default browser. | | [lang#ruby](lang/ruby/) | This layer is for Ruby development, provide autocompletion, syntax checking, code format for Ruby file. | | [lang#rust](lang/rust/) | This layer is for Rust development, provide autocompletion, syntax checking, code format for Rust file. | | [lang#scala](lang/scala/) | This layer adds Scala language support to SpaceVim | @@ -174,7 +177,7 @@ Some layers are enabled by default. The following example shows how to disable ` | [lang#typescript](lang/typescript/) | This layer is for TypeScript development, includding code completion, Syntax lint, and doc generation. | | [lang#v](lang/v/) | This layer is for v development, provide syntax checking, code runner and repl support for v file. | | [lang#vbnet](lang/vbnet/) | This layer is for Visual Basic .NET development, provide code runner vb file. | -| [lang#vim](lang/vim/) | This layer is for writing Vimscript, including code completion, syntax checking and buffer formatting | +| [lang#vim](lang/vim/) | This layer is for writing Vimscript, including code completion, syntax checking and buffer formatting | | [lang#vue](lang/vue/) | This layer adds Vue language support to SpaceVim | | [lang#wolfram](lang/wolfram/) | This layer is for wolfram development, provide syntax checking, code runner and repl support for wolfram file. | | [lang#xml](lang/xml/) | This layer is for xml development, provide syntax checking, indent etc. | diff --git a/docs/layers/core/banner.md b/docs/layers/core/banner.md index 91d1baaf4..f446f66d1 100644 --- a/docs/layers/core/banner.md +++ b/docs/layers/core/banner.md @@ -1,6 +1,6 @@ --- title: "SpaceVim core#banner layer" -description: "This layer provides many default banners on welcome page." +description: "This layer provides many default banner on welcome page." --- # [Available Layers](../) >> core#banner diff --git a/docs/layers/lang/reason.md b/docs/layers/lang/reason.md new file mode 100644 index 000000000..c8b5f0cb2 --- /dev/null +++ b/docs/layers/lang/reason.md @@ -0,0 +1,53 @@ +--- +title: "SpaceVim lang#reason layer" +description: "This layer is for reason development, provide syntax checking, code runner and repl support for reason file." +--- + +# [Available Layers](../../) >> lang#reason + + + +- [Description](#description) +- [Install](#install) +- [Features](#features) +- [Key bindings](#key-bindings) + + + +## Description + +This layer is for [reason](http://reasonml.github.io/) development. + +## Install + +To use this configuration layer, update custom configuration file with: + +```toml +[[layers]] + name = "lang#reason" +``` + +## Features + +- syntax highlighting +- esy tasks detection + +## Key bindings + +The following key bindings are reason language specific key binding, only available when editing +reason file. + +| Key binding | Description | +| --------------- | --------------- | +| `K` / `SPC l d` | Show cursor doc | +| `SPC l e` | Rename symbol | + +**NOTE:** These key bindings require `lsp` layer loaded: + +```toml +[[layers]] + name = "lsp" + filetypes = [ + "reason" + ] +``` diff --git a/docs/layers/lang/rescript.md b/docs/layers/lang/rescript.md new file mode 100644 index 000000000..082833374 --- /dev/null +++ b/docs/layers/lang/rescript.md @@ -0,0 +1,39 @@ +--- +title: "SpaceVim lang#rescript layer" +description: "This layer is for ReScript development, provide syntax checking, code runner and repl support for ReScript file." +--- + +# [Available Layers](../../) >> lang#rescript + + + +- [Description](#description) +- [Install](#install) +- [Features](#features) +- [Key bindings](#key-bindings) + + + +## Description + +This layer is for [ReScript](https://rescript-lang.org/) development. + +## Install + +To use this configuration layer, update custom configuration file with: + +```toml +[[layers]] + name = "lang#rescript" +``` + +## Features + +- syntax highlighting +- tasks detection + +## Key bindings + +| Key binding | Description | +| ----------- | -------------- | +| `SPC p t l` | list all tasks | diff --git a/docs/layers/language-server-protocol.md b/docs/layers/language-server-protocol.md index c86c479e8..591a6a87f 100644 --- a/docs/layers/language-server-protocol.md +++ b/docs/layers/language-server-protocol.md @@ -155,7 +155,7 @@ default language server commands: | language | server command | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `ada` | `['ada_language_server']` | +| `ada` | `['ada_language_server']` | | `c` | `['clangd']` | | `cpp` | `['clangd']` | | `crystal` | `['scry']` | @@ -173,6 +173,7 @@ default language server commands: | `purescript` | `['purescript-language-server', '--stdio']` | | `python` | `['pyls']` | | `ruby` | `['solargraph', 'stdio']` | +| `reason` | `['ocaml-language-server']` | | `rust` | `['rustup', 'run', 'nightly', 'rls']` | | `sh` | `['bash-language-server', 'start']` | | `typescript` | `['typescript-language-server', '--stdio']` | diff --git a/wiki/en/programming-languages.md b/wiki/en/programming-languages.md index 7a3f9ae0a..1090890ce 100644 --- a/wiki/en/programming-languages.md +++ b/wiki/en/programming-languages.md @@ -74,6 +74,8 @@ This is a list of programming languages supported in SpaceVim: | Red | [lang#red](https://spacevim.org/layers/lang/red/) | | | Ring | [lang#ring](https://spacevim.org/layers/lang/ring) | | | Ruby | [lang#ruby](https://spacevim.org/layers/lang/ruby/) | | +| Reason | [lang#ruby](https://spacevim.org/layers/lang/reason/) | | +| ReScript | [lang#ruby](https://spacevim.org/layers/lang/rescript/) | | | Rust | [lang#rust](https://spacevim.org/layers/lang/rust/) | | | Scala | [lang#scala](https://spacevim.org/layers/lang/scala/) | | | Scheme | [lang#scheme](https://spacevim.org/layers/lang/scheme/) | |