This commit is contained in:
baabelfish 2016-02-04 02:58:03 +02:00
commit dc2615545a
9 changed files with 269 additions and 51 deletions

View file

@ -42,14 +42,17 @@ Nim support for Neovim
- [x] NimRenameSymbol - [x] NimRenameSymbol
- [ ] NimRenameSymbolProject - [ ] NimRenameSymbolProject
- [ ] Misc
- [ ] Airline integration
- [ ] IDE features - [ ] IDE features
- [x] Neomake - [x] Neomake
- [x] View online documentation
- [x] Outline with a proper tagbar
- [ ] Search and view online documentation - [ ] Search and view online documentation
- [ ] Usages with unite - [ ] Usages with unite
- [ ] Outline with unite - [ ] Outline with unite
- [ ] Outline with a proper tagbar
- [ ] Parse proc parameter types for parameter completion - [ ] Parse proc parameter types for parameter completion
- [ ] Airline integration
- [ ] When lines are added or removed use cached highlighter results - [ ] When lines are added or removed use cached highlighter results
- [ ] When editing line, remove highlighter results from that line - [ ] When editing line, remove highlighter results from that line
@ -122,8 +125,6 @@ Nim support for Neovim
## v0.2 ## v0.2
## v0.3 ## v0.3
## v0.1
## v0.1
# TASKS # TASKS

View file

@ -6,12 +6,23 @@ let s:loaded = 1
let s:InfoImpl = {} let s:InfoImpl = {}
function! s:New(useWeb)
let result = copy(s:InfoImpl)
let result.useWeb = a:useWeb
return result
endfunction
function! s:InfoImpl.run(data) function! s:InfoImpl.run(data)
if len(a:data.lines) == 0 if len(a:data.lines) == 0
echo "No information found" echo "No information found"
else return
let res = util#ParseV1(a:data.lines[0]) endif
let res = util#ParseV1(a:data.lines[0])
if self.useWeb
call util#open_module_doc(res.location, res.lname)
else
echohl None echohl None
echohl Function | echon res.lname echohl Function | echon res.lname
echohl Comment | echon "\n » " echohl Comment | echon "\n » "
@ -37,6 +48,11 @@ function! s:InfoImpl.run(data)
endfunction endfunction
function! features#info#run() function! features#info#web()
call suggest#New("def", 0, 0, s:InfoImpl) call suggest#New("def", 1, 0, s:New(1))
endfunction
function! features#info#run()
call suggest#New("def", 1, 0, s:New(0))
endfunction endfunction

View file

