Suzy Mueller has uploaded this change for review.
src/pickProcess.ts: add linux cmd for go process
Add a command that allows the user to pick between
processes that are running Go. This implementation
is only available on linux for now.
Change-Id: Ic7c6e76258cfdeec014021895d447cc826082d53
---
M package-lock.json
M package.json
M src/goMain.ts
M src/pickProcess.ts
M src/utils/psProcessParser.ts
5 files changed, 83 insertions(+), 13 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index acd2d31..79eb5d6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "go",
- "version": "0.21.0-dev",
+ "version": "0.22.0-dev",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index a46cc30..d75e7f9 100644
--- a/package.json
+++ b/package.json
@@ -432,7 +432,8 @@
"go"
],
"variables": {
- "pickProcess": "go.debug.pickProcess"
+ "pickProcess": "go.debug.pickProcess",
+ "pickGoProcess": "go.debug.pickGoProcess"
},
"configurationSnippets": [
{
@@ -721,17 +722,18 @@
"processId": {
"anyOf": [
{
- "enum": [
- "${command:pickProcess}"
- ],
- "description": "Use process picker to select a process to attach, or Process ID as integer.",
- "default": "${command:pickProcess}"
+ "enum": [
+ "${command:pickProcess}",
+ "${command:pickGoProcess}"
+ ],
+ "description": "Use process picker to select a process to attach, or Process ID as integer.",
+ "default": "${command:pickProcess}"
},
{
- "type": "number",
- "description": "The ID of the process to be debugged."
+ "type": "number",
+ "description": "The ID of the process to be debugged."
}
- ]
+ ]
},
"mode": {
"enum": [
diff --git a/src/goMain.ts b/src/goMain.ts
index 890a324..49b3343 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -52,7 +52,7 @@
import { subTestAtCursor, testAtCursor, testCurrentFile, testCurrentPackage, testPrevious, testWorkspace } from './goTest';
import { getConfiguredTools } from './goTools';
import { vetCode } from './goVet';
-import { pickProcess } from './pickProcess';
+import { pickGoProcess, pickProcess } from './pickProcess';
import {
getFromGlobalState,
getFromWorkspaceState,
@@ -192,6 +192,10 @@
vscode.commands.registerCommand('go.debug.pickProcess', async (): Promise<string> => {
return await pickProcess();
}));
+ ctx.subscriptions.push(
+ vscode.commands.registerCommand('go.debug.pickGoProcess', async (): Promise<string> => {
+ return await pickGoProcess();
+ }));
buildDiagnosticCollection = vscode.languages.createDiagnosticCollection('go');
ctx.subscriptions.push(buildDiagnosticCollection);
diff --git a/src/pickProcess.ts b/src/pickProcess.ts
index 2eea995..f17815b 100644
--- a/src/pickProcess.ts
+++ b/src/pickProcess.ts
@@ -7,14 +7,29 @@
import util = require('util');
import { QuickPickItem } from 'vscode';
import vscode = require('vscode');
+import { toolExecutionEnvironment } from './goEnv';
+import { getBinPath, getWorkspaceFolderPath } from './util';
+import { envPath, getCurrentGoRoot } from './utils/pathUtils';
import { parsePsProcesses, psDarwinCommand, psLinuxCommand } from './utils/psProcessParser';
import { parseWmicProcesses, wmicCommand } from './utils/wmicProcessParser';
// TODO(suzmue): create a command pickGoProcess to filter
// to processes that are using go.
export async function pickProcess(): Promise<string> {
+ const allProcesses = await getAllProcesses();
+ const id = await processPicker(allProcesses);
+ return id;
+}
+
+export async function pickGoProcess(): Promise<string> {
+ const allProcesses = await getGoProcesses();
+ const id = await processPicker(allProcesses);
+ return id;
+}
+
+async function processPicker(processes: AttachItem[]): Promise<string> {
const selection = await vscode.window.showQuickPick(
- getAllProcesses(),
+ processes,
{
placeHolder: 'Choose a process to attach to',
matchOnDescription: true,
@@ -34,6 +49,7 @@
id: string;
processName: string;
commandLine: string;
+ executable?: string;
isGo?: boolean;
}
@@ -42,6 +58,50 @@
args: string[];
}
+async function getGoProcesses(): Promise<AttachItem[]> {
+ const processes = await getAllProcesses();
+ // TODO(suzmue): set the executable path for win32 and darwin.
+ if (process.platform !== 'linux') {
+ return processes;
+ }
+
+ // Run 'go version' on all of /proc/${pid}/exe to find 'go' processes
+ const goRuntimePath = getBinPath('go');
+ if (!goRuntimePath) {
+ vscode.window.showErrorMessage(
+ `Failed to run "go version" as the "go" binary cannot be found in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath})`
+ );
+ return processes;
+ }
+ const args = ['version'];
+ processes.forEach((item, i) => {
+ args.push(item.executable);
+ });
+ const {stdout} = cp.spawnSync(goRuntimePath, args, { env: toolExecutionEnvironment(), cwd: getWorkspaceFolderPath() });
+
+ // Parse the process ids from stdout. Ignore stderr, since we expect many to fail.
+ const goProcessExes: string[] = [];
+ const lines = stdout.toString().split('\n');
+
+ const goVersionRegexp = /: go\d+.\d+.\d+$/;
+ lines.forEach((line) => {
+ const match = line.match(goVersionRegexp);
+ if (match && match.length > 0) {
+ const exe = line.substr(0, line.length - match[0].length);
+ goProcessExes.push(exe);
+ }
+ });
+
+ const goProcesses: AttachItem[] = [];
+ processes.forEach((item) => {
+ if (goProcessExes.indexOf(item.id) >= 0) {
+ item.isGo = true;
+ goProcesses.push(item);
+ }
+ });
+ return goProcesses;
+}
+
async function getAllProcesses(): Promise<AttachItem[]> {
let processCmd: ProcessListCommand;
switch (process.platform) {
diff --git a/src/utils/psProcessParser.ts b/src/utils/psProcessParser.ts
index 06a9984..714caa3 100644
--- a/src/utils/psProcessParser.ts
+++ b/src/utils/psProcessParser.ts
@@ -93,7 +93,7 @@
const executable = matches[2].trim();
const cmdline = matches[3].trim();
- return {
+ const attachItem: AttachItem = {
label: executable,
description: pid,
detail: cmdline,
@@ -101,5 +101,9 @@
processName: executable,
commandLine: cmdline
};
+ if (process.platform === 'linux') {
+ attachItem.executable = `/proc/${pid}/exe`;
+ }
+ return attachItem;
}
}
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Suzy Mueller.
Kokoro presubmit build finished with status: FAILURE
Logs at: https://source.cloud.google.com/results/invocations/92acbd5e-dd57-4dfe-a039-b2c707be2dba
Patch set 1:TryBot-Result -1
Attention is currently required from: Hyang-Ah Hana Kim.
Suzy Mueller uploaded patch set #2 to this change.
src/pickProcess.ts: add linux cmd for go process
Add a command that allows the user to pick between
processes that are running Go. This implementation
is only available on linux for now.
Change-Id: Ic7c6e76258cfdeec014021895d447cc826082d53
---
M package-lock.json
M package.json
M src/goMain.ts
M src/pickProcess.ts
M src/utils/psProcessParser.ts
5 files changed, 83 insertions(+), 13 deletions(-)
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim.
Suzy Mueller uploaded patch set #3 to this change.
src/pickProcess.ts: add linux cmd for go process
Add a command that allows the user to pick between
processes that are running Go. This implementation
is only available on linux for now.
Change-Id: Ic7c6e76258cfdeec014021895d447cc826082d53
---
M package-lock.json
M package.json
M src/goMain.ts
M src/pickProcess.ts
M src/utils/psProcessParser.ts
5 files changed, 83 insertions(+), 15 deletions(-)
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim.
Suzy Mueller uploaded patch set #4 to this change.
src/pickProcess.ts: add linux cmd for go process
Add a command that allows the user to pick between
processes that are running Go. This implementation
is only available on linux for now.
Change-Id: Ic7c6e76258cfdeec014021895d447cc826082d53
---
M package-lock.json
M package.json
M src/goMain.ts
M src/pickProcess.ts
M src/utils/psProcessParser.ts
5 files changed, 83 insertions(+), 13 deletions(-)
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Suzy Mueller.
Patch set 4:Code-Review +2
1 comment:
Patchset:
How do other extensions present this pick process functionality?
I wonder if they have filtering based on the executable name.
BTW, add the link to the issue in the commit message.
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Suzy Mueller.
Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/976963e6-8f36-4db2-a60d-0f4984192f02
Patch set 4:TryBot-Result +1
Attention is currently required from: Suzy Mueller.
Suzy Mueller uploaded patch set #5 to this change.
src/pickProcess.ts: add linux cmd for go process
Add a command that allows the user to pick between
processes that are running Go. This implementation
is only available on linux for now.
Updates golang/vscode-go#183
Change-Id: Ic7c6e76258cfdeec014021895d447cc826082d53
---
M package-lock.json
M package.json
M src/goMain.ts
M src/pickProcess.ts
M src/utils/psProcessParser.ts
5 files changed, 83 insertions(+), 13 deletions(-)
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
How do other extensions present this pick process functionality? […]
I haven't looked at many extensions to see, just python. In the quickPick once you start typing it filters, so although there are an overwhelming number of processes, you don't have to scroll through them.
And done :)
To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.
Suzy Mueller submitted this change.
src/pickProcess.ts: add linux cmd for go process
Add a command that allows the user to pick between
processes that are running Go. This implementation
is only available on linux for now.
Updates golang/vscode-go#183
Change-Id: Ic7c6e76258cfdeec014021895d447cc826082d53
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/287872
Trust: Suzy Mueller <suz...@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hya...@gmail.com>
---
M package-lock.json
M package.json
M src/goMain.ts
M src/pickProcess.ts
M src/utils/psProcessParser.ts
5 files changed, 83 insertions(+), 13 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index acd2d31..79eb5d6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "go",
- "version": "0.21.0-dev",
+ "version": "0.22.0-dev",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index cbe80b5..e2fbc4f 100644index 32eafe8..58aecae 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -52,7 +52,7 @@
import { subTestAtCursor, testAtCursor, testCurrentFile, testCurrentPackage, testPrevious, testWorkspace } from './goTest';
import { getConfiguredTools } from './goTools';
import { vetCode } from './goVet';
-import { pickProcess } from './pickProcess';
+import { pickGoProcess, pickProcess } from './pickProcess';
import {
getFromGlobalState,
getFromWorkspaceState,
@@ -191,6 +191,10 @@To view, visit change 287872. To unsubscribe, or for help writing mail filters, visit settings.