redhat-developer / vscode-rsp-ui

A unified UI for all RSP servers and RSP server-providers to integrate with
Eclipse Public License 2.0
38 stars 21 forks source link

unable to invoke rsp commands directly #294

Closed dangerusty closed 11 months ago

dangerusty commented 11 months ago

I'm setting up a devcontainer, and looking into managing Tomcat using RSP-UI via Community Server Connector. I've added a server.json file to ~/.rsp/redhat-community-server-connector/servers/, so it is added automatically. To start the server automatically, I was hoping to have a start up task (tasks.json) where the server.start command is invoked directly.

When I try to invoke something like "server.start", I'm struggling with which arguments are needed for success. Is this possible? Can an arguments example be provided?

Here is my guess so far on some of the inputs. I'm currently stuck on some object missing when reading 'state': image

{
    "version": "2.0.0",
    "tasks": [
       {
          "label": "startTomcat",
          "command": "${input:startTomcatInput}",
        },
     ],
    "inputs": [
      {
        "id": "startTomcatInput",
        "type": "command",
        "command": "server.start",
        "args": {
          "server": {
            "type": {
              "id": "redhat.vscode-community-server-connector"
            }
          },
          "context": {
            "server": {
              "id": "Tomcat"
            }
          }
        }
      },
  ]
}
robstryker commented 11 months ago

If we look here: https://github.com/redhat-developer/vscode-rsp-ui/blob/main/src/extensionApi.ts#L150

It appears the command accepts an argument called mode, which is either "run" or "debug". It also accepts a context, which is a ServerStateNode object.


export interface ServerStateNode {
    rsp: string;
    server: Protocol.ServerHandle;
    state: number;
    publishState: number;
    runMode: string;
    deployableStates: DeployableStateNode[];
}

    interface ServerHandle {
        id: string;
        type: ServerType;
    }

export interface DeployableStateNode {
    rsp: string;
    server: Protocol.ServerHandle;
    reference: Protocol.DeployableReference;
    state: number;
    publishState: number;
}

    interface DeployableReference {
        label: string;
        path: string;
        options?: {
            [index: string]: any;
        };
    }

However, it seems we only really call context.rsp, context.server.id, and context.server.type.id of the passed-in context.

The rsp attribute should have a value of redhat.vscode-community-server-connector.

The server.id attribute should have a value of Tomcat or the name of the server as you've declared it.

The server.type.id attribute should have a value of something like org.jboss.ide.eclipse.as.server.tomcat.55 with the suffix adjusted for adapter version type. You can find this value by right-clicking on your desired server and selecting Edit Server... and seeing what value is stored in the org.jboss.tools.rsp.server.typeId attribute.

I don't have any working examples of trying to launch a command in this way, but I can look into it when I have some time. For now, give this a try and see if it works at all.

robstryker commented 11 months ago

I've managed to get this to work as code, but not sure how it would be used in a tasks file as you're doing. Still, this is a good start.

        const context: ServerStateNode = {
            rsp: "redhat.vscode-community-server-connector",
            server: {
                id: "apache-tomcat-5.5.36",
                type: {
                    id: "org.jboss.ide.eclipse.as.server.tomcat.55",
                    description: "",
                    visibleName: ""
                }
            },
            state: 0,
            publishState: 0,
            runMode: 'run',
            deployableStates: []
        };

        vscode.commands.executeCommand("server.start", context);

Hopefully this helps you.

dangerusty commented 11 months ago

Thank you, that worked!

{ "version": "2.0.0", "tasks": [ { "label": "startTomcat", "command": "${input:startTomcatInput}" } ], "inputs": [ { "id": "startTomcatInput", "type": "command", "command": "server.start", "args": { "rsp": "redhat.vscode-community-server-connector", "server": { "id": "Tomcat", "type": { "id": "org.jboss.ide.eclipse.as.server.tomcat.90", "description": "", "visibleName": "" } }, "state": 0, "publishState": 0, "runMode": "run", "deployableStates": [] } } ] }

robstryker commented 11 months ago

Glad this was able to help!