@ -3,33 +3,193 @@ if exists("s:loaded")
endif endif
let s:loaded = 1 let s:loaded = 1
function! features#outline#renderable(parsed)
return {
\ 'line': a:parsed.line,
\ 'col': a:parsed.col,
\ 'name': a:parsed.lname,
\ 'kind': a:parsed.kind }
endfunction
let s:OutlineImpl = { let s:window = -1
\ 'pty': 1, let s:goto_table = {}
let s:groups = {}
let s:group_order = ["Types", "Callables", "Constants", "Globals", "Imports"]
let s:symbols = {
\ 'skProc': "proc",
\ 'skTemplate': "template",
\ 'skType': "",
\ 'skMacro': "macro",
\ 'skMethod': "function",
\ 'skField': "field",
\ 'skAlias': "alias",
\ 'skConst': "constant",
\ 'skConverter': "converter",
\ 'skDynLib': "dynlib",
\ 'skEnumField': "enum",
\ 'skGlobalVar': "var",
\ 'skGlobalLet': "let",
\ 'skIterator': "iterator",
\ 'skLabel': "label",
\ 'skLet': "constant",
\ 'skModule': "module",
\ 'skPackage': "package",
\ } \ }
function! s:OutlineImpl.run(data) " \ 'skField': "Fields",
for line in a:data.lines let s:group_aliases = {
if len(line) == 0 \ 'skType': "Types",
\ 'skProc': "Callables",
\ 'skTemplate': "Callables",
\ 'skMacro': "Callables",
\ 'skMethod': "Callables",
\ 'skConverter': "Callables",
\ 'skIterator': "Callables",
\ 'skConst': "Constants",
\ 'skLet': "Constants",
\ 'skGlobalVar': "Globals",
\ 'skGlobalLet': "Globals",
\ 'skDynLib': "Imports",
\ 'skModule': "Imports",
\ 'skPackage': "Imports",
\ }
function! s:CreateSymbolRow(symbol)
let result = " » " . a:symbol.name
if len(s:symbols[a:symbol.kind]) > 0
let result .= " (" . s:symbols[a:symbol.kind] . ")"
endif
return result
endfunction
function! s:ConfigureOutlineBuffer()
if s:IsOpen()
return
endif
let s:window = winnr()
vsplit __nim_outline__
setlocal filetype=nimoutline
setlocal buftype=nofile
setlocal nonumber
setlocal nowrap
nnoremap <buffer><silent> <return> :call features#outline#JumpToSymbol(0)<cr>
nnoremap <buffer><silent> o :call features#outline#JumpToSymbol(1)<cr>
endfunction
function! features#outline#JumpToSymbol(stay)
if !s:IsFocused()
return
endif
let l = line(".")
if !has_key(s:goto_table, l)
return
endif
let [jl, jc] = s:goto_table[l]
call util#JumpToWindow(s:window, jl, jc)
normal! ^
if a:stay
normal! zt
wincmd p
endif
endfunction
function! s:UpdateOutline(groups)
let s:goto_table = {}
let s:groups = a:groups
call s:ConfigureOutlineBuffer()
call s:RenderOutline()
endfunction
function! s:RenderOutline()
let wasFocused = s:IsFocused()
call s:Focus()
if !s:IsFocused()
return
endif
exec "silent vertical resize " . g:nvim_nim_outline_buffer_width
let rlines = []
for groupname in s:group_order
if len(s:groups[groupname]) == 0
continue continue
endif endif
let [_, node, fullname, type, filename, line, column, doc, random] = split(line, " ")
let name = join(split(fullname, "\\.")[1:], ".") call add(rlines, groupname)
call setqflist([{
\ 'filename': filename, for symbol in s:groups[groupname]
\ 'lnum': line, let s:goto_table[len(rlines) + 1] = [symbol.line, symbol.col]
\ 'col': column + 1, call add(rlines, s:CreateSymbolRow(symbol))
\ 'text': node . " : " . name }], endfor
\ 'a') call add(rlines, "")
endfor endfor
copen
nnoremap <buffer><silent> <return> :call util#JumpFromQuickfix(0)<cr> let idx = 1
nnoremap <buffer><silent> o :call util#JumpFromQuickfix(1)<cr> for line in rlines
call setline(idx, line)
let idx += 1
endfor
exec ":" . len(rlines)
normal! dG
if !wasFocused
wincmd p
endif
endfunction endfunction
function! features#outline#run() function! s:Window()
cclose return bufwinnr("__nim_outline__")
call setqflist([]) endfunction
call suggest#New("outline", 0, 1, s:OutlineImpl)
function! s:IsOpen()
return s:Window() != -1
endfunction
function! s:IsFocused()
return s:IsOpen() && s:Window() == winnr()
endfunction
function! s:Focus()
if s:IsOpen()
exec ":" . s:Window() . "wincmd w"
endif
endfunction
function! features#outline#render()
call s:RenderOutline()
endfunction
let s:OutlineImpl = {}
function! s:OutlineImpl.run(data)
let s:groups = {
\ "Types": [],
\ "Callables": [],
\ "Fields": [],
\ "Constants": [],
\ "Globals": [],
\ "Imports": [],
\ }
for line in a:data.lines
let p = util#ParseV2(line)
if has_key(s:group_aliases, p.kind)
let renderable = features#outline#renderable(p)
call add(s:groups[s:group_aliases[p.kind]], renderable)
endif
endfor
call s:UpdateOutline(s:groups)
endfunction
function! features#outline#run(isUpdating)
if !a:isUpdating || s:IsOpen()
call suggest#New("outline", 1, 1, s:OutlineImpl)
endif
endfunction endfunction

View file

@ -53,6 +53,13 @@ function! util#CheckDependency(command)
endfunction endfunction
function! util#JumpToWindow(window, line, col)
execute ":" . a:window . "wincmd w"
execute ":" . a:line
execute ":norm " . (a:col) . "|"
endfunction
function! util#JumpToLocation(file, line, col) function! util#JumpToLocation(file, line, col)
if expand("%:p") != a:file if expand("%:p") != a:file
execute ":e " . a:file execute ":e " . a:file
@ -195,3 +202,7 @@ function! util#djb(str)
endfor endfor
return float2nr(hash) return float2nr(hash)
endfunction endfunction
function! util#open_module_doc(module, symbol)
call system("$BROWSER " . "http://nim-lang.org/docs/" . a:module . ".html#" . a:symbol)
endfunction

View file

@ -14,4 +14,7 @@ let g:nvim_nim_highlight_use_unite = 0
let g:nvim_nim_autocomplete = "omni" " omni, deoplete, ycm let g:nvim_nim_autocomplete = "omni" " omni, deoplete, ycm
let g:nvim_nim_outline = "quickfix" " quickfix, outline let g:nvim_nim_outline = "quickfix" " quickfix, outline
let g:nvim_nim_outline_buffer = 1
let g:nvim_nim_outline_buffer_width = 30
let g:nvim_nim_highlighter_semantics = ["skConst", "skForVar", "skGlobalVar", "skGlobalLet", "skLet", "skModule", "skParam", "skTemp", "skVar"] let g:nvim_nim_highlighter_semantics = ["skConst", "skForVar", "skGlobalVar", "skGlobalLet", "skLet", "skModule", "skParam", "skTemp", "skVar"]

