autoload/handlers.vim | 32 ++++++++++++++++++++++---------- diff --git a/autoload/handlers.vim b/autoload/handlers.vim index d79efcba025850a54c7db4e1871ee26f5e3a0300..91ff702f6c76bb7f3ba2d987b1cef8095dedd619 100644 --- a/autoload/handlers.vim +++ b/autoload/handlers.vim @@ -328,28 +328,40 @@ enddef # display the list of document symbols from the LSP server in a window as a # tree -def s:showSymbols(symTable: list>) +def s:showSymbols(symTable: list>, uri: string) var symbols: dict>> var symbolType: string var fname: string + var r: dict> + var name: string + + if uri != '' + fname = LspUriToFile(uri) + endif for symbol in symTable if symbol->has_key('location') + # interface SymbolInformation fname = LspUriToFile(symbol.location.uri) symbolType = LspSymbolKindToName(symbol.kind) - if !symbols->has_key(symbolType) - symbols[symbolType] = [] - endif - var name: string = symbol.name + name = symbol.name if symbol->has_key('containerName') if symbol.containerName != '' name ..= ' [' .. symbol.containerName .. ']' endif endif - symbols[symbolType]->add({name: name, - lnum: symbol.location.range.start.line + 1, - col: symbol.location.range.start.character + 1}) + r = symbol.location.range + else + # interface DocumentSymbol + name = symbol.name + symbolType = LspSymbolKindToName(symbol.kind) + r = symbol.range endif + if !symbols->has_key(symbolType) + symbols[symbolType] = [] + endif + symbols[symbolType]->add({name: name, + lnum: r.start.line + 1, col: r.start.character + 1}) endfor var wid: number = bufwinid('LSP-Symbols') @@ -393,7 +405,7 @@ WarnMsg('No symbols are found') return endif - s:showSymbols(reply.result) + s:showSymbols(reply.result, req.params.textDocument.uri) enddef # Returns the byte number of the specified line/col position. Returns a @@ -773,7 +785,7 @@ WarnMsg('Error: Symbol not found') return endif - s:showSymbols(reply.result) + s:showSymbols(reply.result, '') enddef # Process various reply messages from the LSP server