Skip to content

Commit e008fcf

Browse files
Update launch target discovery to include root folder for .csproj files
Note: This change requires an update to OmniSharp in order to function properly. It is dependent on OmniSharp/omnisharp-roslyn#635.
1 parent a745a28 commit e008fcf

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/omnisharp/launcher.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export enum LaunchTargetKind {
2424
* Represents the project or solution that OmniSharp is to be launched with.
2525
* */
2626
export interface LaunchTarget {
27-
label: string;
28-
description: string;
29-
directory: string;
30-
target: string;
31-
kind: LaunchTargetKind;
27+
label: string;
28+
description: string;
29+
directory: string;
30+
target: string;
31+
kind: LaunchTargetKind;
3232
}
3333

3434
export function getDefaultFlavor(kind: LaunchTargetKind) {
@@ -47,7 +47,8 @@ export function getDefaultFlavor(kind: LaunchTargetKind) {
4747
/**
4848
* Returns a list of potential targets on which OmniSharp can be launched.
4949
* This includes `project.json` files, `*.sln` files (if any `*.csproj` files are found), and the root folder
50-
* (if it doesn't contain a `project.json` file, but `project.json` files exist).
50+
* (if it doesn't contain a `project.json` file, but `project.json` files exist). In addition, the root folder
51+
* is included if there are any `*.csproj` files present, but a `*.sln* file is not found.
5152
*/
5253
export function findLaunchTargets(): Thenable<LaunchTarget[]> {
5354
if (!vscode.workspace.rootPath) {
@@ -68,6 +69,7 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
6869
// * If there are .csproj files, .sln files are considered as launch targets.
6970
// * Any project.json file is considered a launch target.
7071
// * If there is no project.json file in the root, the root as added as a launch target.
72+
// * Additionally, if there are .csproj files, but no .sln file, the root is added as a launch target.
7173
//
7274
// TODO:
7375
// * It should be possible to choose a .csproj as a launch target
@@ -80,6 +82,7 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
8082

8183
let targets: LaunchTarget[] = [],
8284
hasCsProjFiles = false,
85+
hasSlnFile = false,
8386
hasProjectJson = false,
8487
hasProjectJsonAtRoot = false;
8588

@@ -88,6 +91,8 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
8891
resources.forEach(resource => {
8992
// Add .sln files if there are .csproj files
9093
if (hasCsProjFiles && isSolution(resource)) {
94+
hasSlnFile = true;
95+
9196
targets.push({
9297
label: path.basename(resource.fsPath),
9398
description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)),
@@ -113,8 +118,10 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
113118
}
114119
});
115120

116-
// Add the root folder if there are project.json files, but none in the root.
117-
if (hasProjectJson && !hasProjectJsonAtRoot) {
121+
// Add the root folder under the following circumstances:
122+
// * If there are .csproj files, but no .sln file, and none in the root.
123+
// * If there are project.json files, but none in the root.
124+
if ((hasCsProjFiles && !hasSlnFile) || (hasProjectJson && !hasProjectJsonAtRoot)) {
118125
targets.push({
119126
label: path.basename(rootPath),
120127
description: '',

src/omnisharp/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,16 @@ export abstract class OmnisharpServer {
363363

364364
public autoStart(preferredPath: string): Thenable<void> {
365365
return findLaunchTargets().then(launchTargets => {
366-
// If there aren't any potential launch targets, we create file watcher and
367-
// try to start the server again once a *.sln or project.json file is created.
366+
// If there aren't any potential launch targets, we create file watcher and try to
367+
// start the server again once a *.sln, *.csproj or project.json file is created.
368368
if (launchTargets.length === 0) {
369369
return new Promise<void>((resolve, reject) => {
370370
// 1st watch for files
371-
let watcher = vscode.workspace.createFileSystemWatcher('{**/*.sln,**/project.json}', false, true, true);
371+
let watcher = vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.csproj,**/project.json}',
372+
/*ignoreCreateEvents*/ false,
373+
/*ignoreChangeEvents*/ true,
374+
/*ignoreDeleteEvents*/ true);
375+
372376
watcher.onDidCreate(uri => {
373377
watcher.dispose();
374378
resolve();

0 commit comments

Comments
 (0)