import sublime_plugin

from .core.protocol import SymbolKind
from .core.configurations import is_supported_view
from .core.clients import client_for_view
from .core.protocol import Request, Range
from .core.url import filename_to_uri


symbol_kind_names = {
    SymbolKind.File: "file",
    SymbolKind.Module: "module",
    SymbolKind.Namespace: "namespace",
    SymbolKind.Package: "package",
    SymbolKind.Class: "class",
    SymbolKind.Method: "method",
    SymbolKind.Function: "function",
    SymbolKind.Field: "field",
    SymbolKind.Variable: "variable",
    SymbolKind.Constant: "constant",
    SymbolKind.Interface: "interface",
    SymbolKind.Property: "property"
}


def format_symbol_kind(kind):
    return symbol_kind_names.get(kind, str(kind))


def format_symbol(item):
    """
    items may be a list of strings, or a list of string lists.
    In the latter case, each entry in the quick panel will show multiple rows
    """
    prefix = item["containerName"] + "." if "containerName" in item else ""
    return [prefix + item.get("name"), format_symbol_kind(item.get("kind"))]


class LspDocumentSymbolsCommand(sublime_plugin.TextCommand):
    def is_enabled(self):
        if is_supported_view(self.view):
            client = client_for_view(self.view)
            if client and client.has_capability('documentSymbolProvider'):
                return True
        return False

    def run(self, edit):
        client = client_for_view(self.view)
        if client:
            params = {
                "textDocument": {
                    "uri": filename_to_uri(self.view.file_name())
                }
            }
            request = Request.documentSymbols(params)
            client.send_request(request, self.handle_response)

    def handle_response(self, response):
        symbols = list(format_symbol(item) for item in response)
        self.symbols = response
        self.view.window().show_quick_panel(symbols, self.on_symbol_selected)

    def on_symbol_selected(self, symbol_index):
        selected_symbol = self.symbols[symbol_index]
        range = selected_symbol['location']['range']
        region = Range.from_lsp(range).to_region(self.view)
        self.view.show_at_center(region)
        self.view.sel().clear()
        self.view.sel().add(region)

@@ -953,17 +953,21 @@
 x = item
-%5B
+.get(
 %22contain
@@ -977,71 +977,72 @@
 ame%22
-%5D + %22.%22 if %22containerName%22 in item else %22%22%0A    return %5B
+, %22%22)%0A    label = prefix + %22.%22 + item.get(%22name%22) if 
 prefix 
-+
+else
  ite
@@ -1054,16 +1054,34 @@
 (%22name%22)
+%0A    return %5Blabel
 , format

Check for language server sending null in containerName