View file

@ -1,6 +1,6 @@
" if exists("b:loaded") if exists("b:loaded")
" finish finish
" endif endif
let b:loaded = 1 let b:loaded = 1
setlocal formatoptions-=t formatoptions+=l setlocal formatoptions-=t formatoptions+=l
@ -11,31 +11,30 @@ setlocal omnifunc=omni#nim
command! NimDefinition :call features#definition#run() command! NimDefinition :call features#definition#run()
command! NimInfo :call features#info#run() command! NimInfo :call features#info#run()
command! NimWeb :call features#info#web()
command! NimUsages :call features#usages#run(0) command! NimUsages :call features#usages#run(0)
command! NimUsagesProject :call features#usages#run(1) command! NimUsagesProject :call features#usages#run(1)
command! NimRenameSymbol :call features#rename#run(0) command! NimRenameSymbol :call features#rename#run(0)
command! NimRenameSymbolProject :call features#rename#run(1) command! NimRenameSymbolProject :call features#rename#run(1)
command! NimDebug :call features#debug#run() command! NimDebug :call features#debug#run()
command! NimOutline :call features#outline#run() command! NimOutline :call features#outline#run(0)
command! NimEdb :call features#debugger#run() command! NimEdb :call features#debugger#run()
command! NimEdbStop :call features#debugger#stop() command! NimEdbStop :call features#debugger#stop()
command! NimEdbContinue :call features#debugger#continue() command! NimEdbContinue :call features#debugger#continue()
command! NimEdbStepInto :call features#debugger#stepinto() command! NimEdbStepInto :call features#debugger#stepinto()
command! NimEdbStepOver :call features#debugger#stepover() command! NimEdbStepOver :call features#debugger#stepover()
command! NimEdbSkipCurrent :call features#debugger#skipcurrent() command! NimEdbSkipCurrent :call features#debugger#skipcurrent()
command! NimEdbIgonore :call features#debugger#ignore() command! NimEdbIgonore :call features#debugger#ignore()
command! NimEdbContinue :call features#debugger#continue() command! NimEdbContinue :call features#debugger#continue()
command! NimEdbToggleBP :call features#debugger#togglebp() command! NimEdbToggleBP :call features#debugger#togglebp()
nnoremap <buffer> <c-]> :NimDefinition<cr> nnoremap <buffer> <c-]> :NimDefinition<cr>
nnoremap <buffer> gd :NimDefinition<cr> nnoremap <buffer> gd :NimDefinition<cr>
nnoremap <buffer> gt :NimInfo<cr> nnoremap <buffer> gt :NimInfo<cr>
nnoremap <buffer> gT :NimInfoVerbose<cr> nnoremap <buffer> gT :NimWeb<cr>
autocmd! CursorHold,InsertLeave,TextChanged,InsertEnter *.nim call highlighter#guard()
autocmd! BufReadPost,BufWritePost *.nim call highlighter#guard()
" autocmd! BufWinEnter quickfix let g:qfix_win = bufnr("$")
" autocmd! BufWinLeave * if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win | call features#usages#clear_matches() | unlet! g:qfix_win | endif
autocmd! BufReadPost,BufWritePost,CursorHold,InsertLeave,TextChanged,InsertEnter *.nim call highlighter#guard()
autocmd! BufWinEnter,BufWritePost,FileWritePost *.nim call features#outline#run(1)
autocmd! VimResized,WinEnter * call features#outline#render()
call highlighter#guard() call highlighter#guard()

BIN
other/pic1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View file

@ -3,8 +3,6 @@
" 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")
let g:nvim_nim_exec_nimsuggest = util#CheckDependency("nimsuggest") let g:nvim_nim_exec_nimsuggest = util#CheckDependency("nimsuggest")

30
syntax/nimoutline.vim Normal file
View file

@ -0,0 +1,30 @@
syntax keyword nimoTypes Types
syntax keyword nimoCallables Callables
syntax keyword nimoConstants Constants
syntax keyword nimoGlobals Globals
syntax keyword nimoImports Imports
syntax match nimoSeparator "[»()<>\[\]]"
syntax match nimoDetail "(\(\w\+\))"
hi link nimoConstants Constant
hi link nimoConverters Function
hi link nimoFields Type
hi link nimoGlobals Constant
hi link nimoInclude Include
hi link nimoIterators Function
hi link nimoMacros Macro
hi link nimoMethods Function
hi link nimoModules Include
hi link nimoPackages Include
hi link nimoProcs Function
hi link nimoTemplates Function
hi link nimoTypes Type
hi link nimoSeparator Comment
hi link nimoTypes Type
hi link nimoCallables Function
hi link nimoConstants Constant
hi link nimoGlobals Identifier
hi link nimoImports Include
hi link nimoDetail Identifier