MCPcopy
hub / github.com/dotnet/vscode-csharp / autoStart

Method autoStart

src/omnisharp/server.ts:676–741  ·  view source on GitHub ↗
(preferredPath: string)

Source from the content-addressed store, hash-verified

674 }
675
676 public async autoStart(preferredPath: string): Promise<void> {
677 const launchTargets = await findLaunchTargets();
678
679 // If there aren't any potential launch targets, we create file watcher and try to
680 // start the server again once a *.sln, *.slnf, *.csproj, CSX or Cake file is created.
681 if (launchTargets.length === 0) {
682 await new Promise<void>((resolve) => {
683 // 1st watch for files
684 const watcher = this.vscode.workspace.createFileSystemWatcher(
685 '{**/*.sln,**/*.slnf,**/*.csproj,**/*.csx,**/*.cake}',
686 /*ignoreCreateEvents*/ false,
687 /*ignoreChangeEvents*/ true,
688 /*ignoreDeleteEvents*/ true
689 );
690
691 watcher.onDidCreate((_) => {
692 watcher.dispose();
693 resolve();
694 });
695 });
696
697 // 2nd try again
698 return this.autoStart(preferredPath);
699 } else if (launchTargets.length === 1) {
700 // If there's only one target, just start
701 return this.start(launchTargets[0]);
702 }
703
704 // First, try to launch against something that matches the user's preferred target
705 const defaultLaunchSolutionConfigValue = commonOptions.defaultSolution;
706 const defaultLaunchSolutionTarget = launchTargets.find(
707 (a) => path.basename(a.target) === defaultLaunchSolutionConfigValue
708 );
709 if (defaultLaunchSolutionTarget) {
710 return this.start(defaultLaunchSolutionTarget);
711 }
712
713 // If there's more than one launch target, we start the server if one of the targets
714 // matches the preferred path.
715 if (preferredPath.length > 0) {
716 const preferredLaunchTarget = launchTargets.find((a_1) => a_1.target === preferredPath);
717 if (preferredLaunchTarget) {
718 return this.start(preferredLaunchTarget);
719 }
720 }
721
722 // To maintain previous behavior when there are mulitple targets available,
723 // launch with first Solution or Folder target.
724 const firstFolderOrSolutionTarget = launchTargets.find(
725 (target) =>
726 target.workspaceKind == LaunchTargetKind.Folder || target.workspaceKind == LaunchTargetKind.Solution
727 );
728 if (firstFolderOrSolutionTarget) {
729 return this.start(firstFolderOrSolutionTarget);
730 }
731
732 // When running integration tests, open the first launch target.
733 if (process.env.RUNNING_INTEGRATION_TESTS === 'true') {

Callers 2

activateFunction · 0.95
restartOmniSharpFunction · 0.45

Calls 5

startMethod · 0.95
_fireEventMethod · 0.95
findLaunchTargetsFunction · 0.90
showProjectSelectorFunction · 0.90
disposeMethod · 0.65

Tested by

no test coverage detected