Repository: sublimelsp/LSP

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.


Discussion:
Even if this is fixed and command runs on the correct session, the `executCommand` will probably still fail as it seems like the intention here is for the editor (VSCode specifically) to intercept that command and trigger completions popup again
So a related question is: do we want to special case `editor.action.triggerSuggest` command in LSP to trigger completion popup (not sure if we are even able to do that)?

Relevant vscode code: https://github.com/microsoft/vscode/blob/45b2a7e10243677801dc9da34a464b1a15f5df57/src/vs/editor/contrib/suggest/suggestController.ts#L297-L312
Maybe we need a mapping from command names that start with `editor.` to ST commands? And then run the ST command instead of a server command.
Sure.

I guess LSP could trigger any [VSCode editor action](https://github.com/microsoft/vscode/search?q=extends+EditorAction&unscoped_q=extends+EditorAction), but hopefully, it's not that many we have to care about.

EDIT: Nah, probably it's just that one since it's special-cased in suggestController like my previous link shows.
@rwols let's just keep it simple and just handle that single one for now, as their suggestController does. There is not necessarily gonna be any other to care about.

Resolving patch:
diff --git a/plugin/completion.py b/plugin/completion.py
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -90,7 +90,8 @@ def epilogue(self, item: Dict[str, Any]) -> None:
         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 @@ def run(self,
             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()


Test patch: