From 1613b8acabb5bd9ec7186392b2dd9eb55bac3e5b Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 6 Jul 2020 10:52:47 +0300 Subject: [PATCH 01/14] parser#lsp: move sym transforms to dedicated funcs --- autoload/vista/parser/lsp.vim | 47 ++++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 431758d6..1d66358a 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -41,6 +41,23 @@ function! s:IsFileUri(uri) abort return stridx(a:uri, 'file:///') == 0 endfunction +function! s:LspToLocalSymbol(sym, range) + return { + \ 'lnum': a:range.start.line + 1, + \ 'col': a:range.start.character + 1, + \ 'kind': s:Kind2Symbol(a:sym.kind), + \ 'text': a:sym.name, + \ } +endfunction + +function! s:LocalToRawSymbol(sym) + return { + \ 'line': a:sym.lnum, + \ 'kind': a:sym.kind, + \ 'name': a:sym.text, + \ } +endfunction + " The kind field in the result is a number instead of a readable text, we " should transform the number to the symbol text first. function! vista#parser#lsp#KindToSymbol(line, container) abort @@ -49,26 +66,11 @@ function! vista#parser#lsp#KindToSymbol(line, container) abort if has_key(line, 'location') let location = line.location if s:IsFileUri(location.uri) - let lnum = location.range.start.line + 1 - let col = location.range.start.character + 1 - call add(a:container, { - \ 'lnum': lnum, - \ 'col': col, - \ 'kind': s:Kind2Symbol(line.kind), - \ 'text': line.name, - \ }) + call add(a:container, s:LspToLocalSymbol(line, location.range)) endif " DocumentSymbol class elseif has_key(line, 'range') - let range = line.range - let lnum = range.start.line + 1 - let col = range.start.character + 1 - call add(a:container, { - \ 'lnum': lnum, - \ 'col': col, - \ 'kind': s:Kind2Symbol(line.kind), - \ 'text': line.name, - \ }) + call add(a:container, s:LspToLocalSymbol(line, line.range)) if has_key(line, 'children') for child in line.children call vista#parser#lsp#KindToSymbol(child, a:container) @@ -82,20 +84,13 @@ function! vista#parser#lsp#CocSymbols(symbol, container) abort return endif - let raw = { 'line': a:symbol.lnum, 'kind': a:symbol.kind, 'name': a:symbol.text } - call add(g:vista.raw, raw) + call add(g:vista.raw, s:LocalToRawSymbol(a:symbol)) if a:symbol.kind ==? 'Method' || a:symbol.kind ==? 'Function' call add(g:vista.functions, a:symbol) endif - call add(a:container, { - \ 'lnum': a:symbol.lnum, - \ 'col': a:symbol.col, - \ 'text': a:symbol.text, - \ 'kind': a:symbol.kind, - \ 'level': a:symbol.level - \ }) + call add(a:container, copy(a:symbol)) endfunction " https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol From c10565d7174b6e61e97cf6ad5670b0b9e890efd3 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 6 Jul 2020 10:56:07 +0300 Subject: [PATCH 02/14] parser#lsp: add documentSymbol payload parser utils Based on CoC data model --- autoload/vista/parser/lsp.vim | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 1d66358a..6a920b2e 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -79,6 +79,76 @@ function! vista#parser#lsp#KindToSymbol(line, container) abort endif endfunction +function! s:IsDocumentSymbol(sym) + return has_key(a:sym, 'selectionRange') +endfunction + +function! s:ParseSymbolInfoList(outlist, symbols) abort + for lspsym in a:symbols + let l:loc = lspsym.location + if s:IsFileUri(l:loc.uri) + call add(a:outlist, s:LspToLocalSymbol(lspsym, l:loc.range)) + endif + endfor +endfunction + +function! s:ParseDocumentSymbolsRec(outlist, symbols, level) abort + for lspsym in a:symbols + let l:sym = s:LspToLocalSymbol(lspsym, lspsym.selectionRange) + let l:sym.level = a:level + call add(a:outlist, l:sym) + if has_key(lspsym, 'children') + call s:ParseDocumentSymbolsRec(a:outlist, lspsym.children, a:level + 1) + endif + endfor +endfunction + +function! s:GroupSymbolsByKind(symbols) abort + let l:groups = {} + for l:sym in a:symbols + let l:list = get(l:groups, l:sym.kind) + if !has_key(l:groups, l:sym.kind) + let l:list = [] + let l:groups[l:sym.kind] = l:list + endif + call add(l:list, l:sym) + endfor + return l:groups +endfunction + +function! vista#parser#lsp#ParseDocumentSymbolPayload(resp) abort + let l:symbols = [] + if s:IsDocumentSymbol(a:resp[0]) + call s:ParseDocumentSymbolsRec(l:symbols, a:resp, 0) + call vista#parser#lsp#FilterDocumentSymbols(l:symbols) + call vista#parser#lsp#DispatchDocumentSymbols(l:symbols) + return l:symbols + else + call s:ParseSymbolInfoList(l:symbols, a:resp) + call vista#parser#lsp#FilterDocumentSymbols(l:symbols) + return s:GroupSymbolsByKind(l:symbols) + endif +endfunction + +function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort + let l:symlist = a:symbols + if exists('g:vista_ignore_kinds') + call filter(l:symlist, 'index(g:vista_ignore_kinds, v:val) < 0') + endif + let g:vista.functions = [] + for l:sym in l:symlist + if l:sym.kind ==? 'Method' || l:sym.kind ==? 'Function' + call add(g:vista.functions, l:sym) + endif + endfor + return l:symlist +endfunction + +function! vista#parser#lsp#DispatchDocumentSymbols(symbols) + let g:vista.raw = map(copy(a:symbols), { _, sym -> s:LocalToRawSymbol(sym) }) + return g:vista.raw +endfunction + function! vista#parser#lsp#CocSymbols(symbol, container) abort if vista#ShouldIgnore(a:symbol.kind) return From c2145fc6c014b8eb35af57b01483e318a977637b Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 6 Jul 2020 11:01:38 +0300 Subject: [PATCH 03/14] renderer: enable nested symbols when supported --- autoload/vista/renderer.vim | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/autoload/vista/renderer.vim b/autoload/vista/renderer.vim index 93476258..3cbf3446 100644 --- a/autoload/vista/renderer.vim +++ b/autoload/vista/renderer.vim @@ -69,13 +69,17 @@ function! vista#renderer#Decorate(kind) abort endif endfunction +function! s:HasNestingLevel(data) + return !empty(a:data) && type(a:data) == v:t_list && has_key(a:data[0], 'level') +endfunction + function! s:Render(data) abort - if g:vista.provider ==# 'coc' + if g:vista.provider ==# 'coc' || s:HasNestingLevel(a:data) return vista#renderer#hir#lsp#Coc(a:data) elseif g:vista.provider ==# 'ctags' && g:vista#renderer#ctags ==# 'default' return vista#renderer#hir#ctags#Render() else - " The kind renderer applys to the LSP provider. + " The kind renderer applies to the LSP provider. return vista#renderer#kind#Render(a:data) endif endfunction @@ -92,14 +96,7 @@ endfunction " Convert the number kind to the text kind, and then " extract the neccessary info from the raw LSP response. function! vista#renderer#LSPPreprocess(lsp_result) abort - let lines = [] - call map(a:lsp_result, 'vista#parser#lsp#KindToSymbol(v:val, lines)') - - let processed_data = {} - let g:vista.functions = [] - call map(lines, 'vista#parser#lsp#ExtractSymbol(v:val, processed_data)') - - return processed_data + return vista#parser#lsp#ParseDocumentSymbolPayload(a:lsp_result) endfunction " React on the preprocessed LSP data From 5015f929bafcad14758a803796a7f8d8ac603989 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 6 Jul 2020 11:04:40 +0300 Subject: [PATCH 04/14] parser#lsp: remove superseded utils --- autoload/vista/parser/lsp.vim | 44 ++--------------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 6a920b2e..3ca78e66 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -33,6 +33,8 @@ let s:symbol_kind = { \ '26': 'TypeParameter', \ } +" The kind field in the result is a number instead of a readable text, we +" should transform the number to the symbol text first. function! s:Kind2Symbol(kind) abort return has_key(s:symbol_kind, a:kind) ? s:symbol_kind[a:kind] : 'Unknown kind '.a:kind endfunction @@ -58,27 +60,6 @@ function! s:LocalToRawSymbol(sym) \ } endfunction -" The kind field in the result is a number instead of a readable text, we -" should transform the number to the symbol text first. -function! vista#parser#lsp#KindToSymbol(line, container) abort - let line = a:line - " SymbolInformation interface - if has_key(line, 'location') - let location = line.location - if s:IsFileUri(location.uri) - call add(a:container, s:LspToLocalSymbol(line, location.range)) - endif - " DocumentSymbol class - elseif has_key(line, 'range') - call add(a:container, s:LspToLocalSymbol(line, line.range)) - if has_key(line, 'children') - for child in line.children - call vista#parser#lsp#KindToSymbol(child, a:container) - endfor - endif - endif -endfunction - function! s:IsDocumentSymbol(sym) return has_key(a:sym, 'selectionRange') endfunction @@ -162,24 +143,3 @@ function! vista#parser#lsp#CocSymbols(symbol, container) abort call add(a:container, copy(a:symbol)) endfunction - -" https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol -function! vista#parser#lsp#ExtractSymbol(symbol, container) abort - let symbol = a:symbol - - if vista#ShouldIgnore(symbol.kind) - return - endif - - if symbol.kind ==? 'Method' || symbol.kind ==? 'Function' - call add(g:vista.functions, symbol) - endif - - let picked = {'lnum': symbol.lnum, 'col': symbol.col, 'text': symbol.text} - - if has_key(a:container, symbol.kind) - call add(a:container[symbol.kind], picked) - else - let a:container[symbol.kind] = [picked] - endif -endfunction From d4ddb30905a21f546754eb592dacef1408cc0f2f Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 8 Jul 2020 20:10:11 +0300 Subject: [PATCH 05/14] parser#lsp: insert list with value when key is absent --- autoload/vista/parser/lsp.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 3ca78e66..e66dc15f 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -87,12 +87,11 @@ endfunction function! s:GroupSymbolsByKind(symbols) abort let l:groups = {} for l:sym in a:symbols - let l:list = get(l:groups, l:sym.kind) - if !has_key(l:groups, l:sym.kind) - let l:list = [] - let l:groups[l:sym.kind] = l:list + if has_key(l:groups, l:sym.kind) + call add(l:groups[l:sym.kind], l:sym) + else + let l:groups[l:sym.kind] = [ l:sym ] endif - call add(l:list, l:sym) endfor return l:groups endfunction From 3667942a9e1743eefe8ca10e2f1bc394c85060a3 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 8 Jul 2020 20:12:54 +0300 Subject: [PATCH 06/14] parser#lsp: replace iteration with filter() --- autoload/vista/parser/lsp.vim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index e66dc15f..31c68d43 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -115,12 +115,8 @@ function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort if exists('g:vista_ignore_kinds') call filter(l:symlist, 'index(g:vista_ignore_kinds, v:val) < 0') endif - let g:vista.functions = [] - for l:sym in l:symlist - if l:sym.kind ==? 'Method' || l:sym.kind ==? 'Function' - call add(g:vista.functions, l:sym) - endif - endfor + let g:vista.functions = + \ filter(copy(l:symlist), 'v:val.kind ==? "Method" || v:val.kind ==? "Function"') return l:symlist endfunction From bd0fe700d9db14c5ee839f23a7e69e2646f3818b Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 8 Jul 2020 20:30:34 +0300 Subject: [PATCH 07/14] parser#lsp: remove l: prefix for consistency --- autoload/vista/parser/lsp.vim | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 31c68d43..02c10f7f 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -66,18 +66,18 @@ endfunction function! s:ParseSymbolInfoList(outlist, symbols) abort for lspsym in a:symbols - let l:loc = lspsym.location - if s:IsFileUri(l:loc.uri) - call add(a:outlist, s:LspToLocalSymbol(lspsym, l:loc.range)) + let loc = lspsym.location + if s:IsFileUri(loc.uri) + call add(a:outlist, s:LspToLocalSymbol(lspsym, loc.range)) endif endfor endfunction function! s:ParseDocumentSymbolsRec(outlist, symbols, level) abort for lspsym in a:symbols - let l:sym = s:LspToLocalSymbol(lspsym, lspsym.selectionRange) - let l:sym.level = a:level - call add(a:outlist, l:sym) + let sym = s:LspToLocalSymbol(lspsym, lspsym.selectionRange) + let sym.level = a:level + call add(a:outlist, sym) if has_key(lspsym, 'children') call s:ParseDocumentSymbolsRec(a:outlist, lspsym.children, a:level + 1) endif @@ -85,39 +85,39 @@ function! s:ParseDocumentSymbolsRec(outlist, symbols, level) abort endfunction function! s:GroupSymbolsByKind(symbols) abort - let l:groups = {} - for l:sym in a:symbols - if has_key(l:groups, l:sym.kind) - call add(l:groups[l:sym.kind], l:sym) + let groups = {} + for sym in a:symbols + if has_key(groups, sym.kind) + call add(groups[sym.kind], sym) else - let l:groups[l:sym.kind] = [ l:sym ] + let groups[sym.kind] = [ sym ] endif endfor - return l:groups + return groups endfunction function! vista#parser#lsp#ParseDocumentSymbolPayload(resp) abort - let l:symbols = [] + let symbols = [] if s:IsDocumentSymbol(a:resp[0]) - call s:ParseDocumentSymbolsRec(l:symbols, a:resp, 0) - call vista#parser#lsp#FilterDocumentSymbols(l:symbols) - call vista#parser#lsp#DispatchDocumentSymbols(l:symbols) - return l:symbols + call s:ParseDocumentSymbolsRec(symbols, a:resp, 0) + call vista#parser#lsp#FilterDocumentSymbols(symbols) + call vista#parser#lsp#DispatchDocumentSymbols(symbols) + return symbols else - call s:ParseSymbolInfoList(l:symbols, a:resp) - call vista#parser#lsp#FilterDocumentSymbols(l:symbols) - return s:GroupSymbolsByKind(l:symbols) + call s:ParseSymbolInfoList(symbols, a:resp) + call vista#parser#lsp#FilterDocumentSymbols(symbols) + return s:GroupSymbolsByKind(symbols) endif endfunction function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort - let l:symlist = a:symbols + let symlist = a:symbols if exists('g:vista_ignore_kinds') - call filter(l:symlist, 'index(g:vista_ignore_kinds, v:val) < 0') + call filter(symlist, 'index(g:vista_ignore_kinds, v:val) < 0') endif let g:vista.functions = - \ filter(copy(l:symlist), 'v:val.kind ==? "Method" || v:val.kind ==? "Function"') - return l:symlist + \ filter(copy(symlist), 'v:val.kind ==? "Method" || v:val.kind ==? "Function"') + return symlist endfunction function! vista#parser#lsp#DispatchDocumentSymbols(symbols) From a127221f8e3be1762f845589622eae080e6e7864 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 8 Jul 2020 20:42:09 +0300 Subject: [PATCH 08/14] parser#lsp: make public only DispatchDocumentSymbols --- autoload/vista/parser/lsp.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 02c10f7f..9e9a446e 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -100,17 +100,16 @@ function! vista#parser#lsp#ParseDocumentSymbolPayload(resp) abort let symbols = [] if s:IsDocumentSymbol(a:resp[0]) call s:ParseDocumentSymbolsRec(symbols, a:resp, 0) - call vista#parser#lsp#FilterDocumentSymbols(symbols) call vista#parser#lsp#DispatchDocumentSymbols(symbols) return symbols else call s:ParseSymbolInfoList(symbols, a:resp) - call vista#parser#lsp#FilterDocumentSymbols(symbols) + call s:FilterDocumentSymbols(symbols) return s:GroupSymbolsByKind(symbols) endif endfunction -function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort +function! s:FilterDocumentSymbols(symbols) abort let symlist = a:symbols if exists('g:vista_ignore_kinds') call filter(symlist, 'index(g:vista_ignore_kinds, v:val) < 0') @@ -121,8 +120,9 @@ function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort endfunction function! vista#parser#lsp#DispatchDocumentSymbols(symbols) - let g:vista.raw = map(copy(a:symbols), { _, sym -> s:LocalToRawSymbol(sym) }) - return g:vista.raw + let symlist = call s:FilterDocumentSymbols(a:symbols) + let g:vista.raw = map(copy(symlist), { _, sym -> s:LocalToRawSymbol(sym) }) + return symlist endfunction function! vista#parser#lsp#CocSymbols(symbol, container) abort From 4b291e01dfce987825fd70722ad44e46c4b97537 Mon Sep 17 00:00:00 2001 From: greye Date: Wed, 8 Jul 2020 20:47:26 +0300 Subject: [PATCH 09/14] executive/coc: use DispatchDocumentSymbols() --- autoload/vista/executive/coc.vim | 6 +----- autoload/vista/parser/lsp.vim | 14 -------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/autoload/vista/executive/coc.vim b/autoload/vista/executive/coc.vim index d394cfaa..83aa5fdc 100644 --- a/autoload/vista/executive/coc.vim +++ b/autoload/vista/executive/coc.vim @@ -9,15 +9,11 @@ let s:should_display = v:false " Extract fruitful infomation from raw symbols function! s:Extract(symbols) abort - let s:data = [] - if empty(a:symbols) return endif - let g:vista.functions = [] - let g:vista.raw = [] - call map(a:symbols, 'vista#parser#lsp#CocSymbols(v:val, s:data)') + let s:data = vista#parser#lsp#DispatchDocumentSymbols(a:symbols) if !empty(s:data) let [s:reload_only, s:should_display] = vista#renderer#LSPProcess(s:data, s:reload_only, s:should_display) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 9e9a446e..45066728 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -124,17 +124,3 @@ function! vista#parser#lsp#DispatchDocumentSymbols(symbols) let g:vista.raw = map(copy(symlist), { _, sym -> s:LocalToRawSymbol(sym) }) return symlist endfunction - -function! vista#parser#lsp#CocSymbols(symbol, container) abort - if vista#ShouldIgnore(a:symbol.kind) - return - endif - - call add(g:vista.raw, s:LocalToRawSymbol(a:symbol)) - - if a:symbol.kind ==? 'Method' || a:symbol.kind ==? 'Function' - call add(g:vista.functions, a:symbol) - endif - - call add(a:container, copy(a:symbol)) -endfunction From d4a6ba9ccc282b9bdfbe04b34f3567f6c7f90da5 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 9 Jul 2020 10:16:18 +0300 Subject: [PATCH 10/14] parser#lsp: remove 'call' in expression syntax --- autoload/vista/parser/lsp.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index 45066728..d7db0052 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -120,7 +120,7 @@ function! s:FilterDocumentSymbols(symbols) abort endfunction function! vista#parser#lsp#DispatchDocumentSymbols(symbols) - let symlist = call s:FilterDocumentSymbols(a:symbols) + let symlist = s:FilterDocumentSymbols(a:symbols) let g:vista.raw = map(copy(symlist), { _, sym -> s:LocalToRawSymbol(sym) }) return symlist endfunction From 606705022aaaa8d944c6f8da122994eb0092ef0a Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 9 Jul 2020 10:32:08 +0300 Subject: [PATCH 11/14] parser#lsp: replace iteration with filter() --- autoload/vista/parser/lsp.vim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index d7db0052..ea2198f7 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -65,12 +65,8 @@ function! s:IsDocumentSymbol(sym) endfunction function! s:ParseSymbolInfoList(outlist, symbols) abort - for lspsym in a:symbols - let loc = lspsym.location - if s:IsFileUri(loc.uri) - call add(a:outlist, s:LspToLocalSymbol(lspsym, loc.range)) - endif - endfor + let filtered = filter(a:symbols, 's:IsFileUri(v:val.location.uri)') + extend(a:outlist, map(filtered, 's:LspToLocalSymbol(v:val, v:val.location.range)')) endfunction function! s:ParseDocumentSymbolsRec(outlist, symbols, level) abort From 7ac9505984cfbf9c4337dfb7d7798c5fe9ed4391 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 9 Jul 2020 10:35:02 +0300 Subject: [PATCH 12/14] parser#lsp: make interfaces more 'functional' --- autoload/vista/parser/lsp.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index ea2198f7..ffd792c1 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -66,7 +66,7 @@ endfunction function! s:ParseSymbolInfoList(outlist, symbols) abort let filtered = filter(a:symbols, 's:IsFileUri(v:val.location.uri)') - extend(a:outlist, map(filtered, 's:LspToLocalSymbol(v:val, v:val.location.range)')) + return map(filtered, 's:LspToLocalSymbol(v:val, v:val.location.range)') endfunction function! s:ParseDocumentSymbolsRec(outlist, symbols, level) abort @@ -78,6 +78,7 @@ function! s:ParseDocumentSymbolsRec(outlist, symbols, level) abort call s:ParseDocumentSymbolsRec(a:outlist, lspsym.children, a:level + 1) endif endfor + return a:outlist endfunction function! s:GroupSymbolsByKind(symbols) abort @@ -93,13 +94,11 @@ function! s:GroupSymbolsByKind(symbols) abort endfunction function! vista#parser#lsp#ParseDocumentSymbolPayload(resp) abort - let symbols = [] if s:IsDocumentSymbol(a:resp[0]) - call s:ParseDocumentSymbolsRec(symbols, a:resp, 0) - call vista#parser#lsp#DispatchDocumentSymbols(symbols) - return symbols + let symbols = s:ParseDocumentSymbolsRec([], a:resp, 0) + return vista#parser#lsp#DispatchDocumentSymbols(symbols) else - call s:ParseSymbolInfoList(symbols, a:resp) + let symbols = s:ParseSymbolInfoList(a:resp) call s:FilterDocumentSymbols(symbols) return s:GroupSymbolsByKind(symbols) endif From 15fe18da1d7a30c903df7eede9632e8120657081 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 9 Jul 2020 10:39:02 +0300 Subject: [PATCH 13/14] parser#lsp: remove lambda for consistency --- autoload/vista/parser/lsp.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index ffd792c1..b672d8c4 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -116,6 +116,6 @@ endfunction function! vista#parser#lsp#DispatchDocumentSymbols(symbols) let symlist = s:FilterDocumentSymbols(a:symbols) - let g:vista.raw = map(copy(symlist), { _, sym -> s:LocalToRawSymbol(sym) }) + let g:vista.raw = map(copy(symlist), 's:LocalToRawSymbol(v:val)') return symlist endfunction From af2ed02ba4b281c73ec38705c4f7221500787e93 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 9 Jul 2020 11:32:18 +0300 Subject: [PATCH 14/14] parser#lsp: remove unused parameter --- autoload/vista/parser/lsp.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vista/parser/lsp.vim b/autoload/vista/parser/lsp.vim index b672d8c4..3101c48e 100644 --- a/autoload/vista/parser/lsp.vim +++ b/autoload/vista/parser/lsp.vim @@ -64,7 +64,7 @@ function! s:IsDocumentSymbol(sym) return has_key(a:sym, 'selectionRange') endfunction -function! s:ParseSymbolInfoList(outlist, symbols) abort +function! s:ParseSymbolInfoList(symbols) abort let filtered = filter(a:symbols, 's:IsFileUri(v:val.location.uri)') return map(filtered, 's:LspToLocalSymbol(v:val, v:val.location.range)') endfunction