Skip to content

Commit dd8c7e1

Browse files
Merge pull request #1247 from filipw/csx
discover CSX files as launch targets
2 parents 01346a9 + 0334fc3 commit dd8c7e1

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/features/status.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ let defaultSelector: vscode.DocumentSelector = [
2626
'csharp', // c#-files OR
2727
{ pattern: '**/project.json' }, // project.json-files OR
2828
{ pattern: '**/*.sln' }, // any solution file OR
29-
{ pattern: '**/*.csproj' } // an csproj file
29+
{ pattern: '**/*.csproj' }, // an csproj file
30+
{ pattern: '**/*.csx' } // C# script
3031
];
3132

3233
class Status {

src/omnisharp/launcher.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { Options } from './options';
1616
export enum LaunchTargetKind {
1717
Solution,
1818
ProjectJson,
19-
Folder
19+
Folder,
20+
Csx
2021
}
2122

2223
/**
@@ -44,7 +45,7 @@ export function findLaunchTargets(): Thenable<LaunchTarget[]> {
4445
const options = Options.Read();
4546

4647
return vscode.workspace.findFiles(
47-
/*include*/ '{**/*.sln,**/*.csproj,**/project.json}',
48+
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx}',
4849
/*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}',
4950
/*maxResults*/ options.maxProjectResults)
5051
.then(resources => {
@@ -72,7 +73,8 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
7273
hasCsProjFiles = false,
7374
hasSlnFile = false,
7475
hasProjectJson = false,
75-
hasProjectJsonAtRoot = false;
76+
hasProjectJsonAtRoot = false,
77+
hasCSX = false;
7678

7779
hasCsProjFiles = resources.some(isCSharpProject);
7880

@@ -104,6 +106,11 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
104106
kind: LaunchTargetKind.ProjectJson
105107
});
106108
}
109+
110+
// Discover if there is any CSX file
111+
if (!hasCSX && isCsx(resource)) {
112+
hasCSX = true;
113+
}
107114
});
108115

109116
// Add the root folder under the following circumstances:
@@ -119,6 +126,17 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
119126
});
120127
}
121128

129+
// if we noticed any CSX file(s), add a single CSX-specific target pointing at the root folder
130+
if (hasCSX) {
131+
targets.push({
132+
label: "CSX",
133+
description: path.basename(rootPath),
134+
target: rootPath,
135+
directory: rootPath,
136+
kind: LaunchTargetKind.Csx
137+
});
138+
}
139+
122140
return targets.sort((a, b) => a.directory.localeCompare(b.directory));
123141
}
124142

@@ -134,6 +152,10 @@ function isProjectJson(resource: vscode.Uri): boolean {
134152
return /\project.json$/i.test(resource.fsPath);
135153
}
136154

155+
function isCsx(resource: vscode.Uri): boolean {
156+
return /\.csx$/i.test(resource.fsPath);
157+
}
158+
137159
export interface LaunchResult {
138160
process: ChildProcess;
139161
command: string;

src/omnisharp/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ export class OmniSharpServer {
350350
public autoStart(preferredPath: string): Thenable<void> {
351351
return findLaunchTargets().then(launchTargets => {
352352
// If there aren't any potential launch targets, we create file watcher and try to
353-
// start the server again once a *.sln, *.csproj or project.json file is created.
353+
// start the server again once a *.sln, *.csproj, project.json or CSX file is created.
354354
if (launchTargets.length === 0) {
355355
return new Promise<void>((resolve, reject) => {
356356
// 1st watch for files
357-
let watcher = vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.csproj,**/project.json}',
357+
let watcher = vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.csproj,**/project.json,**/*.csx}',
358358
/*ignoreCreateEvents*/ false,
359359
/*ignoreChangeEvents*/ true,
360360
/*ignoreDeleteEvents*/ true);

0 commit comments

Comments
 (0)