We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[regression] lsp_execute does nothing due to empty session
Since this [commit](https://github.com/sublimelsp/LSP/commit/7d05794fa3cc4ecd3931d09a90e801addc70d9fa) the `capability` variable got deleted which means that `self.best_session(self.capability)` is unable to find session.

The consequence is that [LSP-metals.sublime-commands](https://github.com/scalameta/metals-sublime/blob/master/LSP-metals.sublime-commands) aren't executed.

 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugin/execute_command.py`
Content:
```
1 import sublime
2 from .core.protocol import Error
3 from .core.protocol import ExecuteCommandParams
4 from .core.registry import LspTextCommand
5 from .core.registry import windows
6 from .core.typing import List, Optional, Any
7 from .core.views import uri_from_view, offset_to_point, region_to_range, text_document_identifier
8 
9 
10 class LspExecuteCommand(LspTextCommand):
11 
12     def run(self,
13             edit: sublime.Edit,
14             command_name: Optional[str] = None,
15             command_args: Optional[List[Any]] = None,
16             session_name: Optional[str] = None,
17             event: Optional[dict] = None) -> None:
18         # Handle VSCode-specific command for triggering AC/sighelp
19         if command_name == "editor.action.triggerSuggest":
20             # Triggered from set_timeout as suggestions popup doesn't trigger otherwise.
21             return sublime.set_timeout(lambda: self.view.run_command("auto_complete"))
22         if command_name == "editor.action.triggerParameterHints":
23 
24             def run_async() -> None:
25                 listener = windows.listener_for_view(self.view)
26                 if listener:
27                     listener.do_signature_help_async(manual=False)
28 
29             return sublime.set_timeout_async(run_async)
30         session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)
31         if session and command_name:
32             if command_args:
33                 self._expand_variables(command_args)
34             params = {"command": command_name}  # type: ExecuteCommandParams
35             if command_args:
36                 params["arguments"] = command_args
37 
38             def handle_response(response: Any) -> None:
39                 assert command_name
40                 if isinstance(response, Error):
41                     sublime.message_dialog("command {} failed. Reason: {}".format(command_name, str(response)))
42                     return
43                 msg = "command {} completed".format(command_name)
44                 if response:
45                     msg += "with response: {}".format(response)
46                 window = self.view.window()
47                 if window:
48                     window.status_message(msg)
49 
50             session.execute_command(params, progress=True).then(handle_response)
51 
52     def _expand_variables(self, command_args: List[Any]) -> None:
53         region = self.view.sel()[0]
54         for i, arg in enumerate(command_args):
55             if arg in ["$document_id", "${document_id}"]:
56                 command_args[i] = text_document_identifier(self.view)
57             if arg in ["$file_uri", "${file_uri}"]:
58                 command_args[i] = uri_from_view(self.view)
59             elif arg in ["$selection", "${selection}"]:
60                 command_args[i] = self.view.substr(region)
61             elif arg in ["$offset", "${offset}"]:
62                 command_args[i] = region.b
63             elif arg in ["$selection_begin", "${selection_begin}"]:
64                 command_args[i] = region.begin()
65             elif arg in ["$selection_end", "${selection_end}"]:
66                 command_args[i] = region.end()
67             elif arg in ["$position", "${position}"]:
68                 command_args[i] = offset_to_point(self.view, region.b).to_lsp()
69             elif arg in ["$range", "${range}"]:
70                 command_args[i] = region_to_range(self.view, region).to_lsp()
71
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugin/execute_command.py b/plugin/execute_command.py
--- a/plugin/execute_command.py
+++ b/plugin/execute_command.py
@@ -27,7 +27,7 @@
                     listener.do_signature_help_async(manual=False)
 
             return sublime.set_timeout_async(run_async)
-        session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)
+        session = self.session_by_name(session_name if session_name else self.session_name)
         if session and command_name:
             if command_args:
                 self._expand_variables(command_args)

