Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node debug attach processId property not accepting custom commands #65566

Closed
JohnsonMG opened this issue Dec 21, 2018 · 8 comments
Closed

Node debug attach processId property not accepting custom commands #65566

JohnsonMG opened this issue Dec 21, 2018 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Milestone

Comments

@JohnsonMG
Copy link

JohnsonMG commented Dec 21, 2018

I am using PM2 to run many node processes and want to setup a debug configuration to attach to running processes that were not started in debug mode. As recommended in this feature request I created my own extension to handle this with a custom command that allows me to select a pid from a dropdown.

No matter how simple I make the command however, even just returning a string synchronously, I get the following error:
image

I have tested this command with other debug configurations (e.g. chrome debugger) and it works totally fine, processId seems to have some type validation which is rejecting it.

Extension package.json

    "name": "pm2support",
    "displayName": "pm2Support",
    "description": "Support for pm2 processes",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.30.0"
    },
    "categories": [
        "Other"
    ],
    "activationEvents": [
        "onCommand:pm2Support.getPids"
    ],
    "main": "./out/extension",
    "contributes": {
        "commands": [{
            "command": "pm2Support.getPids",
            "title": "Get pm2 pids"
        }],
        "debuggers": [
          {
            "type": "node",
            "variables": {
              "PickPm2Process": "pm2Support.getPids"
            }
          },
          {
            "type": "chrome",
            "variables": {
              "PickPm2Process": "pm2Support.getPids"
            }
          }
        ]
    },
    "scripts": {
        "vscode:prepublish": "yarn run compile",
        "compile": "tsc -p ./",
        "watch": "tsc -watch -p ./",
        "postinstall": "node ./node_modules/vscode/bin/install",
        "test": "yarn run compile && node ./node_modules/vscode/bin/test"
    },
    "devDependencies": {
        "typescript": "^3.1.4",
        "vscode": "^1.1.25",
        "tslint": "^5.8.0",
        "@types/node": "^8.10.25",
        "@types/mocha": "^2.2.42"
    }
}

extension.ts:

'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import * as fs from 'fs';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
    // The command has been defined in the package.json file
    // Now provide the implementation of the command with  registerCommand
    // The commandId parameter must match the command field in package.json
    context.subscriptions.push(vscode.commands.registerCommand('pm2Support.getPids', async ():Promise<string> => {
        // The code you place here will be executed every time your command is executed

        let pidOptions: vscode.QuickPickItem[] = [];
        var pidFiles = fs.readdirSync('/Users/gavinjohnson/.pm2/pids');

        // Pull pids from files
        pidFiles.forEach(path => {
          var contents = fs.readFileSync('/Users/gavinjohnson/.pm2/pids/' + path);
          pidOptions.push({
            label: path,
            detail: contents.toString(),
          });
        });
        
         let pickPromise = vscode.window.showQuickPick(pidOptions);
         let pid = await pickPromise.then(pick => {
            if(pick !== undefined) {
              return String(pick.detail);
            } else {
              return "";
            }
         });
         vscode.window.showInformationMessage(pid);
         return pid;
       }));
}

// this method is called when your extension is deactivated
export function deactivate() {
}

launch.json:

{
      "type": "node",
      "request": "attach",
      "name": "Attach to Process",
      "processId": "${command:PickPm2Process}"
    },

code --version :
1.30.1
dea8705
x64

node -v:
v8.11.3

ProductName: Mac OS X
ProductVersion: 10.14.2
BuildVersion: 18C54

@isidorn isidorn assigned weinand and unassigned isidorn Dec 21, 2018
@isidorn isidorn added the debug Debug viewlet, configurations, breakpoints, adapter issues label Dec 21, 2018
@weinand
Copy link
Contributor

weinand commented Jan 25, 2019

@JohnsonMG does it work if you use the command ID directly?
e.g.

{
      "type": "node",
      "request": "attach",
      "name": "Attach to Process",
      "processId": "${command:pm2Support.getPids}"
},

@weinand weinand added the info-needed Issue requires more information from poster label Jan 25, 2019
@JohnsonMG
Copy link
Author

JohnsonMG commented Jan 25, 2019

@JohnsonMG does it work if you use the command ID directly?
e.g.

{
      "type": "node",
      "request": "attach",
      "name": "Attach to Process",
      "processId": "${command:pm2Support.getPids}"
},

Using the command ID directly results in the same error message.
I am happy to supply more information, if you could let me know exactly what information is missing.

Do commands work for you in the processId field? I can't seem to use any commands (apart from PickProcess), let alone my custom one.

Like I stated in my original post, the command works for other fields. e.g. I can use it successfully with the "port" parameter. It seems like the processId field specifically has some validation which rejects commands.

@JohnsonMG
Copy link
Author

@weinand Does this still need more information? Please advise on what you would like if so.

@JohnsonMG
Copy link
Author

JohnsonMG commented Jan 30, 2020

@weinand Since there has been no movement on this I decided to poke around and found this:
https://github.com/microsoft/vscode-node-debug/blob/3bb7e131ba706ecb70bd9ae68e6994256c0e4f2a/src/node/extension/processPicker.ts#L49

It looks like the attach handler has hardcoded in a check for the string '${command:PickProcess}' rather than running any passed in command.

For anyone attempting to do something similar, I got around this by having my custom extension just start a debugging session itself, rather than resolving a string.

const config: vscode.DebugConfiguration = {
            "type": "node",
            "request": "attach",
            "name": "Attach to PM2 ProcessId",
            "processId": pick.detail,
          };

          vscode.debug.startDebugging(undefined, config).then(...

Where pick.detail is the showQuickPick result

Now instead of starting a debug session, I just run my command from the palette and the debugger attaches automatically.

@weinand
Copy link
Contributor

weinand commented Jan 30, 2020

The hardcoded check for '${command:PickProcess}' will become obsolete in the January release when we release the new 'resolveDebugConfigurationWithSubstitutedVariables' hook that provides access to substituted variables. Please see #87450.

@vscodebot vscodebot bot closed this as completed Feb 14, 2020
@vscodebot
Copy link

vscodebot bot commented Feb 14, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@weinand weinand reopened this Feb 14, 2020
@weinand weinand added this to the February 2020 milestone Feb 14, 2020
@vscodebot vscodebot bot closed this as completed Feb 21, 2020
@weinand weinand reopened this Feb 21, 2020
@microsoft microsoft deleted a comment from vscodebot bot Feb 21, 2020
@weinand weinand added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Feb 21, 2020
@weinand weinand modified the milestones: February 2020, March 2020 Feb 24, 2020
@weinand
Copy link
Contributor

weinand commented Mar 3, 2020

@connor4312 I have removed the code that resolves command variables (e.g. the process picker) in resolveDebugConfiguration and now let VS Code do the resolving. This makes it possible to use any command variable for the processId attribute.

connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Mar 5, 2020
@connor4312
Copy link
Member

Sounds good, updated js-debug similarly.

connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Mar 5, 2020
@connor4312 connor4312 added the verified Verification succeeded label Apr 2, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants