Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@JoeRobich
Copy link
Member

As suggested in #53601 (review)

image

Current method of settings SERVICEHUBDEBUGHOSTONSTARTUP causes "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.

@JoeRobich JoeRobich requested a review from a team as a code owner August 27, 2025 07:24
_solutionEventMonitor = new SolutionEventMonitor(globalNotificationService);
TrackBulkFileOperations(globalNotificationService);

#if DEBUG
Copy link
Member

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.

Copy link
Member Author

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));
Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

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

sql injection!

Copy link
Contributor

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;
Copy link
Member

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();
Copy link
Member

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.
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants