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] Numbers
|
||||
- [x] String
|
||||
- [x] Highlight variable names semantically
|
||||
- [ ] Multiline comments
|
||||
- [ ] Highlight variable names semantically
|
||||
- [ ] Indendation
|
||||
- [ ] Compiler support
|
||||
- [x] Omnicomplete
|
||||
- [ ] Make for errors
|
||||
- [ ] Make with nim check
|
||||
- [x] Nimsuggest
|
||||
- [x] Usages
|
||||
- [x] Jump to definition
|
||||
|
|
@ -44,6 +43,11 @@ Nim support for Neovim
|
|||
- [ ] Parse proc parameter types for parameter completion
|
||||
- [ ] REPL interaction
|
||||
- [ ] 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
|
||||
- [x] CI integration
|
||||
- [x] Test nimsuggest for surprises
|
||||
|
|
|
|||
|
|
@ -18,34 +18,35 @@ function! s:NimHighlighter.on_exit()
|
|||
if empty(self.lines) && self.file != expand("%:p")
|
||||
return
|
||||
endif
|
||||
|
||||
let highlights = {
|
||||
\ 'skProc': ["Function", []],
|
||||
\ 'skTemplate': ["PreProc", []],
|
||||
\ 'skType': ["Type", []],
|
||||
\ 'skMacro': ["Macro", []],
|
||||
\ 'skMethod': ["Function", []],
|
||||
\ 'skField': ["Identifier", []],
|
||||
\ 'skAlias': ["Type", []],
|
||||
\ 'skConditional': ["Conditional", []],
|
||||
\ 'skConst': ["Constant", []],
|
||||
\ 'skConverter': ["Function", []],
|
||||
\ 'skDynLib': ["Include", []],
|
||||
\ 'skEnumField': ["Identifier", []],
|
||||
\ 'skForVar': ["Special", []],
|
||||
\ 'skGenericParam': ["Typedef", []],
|
||||
\ 'skGlobalVar': ["Constant", []],
|
||||
\ 'skGlobalLet': ["Constant", []],
|
||||
\ 'skIterator': ["Keyword", []],
|
||||
\ 'skLabel': ["Identifier", []],
|
||||
\ 'skLet': ["Constant", []],
|
||||
\ 'skModule': ["Include", []],
|
||||
\ 'skPackage': ["Define", []],
|
||||
\ 'skParam': ["Identifier", []],
|
||||
\ 'skResult': ["Keyword", []],
|
||||
\ 'skStub': ["PreCondit", []],
|
||||
\ 'skTemp': ["Identifier", []],
|
||||
\ 'skUnknown': ["Error", []],
|
||||
\ 'skVar': ["Constant", []]
|
||||
\ 'skProc': ["Function", [], 0],
|
||||
\ 'skTemplate': ["PreProc", [], 0],
|
||||
\ 'skType': ["Type", [], 0],
|
||||
\ 'skMacro': ["Macro", [], 0],
|
||||
\ 'skMethod': ["Function", [], 0],
|
||||
\ 'skField': ["Identifier", [], 0],
|
||||
\ 'skAlias': ["Type", [], 0],
|
||||
\ 'skConditional': ["Conditional", [], 0],
|
||||
\ 'skConst': ["Constant", [], 1],
|
||||
\ 'skConverter': ["Function", [], 0],
|
||||
\ 'skDynLib': ["Include", [], 0],
|
||||
\ 'skEnumField': ["Identifier", [], 0],
|
||||
\ 'skForVar': ["Special", [], 1],
|
||||
\ 'skGenericParam': ["Typedef", [], 0],
|
||||
\ 'skGlobalVar': ["Constant", [], 1],
|
||||
\ 'skGlobalLet': ["Constant", [], 1],
|
||||
\ 'skIterator': ["Keyword", [], 0],
|
||||
\ 'skLabel': ["Identifier", [], 0],
|
||||
\ 'skLet': ["Constant", [], 1],
|
||||
\ 'skModule': ["Include", [], 1],
|
||||
\ 'skPackage': ["Define", [], 0],
|
||||
\ 'skParam': ["Identifier", [], 1],
|
||||
\ 'skResult': ["Keyword", [], 0],
|
||||
\ 'skStub': ["PreCondit", [], 0],
|
||||
\ 'skTemp': ["Identifier", [], 1],
|
||||
\ 'skUnknown': ["Error", [], 0],
|
||||
\ 'skVar': ["Constant", [], 1]
|
||||
\ }
|
||||
|
||||
for line in self.lines
|
||||
|
|
@ -69,7 +70,16 @@ function! s:NimHighlighter.on_exit()
|
|||
|
||||
let new_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
|
||||
|
||||
for m in b:old_highlights
|
||||
|
|
@ -95,7 +105,7 @@ endfunction
|
|||
|
||||
|
||||
function! highlighter#guard()
|
||||
if g:nvim_nim_enable_highlighter
|
||||
if g:nvim_nim_highlighter_enable
|
||||
if line("$") + 0 < 500
|
||||
call highlighter#New()
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
" if exists("s:loaded")
|
||||
" finish
|
||||
" endif
|
||||
" let s:loaded = 1
|
||||
|
||||
if exists("s:loaded")
|
||||
finish
|
||||
endif
|
||||
let s:loaded = 1
|
||||
|
||||
function! omni#item(parsed)
|
||||
return {
|
||||
\ 'word': a:parsed.lname,
|
||||
\ 'menu': a:parsed.module,
|
||||
\ 'kind': a:parsed.kindshort . " » " . a:parsed.type,
|
||||
\ 'kind': a:parsed.kindshort . " » " . util#SignatureStr(a:parsed.type),
|
||||
\ 'info': a:parsed.doc,
|
||||
\ 'menu': a:parsed.module,
|
||||
\ }
|
||||
" \ 'kind': a:parsed.kindshort . " » " . a:parsed.type,
|
||||
endfunction
|
||||
|
||||
function! omni#nim(findstart, base)
|
||||
|
|
|
|||
|
|
@ -129,3 +129,62 @@ function! util#ParseV2(line)
|
|||
\ }
|
||||
return result
|
||||
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 *.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_highlight_builtin = 1
|
||||
let g:nvim_nim_highlight_use_unite = 0
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
if exists("s:loaded")
|
||||
finish
|
||||
endif
|
||||
let s:loaded = 1
|
||||
" if exists("s:loaded")
|
||||
" finish
|
||||
" endif
|
||||
" 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_nimble = util#CheckDependency("nimble")
|
||||
|
|
|
|||
|
|
@ -154,3 +154,26 @@ highlight link nimRepeat Repeat
|
|||
highlight link nimStorage Structure
|
||||
highlight link nimStorageClass StorageClass
|
||||
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