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

Added processCommand to attach config #2969

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andrew-w-ross
Copy link

Attaching to a process can get quite annoying if you're using dotnet watch as processName isn't specific enough as there are multiple processes called dotnet.
This pr add a config option called processCommand to the attach config that will find the process by it's command.
This pr is just a proof of concept, I'm just looking for feedback on the idea.
If you like the feature I'll do a proper one with all the unit testing and correct error messages, etc.

Added processCommand to optionsSchema.json
Added processCommand to resolve debugCOnfig
@dnfclas
Copy link

dnfclas commented Apr 5, 2019

CLA assistant check
All CLA requirements met.

@codecov
Copy link

codecov bot commented Apr 5, 2019

Codecov Report

Merging #2969 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2969   +/-   ##
=======================================
  Coverage   89.89%   89.89%           
=======================================
  Files          59       59           
  Lines        1583     1583           
  Branches       89       89           
=======================================
  Hits         1423     1423           
  Misses        149      149           
  Partials       11       11
Flag Coverage Δ
#integration 100% <ø> (ø) ⬆️
#unit 89.89% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a26dce...d7b8254. Read the comment docs.

if (config.request === "attach" && config.processCommand) {
const processCommand = config.processCommand.replace(/\${workspaceFolder}/g, folder.uri.fsPath);
delete config.processCommand;
return this.attachItemsProvider.getAttachItems()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return [](start = 12, length = 6)

nit: make this an async method and use await.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (attachItem == null) {
throw new Error("Can't find process");
}
config.processId = attachItem.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.processId = attachItem.id; [](start = 20, length = 33)

We should probably fail if there are multiple processes with the command rather than picking the first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.then(attachItems => {
const attachItem = attachItems.find(ai => ai.detail === processCommand);
if (attachItem == null) {
throw new Error("Can't find process");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Can't find process" [](start = 40, length = 20)

We might want to mention what we are looking for.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now throws Couldn't find process with command ${processCommand}

Copy link
Contributor

@gregg-miskelly gregg-miskelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM. Thanks for the PR! Seems like a useful feature to me.

Better error message if the process can't be found
Error message if process was found more than once
Deleted processCommand in unitDebuggingOptions
@andrew-w-ross
Copy link
Author

@gregg-miskelly Let me know if that's good. I'm not too familiar with Mocha so I'm not entirely sure how to mock DotNetAttachItemsProviderFactory so I can test.

Copy link
Contributor

@gregg-miskelly gregg-miskelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

"processCommand": {
"type": "string",
"description": "Attaches to a process with this command",
"default": "If this is use 'processId' and 'processName' should not be used."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo here. You want 'used' instead of 'use'.

But thinking about it more, you might want to instead use something like dotnet exec /example/path/to/program.dll to provide an example of the kind of thing we might want.

}

if (foundAttatchItems.length > 1) {
throw new Error(`Find ${foundAttatchItems.length} processes with the command "${processCommand}"`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about instead "Unable to select process. Multiple processes found with command line "${processCommand}".

@gregg-miskelly
Copy link
Contributor

gregg-miskelly commented Apr 11, 2019

@gregg-miskelly Let me know if that's good. I'm not too familiar with Mocha so I'm not entirely sure how to mock DotNetAttachItemsProviderFactory so I can test.

I am not an expert on it either, so there may be other options. But what I have always done is extract out the thing I want to unit test into its own class which takes appropriate inputs (ex: probably a process listing + input debug target in your case) and then I can unit test just the transformation without having to get into real object mocking.

Example: f4e8700#diff-cafde65775b42fd5521704bf2b7d3309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants