prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  when cancelling the symbols panel, the last symbol is selected
  https://github.com/tomv564/LSP/blob/be904c56fddf35f724486de405a168786ed4ffeb/plugin/symbols.py#L82-L92
  ```diff
   def on_symbol_selected(self, symbol_index):
  +    if symbol_index == -1:
  +        return
       selected_symbol = self.symbols[symbol_index]
       range = selected_symbol.get('location', selected_symbol.get('range'))
       range = range.get('range', range)
  ```
  
  </issue>
  <code>
  [start of plugin/symbols.py]
  1 from .core.logging import debug
  2 from .core.protocol import Request, Range
  3 from .core.protocol import SymbolKind
  4 from .core.registry import client_for_view, LspTextCommand
  5 from .core.url import filename_to_uri
  6 from .core.views import range_to_region
  7 
  8 try:
  9     from typing import List, Optional, Any
  10     assert List and Optional and Any
  11 except ImportError:
  12     pass
  13 
  14 symbol_kind_names = {
  15     SymbolKind.File: "file",
  16     SymbolKind.Module: "module",
  17     SymbolKind.Namespace: "namespace",
  18     SymbolKind.Package: "package",
  19     SymbolKind.Class: "class",
  20     SymbolKind.Method: "method",
  21     SymbolKind.Property: "property",
  22     SymbolKind.Field: "field",
  23     SymbolKind.Constructor: "constructor",
  24     SymbolKind.Enum: "enum",
  25     SymbolKind.Interface: "interface",
  26     SymbolKind.Function: "function",
  27     SymbolKind.Variable: "variable",
  28     SymbolKind.Constant: "constant",
  29     SymbolKind.String: "string",
  30     SymbolKind.Number: "number",
  31     SymbolKind.Boolean: "boolean",
  32     SymbolKind.Array: "array",
  33     SymbolKind.Object: "object",
  34     SymbolKind.Key: "key",
  35     SymbolKind.Null: "null",
  36     SymbolKind.EnumMember: "enum member",
  37     SymbolKind.Struct: "struct",
  38     SymbolKind.Event: "event",
  39     SymbolKind.Operator: "operator",
  40     SymbolKind.TypeParameter: "type parameter"
  41 }
  42 
  43 
  44 def format_symbol_kind(kind):
  45     return symbol_kind_names.get(kind, str(kind))
  46 
  47 
  48 def format_symbol(item):
  49     """
  50     items may be a list of strings, or a list of string lists.
  51     In the latter case, each entry in the quick panel will show multiple rows
  52     """
  53     prefix = item.get("containerName", "")
  54     label = prefix + "." + item.get("name") if prefix else item.get("name")
  55     return [label, format_symbol_kind(item.get("kind"))]
  56 
  57 
  58 class LspDocumentSymbolsCommand(LspTextCommand):
  59     def __init__(self, view):
  60         super().__init__(view)
  61 
  62     def is_enabled(self, event=None):
  63         return self.has_client_with_capability('documentSymbolProvider')
  64 
  65     def run(self, edit) -> None:
  66         client = client_for_view(self.view)
  67         if client:
  68             params = {
  69                 "textDocument": {
  70                     "uri": filename_to_uri(self.view.file_name())
  71                 }
  72             }
  73             request = Request.documentSymbols(params)
  74             client.send_request(request, self.handle_response)
  75 
  76     def handle_response(self, response: 'Optional[List]') -> None:
  77         response_list = response or []
  78         symbols = list(format_symbol(item) for item in response_list)
  79         self.symbols = response_list
  80         self.view.window().show_quick_panel(symbols, self.on_symbol_selected)
  81 
  82     def on_symbol_selected(self, symbol_index):
  83         selected_symbol = self.symbols[symbol_index]
  84         range = selected_symbol.get('location', selected_symbol.get('range'))
  85         range = range.get('range', range)
  86         if not range:
  87             debug('could not recognize the type: expected either SymbolInformation or DocumentSymbol')
  88             return
  89         region = range_to_region(Range.from_lsp(range), self.view)
  90         self.view.show_at_center(region)
  91         self.view.sel().clear()
  92         self.view.sel().add(region)
  93
  [end of plugin/symbols.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/plugin/symbols.py b/plugin/symbols.py
  --- a/plugin/symbols.py
  +++ b/plugin/symbols.py
  @@ -80,6 +80,8 @@
           self.view.window().show_quick_panel(symbols, self.on_symbol_selected)
   
       def on_symbol_selected(self, symbol_index):
  +        if symbol_index == -1:
  +            return
           selected_symbol = self.symbols[symbol_index]
           range = selected_symbol.get('location', selected_symbol.get('range'))
           range = range.get('range', range)
  
verification_info: {"golden_diff": "diff --git a/plugin/symbols.py b/plugin/symbols.py\n--- a/plugin/symbols.py\n+++ b/plugin/symbols.py\n@@ -80,6 +80,8 @@\n         self.view.window().show_quick_panel(symbols, self.on_symbol_selected)\n \n     def on_symbol_selected(self, symbol_index):\n+        if symbol_index == -1:\n+            return\n         selected_symbol = self.symbols[symbol_index]\n         range = selected_symbol.get('location', selected_symbol.get('range'))\n         range = range.get('range', range)\n", "issue": "when cancelling the symbols panel, the last symbol is selected\nhttps://github.com/tomv564/LSP/blob/be904c56fddf35f724486de405a168786ed4ffeb/plugin/symbols.py#L82-L92\r\n```diff\r\n def on_symbol_selected(self, symbol_index):\r\n+    if symbol_index == -1:\r\n+        return\r\n     selected_symbol = self.symbols[symbol_index]\r\n     range = selected_symbol.get('location', selected_symbol.get('range'))\r\n     range = range.get('range', range)\r\n```\n", "before_files": [{"content": "from .core.logging import debug\nfrom .core.protocol import Request, Range\nfrom .core.protocol import SymbolKind\nfrom .core.registry import client_for_view, LspTextCommand\nfrom .core.url import filename_to_uri\nfrom .core.views import range_to_region\n\ntry:\n    from typing import List, Optional, Any\n    assert List and Optional and Any\nexcept ImportError:\n    pass\n\nsymbol_kind_names = {\n    SymbolKind.File: \"file\",\n    SymbolKind.Module: \"module\",\n    SymbolKind.Namespace: \"namespace\",\n    SymbolKind.Package: \"package\",\n    SymbolKind.Class: \"class\",\n    SymbolKind.Method: \"method\",\n    SymbolKind.Property: \"property\",\n    SymbolKind.Field: \"field\",\n    SymbolKind.Constructor: \"constructor\",\n    SymbolKind.Enum: \"enum\",\n    SymbolKind.Interface: \"interface\",\n    SymbolKind.Function: \"function\",\n    SymbolKind.Variable: \"variable\",\n    SymbolKind.Constant: \"constant\",\n    SymbolKind.String: \"string\",\n    SymbolKind.Number: \"number\",\n    SymbolKind.Boolean: \"boolean\",\n    SymbolKind.Array: \"array\",\n    SymbolKind.Object: \"object\",\n    SymbolKind.Key: \"key\",\n    SymbolKind.Null: \"null\",\n    SymbolKind.EnumMember: \"enum member\",\n    SymbolKind.Struct: \"struct\",\n    SymbolKind.Event: \"event\",\n    SymbolKind.Operator: \"operator\",\n    SymbolKind.TypeParameter: \"type parameter\"\n}\n\n\ndef format_symbol_kind(kind):\n    return symbol_kind_names.get(kind, str(kind))\n\n\ndef format_symbol(item):\n    \"\"\"\n    items may be a list of strings, or a list of string lists.\n    In the latter case, each entry in the quick panel will show multiple rows\n    \"\"\"\n    prefix = item.get(\"containerName\", \"\")\n    label = prefix + \".\" + item.get(\"name\") if prefix else item.get(\"name\")\n    return [label, format_symbol_kind(item.get(\"kind\"))]\n\n\nclass LspDocumentSymbolsCommand(LspTextCommand):\n    def __init__(self, view):\n        super().__init__(view)\n\n    def is_enabled(self, event=None):\n        return self.has_client_with_capability('documentSymbolProvider')\n\n    def run(self, edit) -> None:\n        client = client_for_view(self.view)\n        if client:\n            params = {\n                \"textDocument\": {\n                    \"uri\": filename_to_uri(self.view.file_name())\n                }\n            }\n            request = Request.documentSymbols(params)\n            client.send_request(request, self.handle_response)\n\n    def handle_response(self, response: 'Optional[List]') -> None:\n        response_list = response or []\n        symbols = list(format_symbol(item) for item in response_list)\n        self.symbols = response_list\n        self.view.window().show_quick_panel(symbols, self.on_symbol_selected)\n\n    def on_symbol_selected(self, symbol_index):\n        selected_symbol = self.symbols[symbol_index]\n        range = selected_symbol.get('location', selected_symbol.get('range'))\n        range = range.get('range', range)\n        if not range:\n            debug('could not recognize the type: expected either SymbolInformation or DocumentSymbol')\n            return\n        region = range_to_region(Range.from_lsp(range), self.view)\n        self.view.show_at_center(region)\n        self.view.sel().clear()\n        self.view.sel().add(region)\n", "path": "plugin/symbols.py"}]}