WIP
This commit is contained in:
parent
d07c351677
commit
d8d84209c6
7 changed files with 142 additions and 44 deletions
10
README.md
10
README.md
|
|
@ -13,12 +13,11 @@ Nim support for Neovim
|
||||||
- [x] Operator precedence different colors
|
- [x] Operator precedence different colors
|
||||||
- [x] Numbers
|
- [x] Numbers
|
||||||
- [x] String
|
- [x] String
|
||||||
|
- [x] Highlight variable names semantically
|
||||||
- [ ] Multiline comments
|
- [ ] Multiline comments
|
||||||
- [ ] Highlight variable names semantically
|
|
||||||
- [ ] Indendation
|
- [ ] Indendation
|
||||||
- [ ] Compiler support
|
- [ ] Compiler support
|
||||||
- [x] Omnicomplete
|
- [ ] Make with nim check
|
||||||
- [ ] Make for errors
|
|
||||||
- [x] Nimsuggest
|
- [x] Nimsuggest
|
||||||
- [x] Usages
|
- [x] Usages
|
||||||
- [x] Jump to definition
|
- [x] Jump to definition
|
||||||
|
|
@ -44,6 +43,11 @@ Nim support for Neovim
|
||||||
- [ ] Parse proc parameter types for parameter completion
|
- [ ] Parse proc parameter types for parameter completion
|
||||||
- [ ] REPL interaction
|
- [ ] REPL interaction
|
||||||
- [ ] Airline integration
|
- [ ] Airline integration
|
||||||
|
- [ ] When lines are added or removed use cached highlighter results
|
||||||
|
- [ ] When editing line, remove highlighter results from that line
|
||||||
|
- [ ] Utils
|
||||||
|
- [x] Parse proc/template/method type information
|
||||||
|
- [x] "Haskellify" typesignatures
|
||||||
- [ ] Add tests
|
- [ ] Add tests
|
||||||
- [x] CI integration
|
- [x] CI integration
|
||||||
- [x] Test nimsuggest for surprises
|
- [x] Test nimsuggest for surprises
|
||||||
|
|
|
||||||
|
|
@ -18,34 +18,35 @@ function! s:NimHighlighter.on_exit()
|
||||||
if empty(self.lines) && self.file != expand("%:p")
|
if empty(self.lines) && self.file != expand("%:p")
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let highlights = {
|
let highlights = {
|
||||||
\ 'skProc': ["Function", []],
|
\ 'skProc': ["Function", [], 0],
|
||||||
\ 'skTemplate': ["PreProc", []],
|
\ 'skTemplate': ["PreProc", [], 0],
|
||||||
\ 'skType': ["Type", []],
|
\ 'skType': ["Type", [], 0],
|
||||||
\ 'skMacro': ["Macro", []],
|
\ 'skMacro': ["Macro", [], 0],
|
||||||
\ 'skMethod': ["Function", []],
|
\ 'skMethod': ["Function", [], 0],
|
||||||
\ 'skField': ["Identifier", []],
|
\ 'skField': ["Identifier", [], 0],
|
||||||
\ 'skAlias': ["Type", []],
|
\ 'skAlias': ["Type", [], 0],
|
||||||
\ 'skConditional': ["Conditional", []],
|
\ 'skConditional': ["Conditional", [], 0],
|
||||||
\ 'skConst': ["Constant", []],
|
\ 'skConst': ["Constant", [], 1],
|
||||||
\ 'skConverter': ["Function", []],
|
\ 'skConverter': ["Function", [], 0],
|
||||||
\ 'skDynLib': ["Include", []],
|
\ 'skDynLib': ["Include", [], 0],
|
||||||
\ 'skEnumField': ["Identifier", []],
|
\ 'skEnumField': ["Identifier", [], 0],
|
||||||
\ 'skForVar': ["Special", []],
|
\ 'skForVar': ["Special", [], 1],
|
||||||
\ 'skGenericParam': ["Typedef", []],
|
\ 'skGenericParam': ["Typedef", [], 0],
|
||||||
\ 'skGlobalVar': ["Constant", []],
|
\ 'skGlobalVar': ["Constant", [], 1],
|
||||||
\ 'skGlobalLet': ["Constant", []],
|
\ 'skGlobalLet': ["Constant", [], 1],
|
||||||
\ 'skIterator': ["Keyword", []],
|
\ 'skIterator': ["Keyword", [], 0],
|
||||||
\ 'skLabel': ["Identifier", []],
|
\ 'skLabel': ["Identifier", [], 0],
|
||||||
\ 'skLet': ["Constant", []],
|
\ 'skLet': ["Constant", [], 1],
|
||||||
\ 'skModule': ["Include", []],
|
\ 'skModule': ["Include", [], 1],
|
||||||
\ 'skPackage': ["Define", []],
|
\ 'skPackage': ["Define", [], 0],
|
||||||
\ 'skParam': ["Identifier", []],
|
\ 'skParam': ["Identifier", [], 1],
|
||||||
\ 'skResult': ["Keyword", []],
|
\ 'skResult': ["Keyword", [], 0],
|
||||||
\ 'skStub': ["PreCondit", []],
|
\ 'skStub': ["PreCondit", [], 0],
|
||||||
\ 'skTemp': ["Identifier", []],
|
\ 'skTemp': ["Identifier", [], 1],
|
||||||
\ 'skUnknown': ["Error", []],
|
\ 'skUnknown': ["Error", [], 0],
|
||||||
\ 'skVar': ["Constant", []]
|
\ 'skVar': ["Constant", [], 1]
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
for line in self.lines
|
for line in self.lines
|
||||||
|
|
@ -69,7 +70,16 @@ function! s:NimHighlighter.on_exit()
|
||||||
|
|
||||||
let new_highlights = []
|
let new_highlights = []
|
||||||
for [k, v] in items(highlights)
|
for [k, v] in items(highlights)
|
||||||
call add(new_highlights, matchaddpos(v[0], v[1]))
|
if g:nvim_nim_highlighter_semantic && v[2]
|
||||||
|
for pos in v[1]
|
||||||
|
let l = getline(pos[0])
|
||||||
|
let c = pos[1]
|
||||||
|
let class = (char2nr(l[c]) * char2nr(l[c + 1])) % 20
|
||||||
|
call add(new_highlights, matchaddpos("Semantic" . class, [pos]))
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
call add(new_highlights, matchaddpos(v[0], v[1]))
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
for m in b:old_highlights
|
for m in b:old_highlights
|
||||||
|
|
@ -95,7 +105,7 @@ endfunction
|
||||||
|
|
||||||
|
|
||||||
function! highlighter#guard()
|
function! highlighter#guard()
|
||||||
if g:nvim_nim_enable_highlighter
|
if g:nvim_nim_highlighter_enable
|
||||||
if line("$") + 0 < 500
|
if line("$") + 0 < 500
|
||||||
call highlighter#New()
|
call highlighter#New()
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
" if exists("s:loaded")
|
if exists("s:loaded")
|
||||||
" finish
|
finish
|
||||||
" endif
|
endif
|
||||||
" let s:loaded = 1
|
let s:loaded = 1
|
||||||
|
|
||||||
|
|
||||||
function! omni#item(parsed)
|
function! omni#item(parsed)
|
||||||
return {
|
return {
|
||||||
\ 'word': a:parsed.lname,
|
\ 'word': a:parsed.lname,
|
||||||
\ 'menu': a:parsed.module,
|
\ 'kind': a:parsed.kindshort . " » " . util#SignatureStr(a:parsed.type),
|
||||||
\ 'kind': a:parsed.kindshort . " » " . a:parsed.type,
|
|
||||||
\ 'info': a:parsed.doc,
|
\ 'info': a:parsed.doc,
|
||||||
|
\ 'menu': a:parsed.module,
|
||||||
\ }
|
\ }
|
||||||
|
" \ 'kind': a:parsed.kindshort . " » " . a:parsed.type,
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! omni#nim(findstart, base)
|
function! omni#nim(findstart, base)
|
||||||
|
|
|
||||||
|
|
@ -129,3 +129,62 @@ function! util#ParseV2(line)
|
||||||
\ }
|
\ }
|
||||||
return result
|
return result
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
let s:nesting_chars = ['(', '[', '{']
|
||||||
|
let s:unnesting_chars = [')', ']', '}']
|
||||||
|
let s:strip_regex = '\v^\s*(.{-})\s*$'
|
||||||
|
|
||||||
|
function! util#ParseSignature(input)
|
||||||
|
let pstart = stridx(a:input, "(") + 1
|
||||||
|
let pend = strridx(a:input, ")")
|
||||||
|
let parameters = strpart(a:input, pstart, pend - pstart)
|
||||||
|
let parameters_end = len(parameters) - 1
|
||||||
|
|
||||||
|
let depth = 0
|
||||||
|
let tsep = -1
|
||||||
|
let result = {'params': [], 'reval': '' }
|
||||||
|
|
||||||
|
" Parameters
|
||||||
|
let idx = 0
|
||||||
|
for s:char in split(parameters, '\zs')
|
||||||
|
if index(s:nesting_chars, s:char) >= 0
|
||||||
|
let depth += 1
|
||||||
|
elseif index(s:unnesting_chars, s:char) >= 0
|
||||||
|
let depth -= 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if depth == 0
|
||||||
|
if s:char == ':'
|
||||||
|
let tsep = idx
|
||||||
|
elseif s:char == ',' || s:char == ';'
|
||||||
|
call add(result.params, substitute(strpart(parameters, tsep + 1, idx - tsep - 1), s:strip_regex, '\1', ''))
|
||||||
|
let tsep = -1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
let idx += 1
|
||||||
|
endfor
|
||||||
|
|
||||||
|
if tsep != -1
|
||||||
|
call add(result.params, substitute(strpart(parameters, tsep + 1, parameters_end + 1), s:strip_regex, '\1', ''))
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Return value
|
||||||
|
let rstart = stridx(a:input, ":", pend + 1)
|
||||||
|
let rend = stridx(a:input, "{\.", pend + 1)
|
||||||
|
if rstart != -1 && rstart < rend
|
||||||
|
let reval = strpart(a:input, rstart + 1)
|
||||||
|
if rend != -1
|
||||||
|
let reval = strpart(reval, 0, rend - rstart - 1)
|
||||||
|
endif
|
||||||
|
let result.reval = substitute(reval, s:strip_regex, '\1', '')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return result
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! util#SignatureStr(input)
|
||||||
|
let tinfo = util#ParseSignature(a:input)
|
||||||
|
return join(tinfo.params, " -> ") . (tinfo.reval != "" ? (" => " . tinfo.reval) : "")
|
||||||
|
endfunction
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ let s:loaded = 1
|
||||||
au BufNewFile,BufRead *.nim set filetype=nim
|
au BufNewFile,BufRead *.nim set filetype=nim
|
||||||
au BufNewFile,BufRead *.nims set filetype=nims
|
au BufNewFile,BufRead *.nims set filetype=nims
|
||||||
|
|
||||||
let g:nvim_nim_enable_highlighter = 0
|
let g:nvim_nim_highlighter_enable = 1
|
||||||
|
let g:nvim_nim_highlighter_semantic = 1
|
||||||
let g:nvim_nim_enable_async = 1
|
let g:nvim_nim_enable_async = 1
|
||||||
let g:nvim_nim_highlight_builtin = 1
|
let g:nvim_nim_highlight_builtin = 1
|
||||||
let g:nvim_nim_highlight_use_unite = 0
|
let g:nvim_nim_highlight_use_unite = 0
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
if exists("s:loaded")
|
" if exists("s:loaded")
|
||||||
finish
|
" finish
|
||||||
endif
|
" endif
|
||||||
let s:loaded = 1
|
" let s:loaded = 1
|
||||||
|
|
||||||
|
" echom join(util#ParseSignature("proc (dest:string,sep:string; startLen:Natural):string{.moro.}"), " -> ")
|
||||||
|
|
||||||
let g:nvim_nim_exec_nim = util#CheckDependency("nim")
|
let g:nvim_nim_exec_nim = util#CheckDependency("nim")
|
||||||
let g:nvim_nim_exec_nimble = util#CheckDependency("nimble")
|
let g:nvim_nim_exec_nimble = util#CheckDependency("nimble")
|
||||||
|
|
|
||||||
|
|
@ -154,3 +154,26 @@ highlight link nimRepeat Repeat
|
||||||
highlight link nimStorage Structure
|
highlight link nimStorage Structure
|
||||||
highlight link nimStorageClass StorageClass
|
highlight link nimStorageClass StorageClass
|
||||||
highlight link nimTypedef Typedef
|
highlight link nimTypedef Typedef
|
||||||
|
|
||||||
|
if g:nvim_nim_highlighter_semantic
|
||||||
|
hi Semantic0 guifg=#904719 gui=none
|
||||||
|
hi Semantic1 guifg=#44f365 gui=none
|
||||||
|
hi Semantic2 guifg=#503f43 gui=none
|
||||||
|
hi Semantic3 guifg=#c18167 gui=none
|
||||||
|
hi Semantic4 guifg=#688704 gui=none
|
||||||
|
hi Semantic5 guifg=#6b4b77 gui=none
|
||||||
|
hi Semantic6 guifg=#718c07 gui=none
|
||||||
|
hi Semantic7 guifg=#7211cb gui=none
|
||||||
|
hi Semantic8 guifg=#84ec66 gui=none
|
||||||
|
hi Semantic9 guifg=#8f7fc3 gui=none
|
||||||
|
hi Semantic10 guifg=#9dd1db gui=none
|
||||||
|
hi Semantic11 guifg=#b80145 gui=none
|
||||||
|
hi Semantic12 guifg=#c19345 gui=none
|
||||||
|
hi Semantic13 guifg=#ce6723 gui=none
|
||||||
|
hi Semantic14 guifg=#d787c4 gui=none
|
||||||
|
hi Semantic15 guifg=#e20caf gui=none
|
||||||
|
hi Semantic16 guifg=#e59eee gui=none
|
||||||
|
hi Semantic17 guifg=#efd63f gui=none
|
||||||
|
hi Semantic18 guifg=#fcbc89 gui=none
|
||||||
|
hi Semantic19 guifg=#7c78c9 gui=none
|
||||||
|
endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue