From c9c68de3603b619cefa9d519f73cbb046f7a341b Mon Sep 17 00:00:00 2001 From: simrat39 Date: Mon, 3 May 2021 16:02:56 -0700 Subject: [PATCH] feat(parser): Support SymbolInformation[] -- https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol Some lsp like vuels, pyls etc dont support the newer DocumentSymbol[] data structure so add minimal support for the old way. This is not hierarchical so not really a tree Addresses #13 --- lua/symbols-outline/parser.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lua/symbols-outline/parser.lua b/lua/symbols-outline/parser.lua index 8950009..c7faf50 100644 --- a/lua/symbols-outline/parser.lua +++ b/lua/symbols-outline/parser.lua @@ -33,16 +33,28 @@ function M.parse(result, depth, heirarchy) children = M.parse(value.children, level + 1, child_hir) end + -- support SymbolInformation[] + -- https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol + local selectionRange = value.selectionRange + if value.selectionRange == nil then + selectionRange = value.location.range + end + + local range = value.range + if value.range == nil then + range = value.location.range + end + table.insert(ret, { deprecated = value.deprecated, kind = value.kind, icon = symbols.icon_from_kind(value.kind), name = value.name, detail = value.detail, - line = value.selectionRange.start.line, - range_start = value.range.start.line, - range_end = value.range["end"].line, - character = value.selectionRange.start.character, + line = selectionRange.start.line, + character = selectionRange.start.character, + range_start = range.start.line, + range_end = range["end"].line, children = children, depth = level, isLast = isLast,