Skip to content

Commit

Permalink
Merge pull request #1247 from filipw/csx
Browse files Browse the repository at this point in the history
discover CSX files as launch targets
  • Loading branch information
DustinCampbell authored Mar 8, 2017
2 parents 01346a9 + 0334fc3 commit dd8c7e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
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

0 comments on commit dd8c7e1

Please sign in to comment.