-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Automatically attach the Roslyn ServiceHub service to the VS debugger. #80053
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
base: main
Are you sure you want to change the base?
Conversation
| _solutionEventMonitor = new SolutionEventMonitor(globalNotificationService); | ||
| TrackBulkFileOperations(globalNotificationService); | ||
|
|
||
| #if DEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be debug only? If it's not, then Razor could set the same env var, which would be quite convenient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't even think about that. Happy to remove.
| var hostProcess = Process.GetCurrentProcess(); | ||
| var serviceHubProcess = Process | ||
| .GetProcessesByName("ServiceHub.RoslynCodeAnalysisService") | ||
| .FirstOrDefault(p => IsChildProcess(p, hostProcess)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is possible:
var query = $"SELECT ProcessId FROM Win32_Process WHERE Name='{exe}' AND ParentProcessId={host.Id}; to help get child processes over iterating through each process object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql injection!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, how though? exe is a static value that we'd specify.
| } | ||
| } | ||
|
|
||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have this all in a try/catch. i don't trust these management apis to always be well behaved.
| AttachServiceHubToDebugger(serviceHubProcess); | ||
|
|
||
| watcher.Stop(); | ||
| watcher.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about try/catch as this is in a callback.
| namespace Microsoft.VisualStudio.LanguageServices; | ||
|
|
||
| /// <summary> | ||
| /// This class is a debugging aid to help attach the VS debugger to the Roslyn ServiceHub process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a feature we should just check into the ServiceHub repository so everybody gets this? I'd imagine it also might make it easier to do because rather than having to do all the trickery of watching for the process to launch and figuring out if it's a the right child process, that code would just now since it launched the process in the first place?
As suggested in #53601 (review)
Current method of settings
SERVICEHUBDEBUGHOSTONSTARTUPcauses "choose a debugger" prompt to launch for each ServiceHub service. This new method silently attaches the debugger to the Roslyn ServiceHub process.Current method prompts even when using ctrl+F5. This method requires the debugger to be attached to devenv.