Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discover CSX files as launch targets #1247

Merged
merged 3 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/features/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ let defaultSelector: vscode.DocumentSelector = [
'csharp', // c#-files OR
{ pattern: '**/project.json' }, // project.json-files OR
{ pattern: '**/*.sln' }, // any solution file OR
{ pattern: '**/*.csproj' } // an csproj file
{ pattern: '**/*.csproj' }, // an csproj file
{ pattern: '**/*.csx' } // C# script
];

class Status {
Expand Down
28 changes: 25 additions & 3 deletions src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { Options } from './options';
export enum LaunchTargetKind {
Solution,
ProjectJson,
Folder
Folder,
Csx
}

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

return vscode.workspace.findFiles(
/*include*/ '{**/*.sln,**/*.csproj,**/project.json}',
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx}',
/*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}',
/*maxResults*/ options.maxProjectResults)
.then(resources => {
Expand Down Expand Up @@ -72,7 +73,8 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
hasCsProjFiles = false,
hasSlnFile = false,
hasProjectJson = false,
hasProjectJsonAtRoot = false;
hasProjectJsonAtRoot = false,
hasCSX = false;

hasCsProjFiles = resources.some(isCSharpProject);

Expand Down Expand Up @@ -104,6 +106,11 @@ function select(resources: vscode.Uri[], rootPath: string): LaunchTarget[] {
kind: LaunchTargetKind.ProjectJson
});
}

// Discover if there is any CSX file
if (!hasCSX && isCsx(resource)) {
hasCSX = true;
}
});

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

// if we noticed any CSX file(s), add a single CSX-specific target pointing at the root folder
if (hasCSX) {
targets.push({
label: "CSX",
description: path.basename(rootPath),
target: rootPath,
directory: rootPath,
kind: LaunchTargetKind.Csx
});
}

return targets.sort((a, b) => a.directory.localeCompare(b.directory));
}

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

function isCsx(resource: vscode.Uri): boolean {
return /\.csx$/i.test(resource.fsPath);
}

export interface LaunchResult {
process: ChildProcess;
command: string;
Expand Down
4 changes: 2 additions & 2 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ export class OmniSharpServer {
public autoStart(preferredPath: string): Thenable<void> {
return findLaunchTargets().then(launchTargets => {
// If there aren't any potential launch targets, we create file watcher and try to
// start the server again once a *.sln, *.csproj or project.json file is created.
// start the server again once a *.sln, *.csproj, project.json or CSX file is created.
if (launchTargets.length === 0) {
return new Promise<void>((resolve, reject) => {
// 1st watch for files
let watcher = vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.csproj,**/project.json}',
let watcher = vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.csproj,**/project.json,**/*.csx}',
/*ignoreCreateEvents*/ false,
/*ignoreChangeEvents*/ true,
/*ignoreDeleteEvents*/ true);
Expand Down