prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  LspTextCommand should honor both session_name and capability if defined
  If `capability` in [LspTextCommand](https://github.com/sublimelsp/LSP/blob/81a6e6aeb2c3a6aebad59fbd6eb0361301243bd1/plugin/core/registry.py#L52-L70) is defined, `session_name` is ignored. You might say that LSP-* plugins exactly know the capabilities of their server and thus never need to specify `capability` in a derived class, but in particular it's impossible for plugins to derive from LspExecuteCommand (which is derived from LspTextCommand), because that class already comes with a predefined `capability`. It can be convenient for a plugin to declare a derived class from LspExecuteCommand, so that their commands are only shown/enabled for corresponding filetypes:
  ```python
  class FooExecuteCommand(LspExecuteCommand):
      session_name = "foo"
  ```
  
  **Describe the solution you'd like**
  ```python
      def is_enabled(self, event: Optional[dict] = None, point: Optional[int] = None) -> bool:
          if self.capability:
              # At least one active session with the given capability must exist.
              if not bool(self.best_session(self.capability, get_position(self.view, event, point))):
                  return False
          if self.session_name:
              # There must exist an active session with the given (config) name.
              if not bool(self.session_by_name(self.session_name)):
                  return False
          if not self.capability and not self.session_name:
              # Any session will do.
              return any(self.sessions())
          return True
  ```
  
  **Describe alternatives you've considered**
  Make `session_name` win against `capability`
  
  **Additional context**
  Notice that the implementation suggested above doesn't guarantee that the sessions with the specified name and capability are the same (in case of multiple attached sessions for a view).
  
  </issue>
  <code>
  [start of plugin/core/registry.py]
  1 from .configurations import ConfigManager
  2 from .sessions import Session
  3 from .settings import client_configs
  4 from .typing import Optional, Any, Generator, Iterable
  5 from .windows import WindowRegistry
  6 import sublime
  7 import sublime_plugin
  8 
  9 
  10 def sessions_for_view(view: sublime.View, capability: Optional[str] = None) -> Generator[Session, None, None]:
  11     """
  12     Returns all sessions for this view, optionally matching the capability path.
  13     """
  14     window = view.window()
  15     if window:
  16         manager = windows.lookup(window)
  17         yield from manager.sessions(view, capability)
  18 
  19 
  20 def best_session(view: sublime.View, sessions: Iterable[Session], point: Optional[int] = None) -> Optional[Session]:
  21     if point is None:
  22         try:
  23             point = view.sel()[0].b
  24         except IndexError:
  25             return None
  26     try:
  27         return max(sessions, key=lambda s: view.score_selector(point, s.config.priority_selector))  # type: ignore
  28     except ValueError:
  29         return None
  30 
  31 
  32 configs = ConfigManager(client_configs.all)
  33 client_configs.set_listener(configs.update)
  34 windows = WindowRegistry(configs)
  35 
  36 
  37 def get_position(view: sublime.View, event: Optional[dict] = None, point: Optional[int] = None) -> int:
  38     if isinstance(point, int):
  39         return point
  40     elif event:
  41         return view.window_to_text((event["x"], event["y"]))
  42     else:
  43         return view.sel()[0].begin()
  44 
  45 
  46 class LspTextCommand(sublime_plugin.TextCommand):
  47     """
  48     Inherit from this class to define your requests that should be triggered via the command palette and/or a
  49     keybinding.
  50     """
  51 
  52     # When this is defined in a derived class, the command is enabled if and only if there exists a session attached
  53     # to the view that has the given capability. When both `capability` and `session_name` are defined, `capability`
  54     # wins.
  55     capability = ''
  56 
  57     # When this is defined in a derived class, the command is enabled if and only if there exists a session attached
  58     # to the view that has the given name. When both `capability` and `session_name` are defined, `capability` wins.
  59     session_name = ''
  60 
  61     def is_enabled(self, event: Optional[dict] = None, point: Optional[int] = None) -> bool:
  62         if self.capability:
  63             # At least one active session with the given capability must exist.
  64             return bool(self.best_session(self.capability, get_position(self.view, event, point)))
  65         elif self.session_name:
  66             # There must exist an active session with the given (config) name.
  67             return bool(self.session_by_name(self.session_name))
  68         else:
  69             # Any session will do.
  70             return any(self.sessions())
  71 
  72     def want_event(self) -> bool:
  73         return True
  74 
  75     def best_session(self, capability: str, point: Optional[int] = None) -> Optional[Session]:
  76         listener = windows.listener_for_view(self.view)
  77         return listener.session(capability, point) if listener else None
  78 
  79     def session_by_name(self, name: Optional[str] = None) -> Optional[Session]:
  80         target = name if name else self.session_name
  81         for session in self.sessions():
  82             if session.config.name == target:
  83                 return session
  84         return None
  85 
  86     def sessions(self, capability: Optional[str] = None) -> Generator[Session, None, None]:
  87         yield from sessions_for_view(self.view, capability)
  88 
  89 
  90 class LspRestartClientCommand(sublime_plugin.TextCommand):
  91     def run(self, edit: Any) -> None:
  92         window = self.view.window()
  93         if window:
  94             windows.lookup(window).restart_sessions_async()
  95 
  96 
  97 class LspRecheckSessionsCommand(sublime_plugin.WindowCommand):
  98     def run(self) -> None:
  99         sublime.set_timeout_async(lambda: windows.lookup(self.window).restart_sessions_async())
  100
  [end of plugin/core/registry.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/core/registry.py b/plugin/core/registry.py
  --- a/plugin/core/registry.py
  +++ b/plugin/core/registry.py
  @@ -49,25 +49,27 @@
       keybinding.
       """
   
  -    # When this is defined in a derived class, the command is enabled if and only if there exists a session attached
  -    # to the view that has the given capability. When both `capability` and `session_name` are defined, `capability`
  -    # wins.
  +    # When this is defined in a derived class, the command is enabled only if there exists a session attached to the
  +    # view that has the given capability.
       capability = ''
   
  -    # When this is defined in a derived class, the command is enabled if and only if there exists a session attached
  -    # to the view that has the given name. When both `capability` and `session_name` are defined, `capability` wins.
  +    # When this is defined in a derived class, the command is enabled only if there exists a session attached to the
  +    # view that has the given name.
       session_name = ''
   
       def is_enabled(self, event: Optional[dict] = None, point: Optional[int] = None) -> bool:
           if self.capability:
               # At least one active session with the given capability must exist.
  -            return bool(self.best_session(self.capability, get_position(self.view, event, point)))
  -        elif self.session_name:
  +            if not self.best_session(self.capability, get_position(self.view, event, point)):
  +                return False
  +        if self.session_name:
               # There must exist an active session with the given (config) name.
  -            return bool(self.session_by_name(self.session_name))
  -        else:
  +            if not self.session_by_name(self.session_name):
  +                return False
  +        if not self.capability and not self.session_name:
               # Any session will do.
               return any(self.sessions())
  +        return True
   
       def want_event(self) -> bool:
           return True
  
verification_info: {"golden_diff": "diff --git a/plugin/core/registry.py b/plugin/core/registry.py\n--- a/plugin/core/registry.py\n+++ b/plugin/core/registry.py\n@@ -49,25 +49,27 @@\n     keybinding.\n     \"\"\"\n \n-    # When this is defined in a derived class, the command is enabled if and only if there exists a session attached\n-    # to the view that has the given capability. When both `capability` and `session_name` are defined, `capability`\n-    # wins.\n+    # When this is defined in a derived class, the command is enabled only if there exists a session attached to the\n+    # view that has the given capability.\n     capability = ''\n \n-    # When this is defined in a derived class, the command is enabled if and only if there exists a session attached\n-    # to the view that has the given name. When both `capability` and `session_name` are defined, `capability` wins.\n+    # When this is defined in a derived class, the command is enabled only if there exists a session attached to the\n+    # view that has the given name.\n     session_name = ''\n \n     def is_enabled(self, event: Optional[dict] = None, point: Optional[int] = None) -> bool:\n         if self.capability:\n             # At least one active session with the given capability must exist.\n-            return bool(self.best_session(self.capability, get_position(self.view, event, point)))\n-        elif self.session_name:\n+            if not self.best_session(self.capability, get_position(self.view, event, point)):\n+                return False\n+        if self.session_name:\n             # There must exist an active session with the given (config) name.\n-            return bool(self.session_by_name(self.session_name))\n-        else:\n+            if not self.session_by_name(self.session_name):\n+                return False\n+        if not self.capability and not self.session_name:\n             # Any session will do.\n             return any(self.sessions())\n+        return True\n \n     def want_event(self) -> bool:\n         return True\n", "issue": "LspTextCommand should honor both session_name and capability if defined\nIf `capability` in [LspTextCommand](https://github.com/sublimelsp/LSP/blob/81a6e6aeb2c3a6aebad59fbd6eb0361301243bd1/plugin/core/registry.py#L52-L70) is defined, `session_name` is ignored. You might say that LSP-* plugins exactly know the capabilities of their server and thus never need to specify `capability` in a derived class, but in particular it's impossible for plugins to derive from LspExecuteCommand (which is derived from LspTextCommand), because that class already comes with a predefined `capability`. It can be convenient for a plugin to declare a derived class from LspExecuteCommand, so that their commands are only shown/enabled for corresponding filetypes:\r\n```python\r\nclass FooExecuteCommand(LspExecuteCommand):\r\n    session_name = \"foo\"\r\n```\r\n\r\n**Describe the solution you'd like**\r\n```python\r\n    def is_enabled(self, event: Optional[dict] = None, point: Optional[int] = None) -> bool:\r\n        if self.capability:\r\n            # At least one active session with the given capability must exist.\r\n            if not bool(self.best_session(self.capability, get_position(self.view, event, point))):\r\n                return False\r\n        if self.session_name:\r\n            # There must exist an active session with the given (config) name.\r\n            if not bool(self.session_by_name(self.session_name)):\r\n                return False\r\n        if not self.capability and not self.session_name:\r\n            # Any session will do.\r\n            return any(self.sessions())\r\n        return True\r\n```\r\n\r\n**Describe alternatives you've considered**\r\nMake `session_name` win against `capability`\r\n\r\n**Additional context**\r\nNotice that the implementation suggested above doesn't guarantee that the sessions with the specified name and capability are the same (in case of multiple attached sessions for a view).\n", "before_files": [{"content": "from .configurations import ConfigManager\nfrom .sessions import Session\nfrom .settings import client_configs\nfrom .typing import Optional, Any, Generator, Iterable\nfrom .windows import WindowRegistry\nimport sublime\nimport sublime_plugin\n\n\ndef sessions_for_view(view: sublime.View, capability: Optional[str] = None) -> Generator[Session, None, None]:\n    \"\"\"\n    Returns all sessions for this view, optionally matching the capability path.\n    \"\"\"\n    window = view.window()\n    if window:\n        manager = windows.lookup(window)\n        yield from manager.sessions(view, capability)\n\n\ndef best_session(view: sublime.View, sessions: Iterable[Session], point: Optional[int] = None) -> Optional[Session]:\n    if point is None:\n        try:\n            point = view.sel()[0].b\n        except IndexError:\n            return None\n    try:\n        return max(sessions, key=lambda s: view.score_selector(point, s.config.priority_selector))  # type: ignore\n    except ValueError:\n        return None\n\n\nconfigs = ConfigManager(client_configs.all)\nclient_configs.set_listener(configs.update)\nwindows = WindowRegistry(configs)\n\n\ndef get_position(view: sublime.View, event: Optional[dict] = None, point: Optional[int] = None) -> int:\n    if isinstance(point, int):\n        return point\n    elif event:\n        return view.window_to_text((event[\"x\"], event[\"y\"]))\n    else:\n        return view.sel()[0].begin()\n\n\nclass LspTextCommand(sublime_plugin.TextCommand):\n    \"\"\"\n    Inherit from this class to define your requests that should be triggered via the command palette and/or a\n    keybinding.\n    \"\"\"\n\n    # When this is defined in a derived class, the command is enabled if and only if there exists a session attached\n    # to the view that has the given capability. When both `capability` and `session_name` are defined, `capability`\n    # wins.\n    capability = ''\n\n    # When this is defined in a derived class, the command is enabled if and only if there exists a session attached\n    # to the view that has the given name. When both `capability` and `session_name` are defined, `capability` wins.\n    session_name = ''\n\n    def is_enabled(self, event: Optional[dict] = None, point: Optional[int] = None) -> bool:\n        if self.capability:\n            # At least one active session with the given capability must exist.\n            return bool(self.best_session(self.capability, get_position(self.view, event, point)))\n        elif self.session_name:\n            # There must exist an active session with the given (config) name.\n            return bool(self.session_by_name(self.session_name))\n        else:\n            # Any session will do.\n            return any(self.sessions())\n\n    def want_event(self) -> bool:\n        return True\n\n    def best_session(self, capability: str, point: Optional[int] = None) -> Optional[Session]:\n        listener = windows.listener_for_view(self.view)\n        return listener.session(capability, point) if listener else None\n\n    def session_by_name(self, name: Optional[str] = None) -> Optional[Session]:\n        target = name if name else self.session_name\n        for session in self.sessions():\n            if session.config.name == target:\n                return session\n        return None\n\n    def sessions(self, capability: Optional[str] = None) -> Generator[Session, None, None]:\n        yield from sessions_for_view(self.view, capability)\n\n\nclass LspRestartClientCommand(sublime_plugin.TextCommand):\n    def run(self, edit: Any) -> None:\n        window = self.view.window()\n        if window:\n            windows.lookup(window).restart_sessions_async()\n\n\nclass LspRecheckSessionsCommand(sublime_plugin.WindowCommand):\n    def run(self) -> None:\n        sublime.set_timeout_async(lambda: windows.lookup(self.window).restart_sessions_async())\n", "path": "plugin/core/registry.py"}]}