Skip to content

Commit 030a5bb

Browse files
Support workspace folders in OmniSharp launcher
1 parent 0e17bc1 commit 030a5bb

File tree

2 files changed

+106
-83
lines changed

2 files changed

+106
-83
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
}
191191
],
192192
"engines": {
193-
"vscode": "^1.15.0"
193+
"vscode": "^1.17.0"
194194
},
195195
"activationEvents": [
196196
"onLanguage:csharp",

src/omnisharp/launcher.ts

Lines changed: 105 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,24 @@ export interface LaunchTarget {
3939
* is included if there are any `*.csproj` files present, but a `*.sln* file is not found.
4040
*/
4141
export function findLaunchTargets(): Thenable<LaunchTarget[]> {
42-
if (!vscode.workspace.rootPath) {
42+
if (!vscode.workspace.workspaceFolders) {
4343
return Promise.resolve([]);
4444
}
4545

4646
const options = Options.Read();
4747

4848
return vscode.workspace.findFiles(
49-
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
50-
/*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}',
51-
/*maxResults*/ options.maxProjectResults)
52-
.then(resources => {
53-
return select(resources, vscode.workspace.rootPath);
54-
});
49+
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
50+
/*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}',
51+
/*maxResults*/ options.maxProjectResults)
52+
.then(resourcesToLaunchTargets);
5553
}
5654

57-
function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
55+
function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
5856
// The list of launch targets is calculated like so:
5957
// * If there are .csproj files, .sln files are considered as launch targets.
6058
// * Any project.json file is considered a launch target.
61-
// * If there is no project.json file in the root, the root as added as a launch target.
59+
// * If there is no project.json file in a workspace folder, the workspace folder as added as a launch target.
6260
// * Additionally, if there are .csproj files, but no .sln file, the root is added as a launch target.
6361
//
6462
// TODO:
@@ -70,91 +68,116 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
7068
return [];
7169
}
7270

73-
let targets: LaunchTarget[] = [],
74-
hasCsProjFiles = false,
75-
hasSlnFile = false,
76-
hasProjectJson = false,
77-
hasProjectJsonAtRoot = false,
78-
hasCSX = false,
79-
hasCake = false;
71+
let workspaceFolderToUriMap = new Map<number, vscode.Uri[]>();
8072

81-
hasCsProjFiles = resources.some(isCSharpProject);
73+
for (let resource of resources) {
74+
let folder = vscode.workspace.getWorkspaceFolder(resource);
75+
if (folder) {
76+
let buckets: vscode.Uri[];
8277

83-
resources.forEach(resource => {
84-
// Add .sln files if there are .csproj files
85-
if (hasCsProjFiles && isSolution(resource)) {
86-
hasSlnFile = true;
78+
if (workspaceFolderToUriMap.has(folder.index)) {
79+
buckets = workspaceFolderToUriMap.get(folder.index);
80+
} else {
81+
buckets = [];
82+
workspaceFolderToUriMap.set(folder.index, buckets);
83+
}
8784

88-
targets.push({
89-
label: path.basename(resource.fsPath),
90-
description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)),
91-
target: resource.fsPath,
92-
directory: path.dirname(resource.fsPath),
93-
kind: LaunchTargetKind.Solution
94-
});
85+
buckets.push(resource);
9586
}
87+
}
9688

97-
// Add project.json files
98-
if (isProjectJson(resource)) {
99-
const dirname = path.dirname(resource.fsPath);
100-
hasProjectJson = true;
101-
hasProjectJsonAtRoot = hasProjectJsonAtRoot || dirname === rootPath;
102-
89+
let targets: LaunchTarget[] = [];
90+
91+
workspaceFolderToUriMap.forEach((resources, folderIndex) =>
92+
{
93+
let hasCsProjFiles = false,
94+
hasSlnFile = false,
95+
hasProjectJson = false,
96+
hasProjectJsonAtRoot = false,
97+
hasCSX = false,
98+
hasCake = false;
99+
100+
hasCsProjFiles = resources.some(isCSharpProject);
101+
102+
let folder = vscode.workspace.workspaceFolders[folderIndex];
103+
let folderPath = folder.uri.fsPath;
104+
105+
resources.forEach(resource => {
106+
// Add .sln files if there are .csproj files
107+
if (hasCsProjFiles && isSolution(resource)) {
108+
hasSlnFile = true;
109+
110+
targets.push({
111+
label: path.basename(resource.fsPath),
112+
description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)),
113+
target: resource.fsPath,
114+
directory: path.dirname(resource.fsPath),
115+
kind: LaunchTargetKind.Solution
116+
});
117+
}
118+
119+
// Add project.json files
120+
if (isProjectJson(resource)) {
121+
const dirname = path.dirname(resource.fsPath);
122+
hasProjectJson = true;
123+
hasProjectJsonAtRoot = hasProjectJsonAtRoot || dirname === folderPath;
124+
125+
targets.push({
126+
label: path.basename(resource.fsPath),
127+
description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)),
128+
target: dirname,
129+
directory: dirname,
130+
kind: LaunchTargetKind.ProjectJson
131+
});
132+
}
133+
134+
// Discover if there is any CSX file
135+
if (!hasCSX && isCsx(resource)) {
136+
hasCSX = true;
137+
}
138+
139+
// Discover if there is any Cake file
140+
if (!hasCake && isCake(resource)) {
141+
hasCake = true;
142+
}
143+
});
144+
145+
// Add the root folder under the following circumstances:
146+
// * If there are .csproj files, but no .sln file, and none in the root.
147+
// * If there are project.json files, but none in the root.
148+
if ((hasCsProjFiles && !hasSlnFile) || (hasProjectJson && !hasProjectJsonAtRoot)) {
103149
targets.push({
104-
label: path.basename(resource.fsPath),
105-
description: vscode.workspace.asRelativePath(path.dirname(resource.fsPath)),
106-
target: dirname,
107-
directory: dirname,
108-
kind: LaunchTargetKind.ProjectJson
150+
label: path.basename(folderPath),
151+
description: '',
152+
target: folderPath,
153+
directory: folderPath,
154+
kind: LaunchTargetKind.Folder
109155
});
110156
}
111-
112-
// Discover if there is any CSX file
113-
if (!hasCSX && isCsx(resource)) {
114-
hasCSX = true;
157+
158+
// if we noticed any CSX file(s), add a single CSX-specific target pointing at the root folder
159+
if (hasCSX) {
160+
targets.push({
161+
label: "CSX",
162+
description: path.basename(folderPath),
163+
target: folderPath,
164+
directory: folderPath,
165+
kind: LaunchTargetKind.Csx
166+
});
115167
}
116-
117-
// Discover if there is any Cake file
118-
if (!hasCake && isCake(resource)) {
119-
hasCake = true;
168+
169+
// if we noticed any Cake file(s), add a single Cake-specific target pointing at the root folder
170+
if (hasCake) {
171+
targets.push({
172+
label: "Cake",
173+
description: path.basename(folderPath),
174+
target: folderPath,
175+
directory: folderPath,
176+
kind: LaunchTargetKind.Cake
177+
});
120178
}
121179
});
122180

123-
// Add the root folder under the following circumstances:
124-
// * If there are .csproj files, but no .sln file, and none in the root.
125-
// * If there are project.json files, but none in the root.
126-
if ((hasCsProjFiles && !hasSlnFile) || (hasProjectJson && !hasProjectJsonAtRoot)) {
127-
targets.push({
128-
label: path.basename(rootPath),
129-
description: '',
130-
target: rootPath,
131-
directory: rootPath,
132-
kind: LaunchTargetKind.Folder
133-
});
134-
}
135-
136-
// if we noticed any CSX file(s), add a single CSX-specific target pointing at the root folder
137-
if (hasCSX) {
138-
targets.push({
139-
label: "CSX",
140-
description: path.basename(rootPath),
141-
target: rootPath,
142-
directory: rootPath,
143-
kind: LaunchTargetKind.Csx
144-
});
145-
}
146-
147-
// if we noticed any Cake file(s), add a single Cake-specific target pointing at the root folder
148-
if (hasCake) {
149-
targets.push({
150-
label: "Cake",
151-
description: path.basename(rootPath),
152-
target: rootPath,
153-
directory: rootPath,
154-
kind: LaunchTargetKind.Cake
155-
});
156-
}
157-
158181
return targets.sort((a, b) => a.directory.localeCompare(b.directory));
159182
}
160183

0 commit comments

Comments
 (0)