We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Triggers completion command on the wrong session
When having both LSP-css and LSP-stylelint running for open file (*.css), the completions are requested from LSP-css but the `command` that the completion item triggers runs on `LSP-stylelint` triggering an error dialog.

An example completion item looks like this:
```
    {
      "command": {
        "command": "editor.action.triggerSuggest",
        "title": "Suggest"
      },
      "documentation": {
        "kind": "plaintext",
        "value": "Specifies the width of the content area, padding area or border area (depending on 'box-sizing') of certain boxes.\n\nSyntax: <viewport-length>{1,2}\n\nMDN Reference: https://developer.mozilla.org/docs/Web/CSS/width"
      },
      "insertTextFormat": 2,
      "kind": 10,
      "label": "width",
      "sortText": "d_0000",
      "tags": [],
      "textEdit": {
        "newText": "width: $0;",
        "range": {
          "end": {
            "character": 5,
            "line": 4
          },
          "start": {
            "character": 4,
            "line": 4
          }
        }
      }
    },
```

It has a `command` that runs after inserting completion.

--- 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/completion.py`
Content:
```
1 import mdpopups
2 import sublime
3 import sublime_plugin
4 import webbrowser
5 from .core.css import css
6 from .core.logging import debug
7 from .core.edit import parse_text_edit
8 from .core.protocol import Request, InsertTextFormat, Range
9 from .core.registry import LspTextCommand
10 from .core.typing import Any, List, Dict, Optional, Generator, Union
11 from .core.views import FORMAT_STRING, FORMAT_MARKUP_CONTENT, minihtml
12 from .core.views import range_to_region
13 
14 
15 class LspResolveDocsCommand(LspTextCommand):
16 
17     completions = []  # type: List[Dict[str, Any]]
18 
19     def run(self, edit: sublime.Edit, index: int, event: Optional[dict] = None) -> None:
20         item = self.completions[index]
21         detail = self.format_documentation(item.get('detail') or "")
22         documentation = self.format_documentation(item.get("documentation") or "")
23         # don't show the detail in the cooperate AC popup if it is already shown in the AC details filed.
24         self.is_detail_shown = bool(detail)
25         if not detail or not documentation:
26             # To make sure that the detail or documentation fields doesn't exist we need to resove the completion item.
27             # If those fields appear after the item is resolved we show them in the popup.
28             session = self.best_session('completionProvider.resolveProvider')
29             if session:
30                 session.send_request(Request.resolveCompletionItem(item), self.handle_resolve_response)
31                 return
32         minihtml_content = self.get_content(documentation, detail)
33         self.show_popup(minihtml_content)
34 
35     def format_documentation(self, content: Union[str, Dict[str, str]]) -> str:
36         return minihtml(self.view, content, allowed_formats=FORMAT_STRING | FORMAT_MARKUP_CONTENT)
37 
38     def get_content(self, documentation: str, detail: str) -> str:
39         content = ""
40         if detail and not self.is_detail_shown:
41             content += "<div class='highlight'>{}</div>".format(detail)
42         if documentation:
43             content += "<div>{}</div>".format(documentation)
44         return content
45 
46     def show_popup(self, minihtml_content: str) -> None:
47         viewport_width = self.view.viewport_extent()[0]
48         mdpopups.show_popup(
49             self.view,
50             minihtml_content,
51             flags=sublime.COOPERATE_WITH_AUTO_COMPLETE,
52             css=css().popups,
53             wrapper_class=css().popups_classname,
54             max_width=viewport_width,
55             on_navigate=self.on_navigate
56         )
57 
58     def on_navigate(self, url: str) -> None:
59         webbrowser.open(url)
60 
61     def handle_resolve_response(self, item: Optional[dict]) -> None:
62         detail = ""
63         documentation = ""
64         if item:
65             detail = self.format_documentation(item.get('detail') or "")
66             documentation = self.format_documentation(item.get("documentation") or "")
67         if not documentation:
68             documentation = self.format_documentation({"kind": "markdown", "value": "*No documentation available.*"})
69         minihtml_content = self.get_content(documentation, detail)
70         show = self.update_popup if self.view.is_popup_visible() else self.show_popup
71         # NOTE: Update/show popups from the main thread, or else the popup might make the AC widget disappear.
72         sublime.set_timeout(lambda: show(minihtml_content))
73 
74     def update_popup(self, minihtml_content: str) -> None:
75         mdpopups.update_popup(
76             self.view,
77             minihtml_content,
78             css=css().popups,
79             wrapper_class=css().popups_classname,
80         )
81 
82 
83 class LspCompleteCommand(sublime_plugin.TextCommand):
84 
85     def epilogue(self, item: Dict[str, Any]) -> None:
86         additional_edits = item.get('additionalTextEdits')
87         if additional_edits:
88             edits = [parse_text_edit(additional_edit) for additional_edit in additional_edits]
89             self.view.run_command("lsp_apply_document_edit", {'changes': edits})
90         command = item.get("command")
91         if command:
92             debug('Running server command "{}" for view {}'.format(command, self.view.id()))
93             self.view.run_command("lsp_execute", {"command_name": command})
94 
95 
96 class LspCompleteInsertTextCommand(LspCompleteCommand):
97 
98     def run(self, edit: sublime.Edit, **item: Any) -> None:
99         insert_text = item.get("insertText") or item["label"]
100         if item.get("insertTextFormat", InsertTextFormat.PlainText) == InsertTextFormat.Snippet:
101             self.view.run_command("insert_snippet", {"contents": insert_text})
102         else:
103             self.view.run_command("insert", {"characters": insert_text})
104         self.epilogue(item)
105 
106 
107 class LspCompleteTextEditCommand(LspCompleteCommand):
108 
109     def run(self, edit: sublime.Edit, **item: Any) -> None:
110         text_edit = item["textEdit"]
111         new_text = text_edit['newText']
112         edit_region = range_to_region(Range.from_lsp(text_edit['range']), self.view)
113         if item.get("insertTextFormat", InsertTextFormat.PlainText) == InsertTextFormat.Snippet:
114             for region in self.translated_regions(edit_region):
115                 self.view.erase(edit, region)
116             self.view.run_command("insert_snippet", {"contents": new_text})
117         else:
118             for region in self.translated_regions(edit_region):
119                 # NOTE: Cannot do .replace, because ST will select the replacement.
120                 self.view.erase(edit, region)
121                 self.view.insert(edit, region.a, new_text)
122         self.epilogue(item)
123 
124     def translated_regions(self, edit_region: sublime.Region) -> Generator[sublime.Region, None, None]:
125         selection = self.view.sel()
126         primary_cursor_position = selection[0].b
127         for region in reversed(selection):
128             # For each selection region, apply the same removal as for the "primary" region.
129             # To do that, translate, or offset, the LSP edit region into the non-"primary" regions.
130             # The concept of "primary" is our own, and there is no mention of it in the LSP spec.
131             translation = region.b - primary_cursor_position
132             translated_edit_region = sublime.Region(edit_region.a + translation, edit_region.b + translation)
133             yield translated_edit_region
134 
135 
136 def resolve(completion_list: sublime.CompletionList, items: List[sublime.CompletionItem], flags: int = 0) -> None:
137     # Resolve the promise on the main thread to prevent any sort of data race for _set_target (see sublime_plugin.py).
138     sublime.set_timeout(lambda: completion_list.set_completions(items, flags))
139
```

Path: `plugin/execute_command.py`
Content:
```
1 import sublime
2 from .core.protocol import Request
3 from .core.registry import LspTextCommand
4 from .core.sessions import Session
5 from .core.typing import List, Optional, Dict, Any
6 from .core.views import uri_from_view, offset_to_point, region_to_range
7 
8 
9 class LspExecuteCommand(LspTextCommand):
10 
11     capability = 'executeCommandProvider'
12 
13     def run(self,
14             edit: sublime.Edit,
15             command_name: Optional[str] = None,
16             command_args: Optional[List[Any]] = None,
17             event: Optional[dict] = None) -> None:
18         session = self.best_session(self.capability)
19         if session and command_name:
20             window = self.view.window()
21             if window:
22                 window.status_message("Running command {}".format(command_name))
23             if command_args:
24                 self._expand_variables(command_args)
25             self._send_command(session, command_name, command_args)
26 
27     def _expand_variables(self, command_args: List[Any]) -> None:
28         region = self.view.sel()[0]
29         for i, arg in enumerate(command_args):
30             if arg in ["$file_uri", "${file_uri}"]:
31                 command_args[i] = uri_from_view(self.view)
32             elif arg in ["$selection", "${selection}"]:
33                 command_args[i] = self.view.substr(region)
34             elif arg in ["$offset", "${offset}"]:
35                 command_args[i] = region.b
36             elif arg in ["$selection_begin", "${selection_begin}"]:
37                 command_args[i] = region.begin()
38             elif arg in ["$selection_end", "${selection_end}"]:
39                 command_args[i] = region.end()
40             elif arg in ["$position", "${position}"]:
41                 command_args[i] = offset_to_point(self.view, region.b).to_lsp()
42             elif arg in ["$range", "${range}"]:
43                 command_args[i] = region_to_range(self.view, region).to_lsp()
44 
45     def _handle_response(self, command: str, response: Optional[Any]) -> None:
46         msg = "command {} completed".format(command)
47         if response:
48             msg += "with response: {}".format(response)
49 
50         window = self.view.window()
51         if window:
52             window.status_message(msg)
53 
54     def _handle_error(self, command: str, error: Dict[str, Any]) -> None:
55         msg = "command {} failed. Reason: {}".format(command, error.get("message", "none provided by server :("))
56         sublime.message_dialog(msg)
57 
58     def _send_command(self, session: Session, command_name: str, command_args: Optional[List[Any]]) -> None:
59         request = {"command": command_name, "arguments": command_args} if command_args else {"command": command_name}
60         session.send_request(Request.executeCommand(request),
61                              lambda reponse: self._handle_response(command_name, reponse),
62                              lambda error: self._handle_error(command_name, error))
63
```
--- 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/completion.py b/plugin/completion.py
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -90,7 +90,8 @@
         command = item.get("command")
         if command:
             debug('Running server command "{}" for view {}'.format(command, self.view.id()))
-            self.view.run_command("lsp_execute", {"command_name": command})
+            args = {"command_name": command["command"], "command_args": command.get("arguments")}
+            self.view.run_command("lsp_execute", args)
 
 
 class LspCompleteInsertTextCommand(LspCompleteCommand):
diff --git a/plugin/execute_command.py b/plugin/execute_command.py
--- a/plugin/execute_command.py
+++ b/plugin/execute_command.py
@@ -15,6 +15,11 @@
             command_name: Optional[str] = None,
             command_args: Optional[List[Any]] = None,
             event: Optional[dict] = None) -> None:
+        # Handle VSCode-specific command for triggering suggestions popup.
+        if command_name == "editor.action.triggerSuggest":
+            # Triggered from set_timeout as suggestions popup doesn't trigger otherwise.
+            sublime.set_timeout(lambda: self.view.run_command("auto_complete"))
+            return
         session = self.best_session(self.capability)
         if session and command_name:
             window = self.view.window()

{"golden_diff": "diff --git a/plugin/completion.py b/plugin/completion.py\n--- a/plugin/completion.py\n+++ b/plugin/completion.py\n@@ -90,7 +90,8 @@\n         command = item.get(\"command\")\n         if command:\n             debug('Running server command \"{}\" for view {}'.format(command, self.view.id()))\n-            self.view.run_command(\"lsp_execute\", {\"command_name\": command})\n+            args = {\"command_name\": command[\"command\"], \"command_args\": command.get(\"arguments\")}\n+            self.view.run_command(\"lsp_execute\", args)\n \n \n class LspCompleteInsertTextCommand(LspCompleteCommand):\ndiff --git a/plugin/execute_command.py b/plugin/execute_command.py\n--- a/plugin/execute_command.py\n+++ b/plugin/execute_command.py\n@@ -15,6 +15,11 @@\n             command_name: Optional[str] = None,\n             command_args: Optional[List[Any]] = None,\n             event: Optional[dict] = None) -> None:\n+        # Handle VSCode-specific command for triggering suggestions popup.\n+        if command_name == \"editor.action.triggerSuggest\":\n+            # Triggered from set_timeout as suggestions popup doesn't trigger otherwise.\n+            sublime.set_timeout(lambda: self.view.run_command(\"auto_complete\"))\n+            return\n         session = self.best_session(self.capability)\n         if session and command_name:\n             window = self.view.window()\n", "issue": "Triggers completion command on the wrong session\nWhen having both LSP-css and LSP-stylelint running for open file (*.css), the completions are requested from LSP-css but the `command` that the completion item triggers runs on `LSP-stylelint` triggering an error dialog.\r\n\r\nAn example completion item looks like this:\r\n```\r\n    {\r\n      \"command\": {\r\n        \"command\": \"editor.action.triggerSuggest\",\r\n        \"title\": \"Suggest\"\r\n      },\r\n      \"documentation\": {\r\n        \"kind\": \"plaintext\",\r\n        \"value\": \"Specifies the width of the content area, padding area or border area (depending on 'box-sizing') of certain boxes.\\n\\nSyntax: <viewport-length>{1,2}\\n\\nMDN Reference: https://developer.mozilla.org/docs/Web/CSS/width\"\r\n      },\r\n      \"insertTextFormat\": 2,\r\n      \"kind\": 10,\r\n      \"label\": \"width\",\r\n      \"sortText\": \"d_0000\",\r\n      \"tags\": [],\r\n      \"textEdit\": {\r\n        \"newText\": \"width: $0;\",\r\n        \"range\": {\r\n          \"end\": {\r\n            \"character\": 5,\r\n            \"line\": 4\r\n          },\r\n          \"start\": {\r\n            \"character\": 4,\r\n            \"line\": 4\r\n          }\r\n        }\r\n      }\r\n    },\r\n```\r\n\r\nIt has a `command` that runs after inserting completion.\n", "before_files": [{"content": "import mdpopups\nimport sublime\nimport sublime_plugin\nimport webbrowser\nfrom .core.css import css\nfrom .core.logging import debug\nfrom .core.edit import parse_text_edit\nfrom .core.protocol import Request, InsertTextFormat, Range\nfrom .core.registry import LspTextCommand\nfrom .core.typing import Any, List, Dict, Optional, Generator, Union\nfrom .core.views import FORMAT_STRING, FORMAT_MARKUP_CONTENT, minihtml\nfrom .core.views import range_to_region\n\n\nclass LspResolveDocsCommand(LspTextCommand):\n\n    completions = []  # type: List[Dict[str, Any]]\n\n    def run(self, edit: sublime.Edit, index: int, event: Optional[dict] = None) -> None:\n        item = self.completions[index]\n        detail = self.format_documentation(item.get('detail') or \"\")\n        documentation = self.format_documentation(item.get(\"documentation\") or \"\")\n        # don't show the detail in the cooperate AC popup if it is already shown in the AC details filed.\n        self.is_detail_shown = bool(detail)\n        if not detail or not documentation:\n            # To make sure that the detail or documentation fields doesn't exist we need to resove the completion item.\n            # If those fields appear after the item is resolved we show them in the popup.\n            session = self.best_session('completionProvider.resolveProvider')\n            if session:\n                session.send_request(Request.resolveCompletionItem(item), self.handle_resolve_response)\n                return\n        minihtml_content = self.get_content(documentation, detail)\n        self.show_popup(minihtml_content)\n\n    def format_documentation(self, content: Union[str, Dict[str, str]]) -> str:\n        return minihtml(self.view, content, allowed_formats=FORMAT_STRING | FORMAT_MARKUP_CONTENT)\n\n    def get_content(self, documentation: str, detail: str) -> str:\n        content = \"\"\n        if detail and not self.is_detail_shown:\n            content += \"<div class='highlight'>{}</div>\".format(detail)\n        if documentation:\n            content += \"<div>{}</div>\".format(documentation)\n        return content\n\n    def show_popup(self, minihtml_content: str) -> None:\n        viewport_width = self.view.viewport_extent()[0]\n        mdpopups.show_popup(\n            self.view,\n            minihtml_content,\n            flags=sublime.COOPERATE_WITH_AUTO_COMPLETE,\n            css=css().popups,\n            wrapper_class=css().popups_classname,\n            max_width=viewport_width,\n            on_navigate=self.on_navigate\n        )\n\n    def on_navigate(self, url: str) -> None:\n        webbrowser.open(url)\n\n    def handle_resolve_response(self, item: Optional[dict]) -> None:\n        detail = \"\"\n        documentation = \"\"\n        if item:\n            detail = self.format_documentation(item.get('detail') or \"\")\n            documentation = self.format_documentation(item.get(\"documentation\") or \"\")\n        if not documentation:\n            documentation = self.format_documentation({\"kind\": \"markdown\", \"value\": \"*No documentation available.*\"})\n        minihtml_content = self.get_content(documentation, detail)\n        show = self.update_popup if self.view.is_popup_visible() else self.show_popup\n        # NOTE: Update/show popups from the main thread, or else the popup might make the AC widget disappear.\n        sublime.set_timeout(lambda: show(minihtml_content))\n\n    def update_popup(self, minihtml_content: str) -> None:\n        mdpopups.update_popup(\n            self.view,\n            minihtml_content,\n            css=css().popups,\n            wrapper_class=css().popups_classname,\n        )\n\n\nclass LspCompleteCommand(sublime_plugin.TextCommand):\n\n    def epilogue(self, item: Dict[str, Any]) -> None:\n        additional_edits = item.get('additionalTextEdits')\n        if additional_edits:\n            edits = [parse_text_edit(additional_edit) for additional_edit in additional_edits]\n            self.view.run_command(\"lsp_apply_document_edit\", {'changes': edits})\n        command = item.get(\"command\")\n        if command:\n            debug('Running server command \"{}\" for view {}'.format(command, self.view.id()))\n            self.view.run_command(\"lsp_execute\", {\"command_name\": command})\n\n\nclass LspCompleteInsertTextCommand(LspCompleteCommand):\n\n    def run(self, edit: sublime.Edit, **item: Any) -> None:\n        insert_text = item.get(\"insertText\") or item[\"label\"]\n        if item.get(\"insertTextFormat\", InsertTextFormat.PlainText) == InsertTextFormat.Snippet:\n            self.view.run_command(\"insert_snippet\", {\"contents\": insert_text})\n        else:\n            self.view.run_command(\"insert\", {\"characters\": insert_text})\n        self.epilogue(item)\n\n\nclass LspCompleteTextEditCommand(LspCompleteCommand):\n\n    def run(self, edit: sublime.Edit, **item: Any) -> None:\n        text_edit = item[\"textEdit\"]\n        new_text = text_edit['newText']\n        edit_region = range_to_region(Range.from_lsp(text_edit['range']), self.view)\n        if item.get(\"insertTextFormat\", InsertTextFormat.PlainText) == InsertTextFormat.Snippet:\n            for region in self.translated_regions(edit_region):\n                self.view.erase(edit, region)\n            self.view.run_command(\"insert_snippet\", {\"contents\": new_text})\n        else:\n            for region in self.translated_regions(edit_region):\n                # NOTE: Cannot do .replace, because ST will select the replacement.\n                self.view.erase(edit, region)\n                self.view.insert(edit, region.a, new_text)\n        self.epilogue(item)\n\n    def translated_regions(self, edit_region: sublime.Region) -> Generator[sublime.Region, None, None]:\n        selection = self.view.sel()\n        primary_cursor_position = selection[0].b\n        for region in reversed(selection):\n            # For each selection region, apply the same removal as for the \"primary\" region.\n            # To do that, translate, or offset, the LSP edit region into the non-\"primary\" regions.\n            # The concept of \"primary\" is our own, and there is no mention of it in the LSP spec.\n            translation = region.b - primary_cursor_position\n            translated_edit_region = sublime.Region(edit_region.a + translation, edit_region.b + translation)\n            yield translated_edit_region\n\n\ndef resolve(completion_list: sublime.CompletionList, items: List[sublime.CompletionItem], flags: int = 0) -> None:\n    # Resolve the promise on the main thread to prevent any sort of data race for _set_target (see sublime_plugin.py).\n    sublime.set_timeout(lambda: completion_list.set_completions(items, flags))\n", "path": "plugin/completion.py"}, {"content": "import sublime\nfrom .core.protocol import Request\nfrom .core.registry import LspTextCommand\nfrom .core.sessions import Session\nfrom .core.typing import List, Optional, Dict, Any\nfrom .core.views import uri_from_view, offset_to_point, region_to_range\n\n\nclass LspExecuteCommand(LspTextCommand):\n\n    capability = 'executeCommandProvider'\n\n    def run(self,\n            edit: sublime.Edit,\n            command_name: Optional[str] = None,\n            command_args: Optional[List[Any]] = None,\n            event: Optional[dict] = None) -> None:\n        session = self.best_session(self.capability)\n        if session and command_name:\n            window = self.view.window()\n            if window:\n                window.status_message(\"Running command {}\".format(command_name))\n            if command_args:\n                self._expand_variables(command_args)\n            self._send_command(session, command_name, command_args)\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 [\"$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\n    def _handle_response(self, command: str, response: Optional[Any]) -> None:\n        msg = \"command {} completed\".format(command)\n        if response:\n            msg += \"with response: {}\".format(response)\n\n        window = self.view.window()\n        if window:\n            window.status_message(msg)\n\n    def _handle_error(self, command: str, error: Dict[str, Any]) -> None:\n        msg = \"command {} failed. Reason: {}\".format(command, error.get(\"message\", \"none provided by server :(\"))\n        sublime.message_dialog(msg)\n\n    def _send_command(self, session: Session, command_name: str, command_args: Optional[List[Any]]) -> None:\n        request = {\"command\": command_name, \"arguments\": command_args} if command_args else {\"command\": command_name}\n        session.send_request(Request.executeCommand(request),\n                             lambda reponse: self._handle_response(command_name, reponse),\n                             lambda error: self._handle_error(command_name, error))\n", "path": "plugin/execute_command.py"}], "after_files": [{"content": "import mdpopups\nimport sublime\nimport sublime_plugin\nimport webbrowser\nfrom .core.css import css\nfrom .core.logging import debug\nfrom .core.edit import parse_text_edit\nfrom .core.protocol import Request, InsertTextFormat, Range\nfrom .core.registry import LspTextCommand\nfrom .core.typing import Any, List, Dict, Optional, Generator, Union\nfrom .core.views import FORMAT_STRING, FORMAT_MARKUP_CONTENT, minihtml\nfrom .core.views import range_to_region\n\n\nclass LspResolveDocsCommand(LspTextCommand):\n\n    completions = []  # type: List[Dict[str, Any]]\n\n    def run(self, edit: sublime.Edit, index: int, event: Optional[dict] = None) -> None:\n        item = self.completions[index]\n        detail = self.format_documentation(item.get('detail') or \"\")\n        documentation = self.format_documentation(item.get(\"documentation\") or \"\")\n        # don't show the detail in the cooperate AC popup if it is already shown in the AC details filed.\n        self.is_detail_shown = bool(detail)\n        if not detail or not documentation:\n            # To make sure that the detail or documentation fields doesn't exist we need to resove the completion item.\n            # If those fields appear after the item is resolved we show them in the popup.\n            session = self.best_session('completionProvider.resolveProvider')\n            if session:\n                session.send_request(Request.resolveCompletionItem(item), self.handle_resolve_response)\n                return\n        minihtml_content = self.get_content(documentation, detail)\n        self.show_popup(minihtml_content)\n\n    def format_documentation(self, content: Union[str, Dict[str, str]]) -> str:\n        return minihtml(self.view, content, allowed_formats=FORMAT_STRING | FORMAT_MARKUP_CONTENT)\n\n    def get_content(self, documentation: str, detail: str) -> str:\n        content = \"\"\n        if detail and not self.is_detail_shown:\n            content += \"<div class='highlight'>{}</div>\".format(detail)\n        if documentation:\n            content += \"<div>{}</div>\".format(documentation)\n        return content\n\n    def show_popup(self, minihtml_content: str) -> None:\n        viewport_width = self.view.viewport_extent()[0]\n        mdpopups.show_popup(\n            self.view,\n            minihtml_content,\n            flags=sublime.COOPERATE_WITH_AUTO_COMPLETE,\n            css=css().popups,\n            wrapper_class=css().popups_classname,\n            max_width=viewport_width,\n            on_navigate=self.on_navigate\n        )\n\n    def on_navigate(self, url: str) -> None:\n        webbrowser.open(url)\n\n    def handle_resolve_response(self, item: Optional[dict]) -> None:\n        detail = \"\"\n        documentation = \"\"\n        if item:\n            detail = self.format_documentation(item.get('detail') or \"\")\n            documentation = self.format_documentation(item.get(\"documentation\") or \"\")\n        if not documentation:\n            documentation = self.format_documentation({\"kind\": \"markdown\", \"value\": \"*No documentation available.*\"})\n        minihtml_content = self.get_content(documentation, detail)\n        show = self.update_popup if self.view.is_popup_visible() else self.show_popup\n        # NOTE: Update/show popups from the main thread, or else the popup might make the AC widget disappear.\n        sublime.set_timeout(lambda: show(minihtml_content))\n\n    def update_popup(self, minihtml_content: str) -> None:\n        mdpopups.update_popup(\n            self.view,\n            minihtml_content,\n            css=css().popups,\n            wrapper_class=css().popups_classname,\n        )\n\n\nclass LspCompleteCommand(sublime_plugin.TextCommand):\n\n    def epilogue(self, item: Dict[str, Any]) -> None:\n        additional_edits = item.get('additionalTextEdits')\n        if additional_edits:\n            edits = [parse_text_edit(additional_edit) for additional_edit in additional_edits]\n            self.view.run_command(\"lsp_apply_document_edit\", {'changes': edits})\n        command = item.get(\"command\")\n        if command:\n            debug('Running server command \"{}\" for view {}'.format(command, self.view.id()))\n            args = {\"command_name\": command[\"command\"], \"command_args\": command.get(\"arguments\")}\n            self.view.run_command(\"lsp_execute\", args)\n\n\nclass LspCompleteInsertTextCommand(LspCompleteCommand):\n\n    def run(self, edit: sublime.Edit, **item: Any) -> None:\n        insert_text = item.get(\"insertText\") or item[\"label\"]\n        if item.get(\"insertTextFormat\", InsertTextFormat.PlainText) == InsertTextFormat.Snippet:\n            self.view.run_command(\"insert_snippet\", {\"contents\": insert_text})\n        else:\n            self.view.run_command(\"insert\", {\"characters\": insert_text})\n        self.epilogue(item)\n\n\nclass LspCompleteTextEditCommand(LspCompleteCommand):\n\n    def run(self, edit: sublime.Edit, **item: Any) -> None:\n        text_edit = item[\"textEdit\"]\n        new_text = text_edit['newText']\n        edit_region = range_to_region(Range.from_lsp(text_edit['range']), self.view)\n        if item.get(\"insertTextFormat\", InsertTextFormat.PlainText) == InsertTextFormat.Snippet:\n            for region in self.translated_regions(edit_region):\n                self.view.erase(edit, region)\n            self.view.run_command(\"insert_snippet\", {\"contents\": new_text})\n        else:\n            for region in self.translated_regions(edit_region):\n                # NOTE: Cannot do .replace, because ST will select the replacement.\n                self.view.erase(edit, region)\n                self.view.insert(edit, region.a, new_text)\n        self.epilogue(item)\n\n    def translated_regions(self, edit_region: sublime.Region) -> Generator[sublime.Region, None, None]:\n        selection = self.view.sel()\n        primary_cursor_position = selection[0].b\n        for region in reversed(selection):\n            # For each selection region, apply the same removal as for the \"primary\" region.\n            # To do that, translate, or offset, the LSP edit region into the non-\"primary\" regions.\n            # The concept of \"primary\" is our own, and there is no mention of it in the LSP spec.\n            translation = region.b - primary_cursor_position\n            translated_edit_region = sublime.Region(edit_region.a + translation, edit_region.b + translation)\n            yield translated_edit_region\n\n\ndef resolve(completion_list: sublime.CompletionList, items: List[sublime.CompletionItem], flags: int = 0) -> None:\n    # Resolve the promise on the main thread to prevent any sort of data race for _set_target (see sublime_plugin.py).\n    sublime.set_timeout(lambda: completion_list.set_completions(items, flags))\n", "path": "plugin/completion.py"}, {"content": "import sublime\nfrom .core.protocol import Request\nfrom .core.registry import LspTextCommand\nfrom .core.sessions import Session\nfrom .core.typing import List, Optional, Dict, Any\nfrom .core.views import uri_from_view, offset_to_point, region_to_range\n\n\nclass LspExecuteCommand(LspTextCommand):\n\n    capability = 'executeCommandProvider'\n\n    def run(self,\n            edit: sublime.Edit,\n            command_name: Optional[str] = None,\n            command_args: Optional[List[Any]] = None,\n            event: Optional[dict] = None) -> None:\n        # Handle VSCode-specific command for triggering suggestions popup.\n        if command_name == \"editor.action.triggerSuggest\":\n            # Triggered from set_timeout as suggestions popup doesn't trigger otherwise.\n            sublime.set_timeout(lambda: self.view.run_command(\"auto_complete\"))\n            return\n        session = self.best_session(self.capability)\n        if session and command_name:\n            window = self.view.window()\n            if window:\n                window.status_message(\"Running command {}\".format(command_name))\n            if command_args:\n                self._expand_variables(command_args)\n            self._send_command(session, command_name, command_args)\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 [\"$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\n    def _handle_response(self, command: str, response: Optional[Any]) -> None:\n        msg = \"command {} completed\".format(command)\n        if response:\n            msg += \"with response: {}\".format(response)\n\n        window = self.view.window()\n        if window:\n            window.status_message(msg)\n\n    def _handle_error(self, command: str, error: Dict[str, Any]) -> None:\n        msg = \"command {} failed. Reason: {}\".format(command, error.get(\"message\", \"none provided by server :(\"))\n        sublime.message_dialog(msg)\n\n    def _send_command(self, session: Session, command_name: str, command_args: Optional[List[Any]]) -> None:\n        request = {\"command\": command_name, \"arguments\": command_args} if command_args else {\"command\": command_name}\n        session.send_request(Request.executeCommand(request),\n                             lambda reponse: self._handle_response(command_name, reponse),\n                             lambda error: self._handle_error(command_name, error))\n", "path": "plugin/execute_command.py"}]}