{"golden_diff": "diff --git a/plugin/execute_command.py b/plugin/execute_command.py\n--- a/plugin/execute_command.py\n+++ b/plugin/execute_command.py\n@@ -27,7 +27,7 @@\n                     listener.do_signature_help_async(manual=False)\n \n             return sublime.set_timeout_async(run_async)\n-        session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)\n+        session = self.session_by_name(session_name if session_name else self.session_name)\n         if session and command_name:\n             if command_args:\n                 self._expand_variables(command_args)\n", "issue": "[regression] lsp_execute does nothing due to empty session\nSince this [commit](https://github.com/sublimelsp/LSP/commit/7d05794fa3cc4ecd3931d09a90e801addc70d9fa) the `capability` variable got deleted which means that `self.best_session(self.capability)` is unable to find session.\r\n\r\nThe consequence is that [LSP-metals.sublime-commands](https://github.com/scalameta/metals-sublime/blob/master/LSP-metals.sublime-commands) aren't executed.\r\n\r\n \r\n\n", "before_files": [{"content": "import sublime\nfrom .core.protocol import Error\nfrom .core.protocol import ExecuteCommandParams\nfrom .core.registry import LspTextCommand\nfrom .core.registry import windows\nfrom .core.typing import List, Optional, Any\nfrom .core.views import uri_from_view, offset_to_point, region_to_range, text_document_identifier\n\n\nclass LspExecuteCommand(LspTextCommand):\n\n    def run(self,\n            edit: sublime.Edit,\n            command_name: Optional[str] = None,\n            command_args: Optional[List[Any]] = None,\n            session_name: Optional[str] = None,\n            event: Optional[dict] = None) -> None:\n        # Handle VSCode-specific command for triggering AC/sighelp\n        if command_name == \"editor.action.triggerSuggest\":\n            # Triggered from set_timeout as suggestions popup doesn't trigger otherwise.\n            return sublime.set_timeout(lambda: self.view.run_command(\"auto_complete\"))\n        if command_name == \"editor.action.triggerParameterHints\":\n\n            def run_async() -> None:\n                listener = windows.listener_for_view(self.view)\n                if listener:\n                    listener.do_signature_help_async(manual=False)\n\n            return sublime.set_timeout_async(run_async)\n        session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)\n        if session and command_name:\n            if command_args:\n                self._expand_variables(command_args)\n            params = {\"command\": command_name}  # type: ExecuteCommandParams\n            if command_args:\n                params[\"arguments\"] = command_args\n\n            def handle_response(response: Any) -> None:\n                assert command_name\n                if isinstance(response, Error):\n                    sublime.message_dialog(\"command {} failed. Reason: {}\".format(command_name, str(response)))\n                    return\n                msg = \"command {} completed\".format(command_name)\n                if response:\n                    msg += \"with response: {}\".format(response)\n                window = self.view.window()\n                if window:\n                    window.status_message(msg)\n\n            session.execute_command(params, progress=True).then(handle_response)\n\n    def _expand_variables(self, command_args: List[Any]) -> None:\n        region = self.view.sel()[0]\n        for i, arg in enumerate(command_args):\n            if arg in [\"$document_id\", \"${document_id}\"]:\n                command_args[i] = text_document_identifier(self.view)\n            if arg in [\"$file_uri\", \"${file_uri}\"]:\n                command_args[i] = uri_from_view(self.view)\n            elif arg in [\"$selection\", \"${selection}\"]:\n                command_args[i] = self.view.substr(region)\n            elif arg in [\"$offset\", \"${offset}\"]:\n                command_args[i] = region.b\n            elif arg in [\"$selection_begin\", \"${selection_begin}\"]:\n                command_args[i] = region.begin()\n            elif arg in [\"$selection_end\", \"${selection_end}\"]:\n                command_args[i] = region.end()\n            elif arg in [\"$position\", \"${position}\"]:\n                command_args[i] = offset_to_point(self.view, region.b).to_lsp()\n            elif arg in [\"$range\", \"${range}\"]:\n                command_args[i] = region_to_range(self.view, region).to_lsp()\n", "path": "plugin/execute_command.py"}], "after_files": [{"content": "import sublime\nfrom .core.protocol import Error\nfrom .core.protocol import ExecuteCommandParams\nfrom .core.registry import LspTextCommand\nfrom .core.registry import windows\nfrom .core.typing import List, Optional, Any\nfrom .core.views import uri_from_view, offset_to_point, region_to_range, text_document_identifier\n\n\nclass LspExecuteCommand(LspTextCommand):\n\n    def run(self,\n            edit: sublime.Edit,\n            command_name: Optional[str] = None,\n            command_args: Optional[List[Any]] = None,\n            session_name: Optional[str] = None,\n            event: Optional[dict] = None) -> None:\n        # Handle VSCode-specific command for triggering AC/sighelp\n        if command_name == \"editor.action.triggerSuggest\":\n            # Triggered from set_timeout as suggestions popup doesn't trigger otherwise.\n            return sublime.set_timeout(lambda: self.view.run_command(\"auto_complete\"))\n        if command_name == \"editor.action.triggerParameterHints\":\n\n            def run_async() -> None:\n                listener = windows.listener_for_view(self.view)\n                if listener:\n                    listener.do_signature_help_async(manual=False)\n\n            return sublime.set_timeout_async(run_async)\n        session = self.session_by_name(session_name if session_name else self.session_name)\n        if session and command_name:\n            if command_args:\n                self._expand_variables(command_args)\n            params = {\"command\": command_name}  # type: ExecuteCommandParams\n            if command_args:\n                params[\"arguments\"] = command_args\n\n            def handle_response(response: Any) -> None:\n                assert command_name\n                if isinstance(response, Error):\n                    sublime.message_dialog(\"command {} failed. Reason: {}\".format(command_name, str(response)))\n                    return\n                msg = \"command {} completed\".format(command_name)\n                if response:\n                    msg += \"with response: {}\".format(response)\n                window = self.view.window()\n                if window:\n                    window.status_message(msg)\n\n            session.execute_command(params, progress=True).then(handle_response)\n\n    def _expand_variables(self, command_args: List[Any]) -> None:\n        region = self.view.sel()[0]\n        for i, arg in enumerate(command_args):\n            if arg in [\"$document_id\", \"${document_id}\"]:\n                command_args[i] = text_document_identifier(self.view)\n            if arg in [\"$file_uri\", \"${file_uri}\"]:\n                command_args[i] = uri_from_view(self.view)\n            elif arg in [\"$selection\", \"${selection}\"]:\n                command_args[i] = self.view.substr(region)\n            elif arg in [\"$offset\", \"${offset}\"]:\n                command_args[i] = region.b\n            elif arg in [\"$selection_begin\", \"${selection_begin}\"]:\n                command_args[i] = region.begin()\n            elif arg in [\"$selection_end\", \"${selection_end}\"]:\n                command_args[i] = region.end()\n            elif arg in [\"$position\", \"${position}\"]:\n                command_args[i] = offset_to_point(self.view, region.b).to_lsp()\n            elif arg in [\"$range\", \"${range}\"]:\n                command_args[i] = region_to_range(self.view, region).to_lsp()\n", "path": "plugin/execute_command.py"}]}