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

Support solution filters (*.slnf) #4076

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,12 @@
"workspaceContains:project.json",
"workspaceContains:*.csproj",
"workspaceContains:*.sln",
"workspaceContains:*.slnf",
"workspaceContains:*.csx",
"workspaceContains:*.cake",
"workspaceContains:**/*.csproj",
"workspaceContains:**/*.sln",
"workspaceContains:**/*.slnf",
"workspaceContains:**/*.csx",
"workspaceContains:**/*.cake"
],
Expand Down
2 changes: 1 addition & 1 deletion src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CSharpConfigurationProvider implements vscode.DebugConfigurationPro
}

let serverFolder = solutionPathOrFolder;
// If its a .sln file, get the folder of the solution.
// If its a .sln or .slnf file, get the folder of the solution.
return fs.lstat(solutionPathOrFolder).then(stat => {
return stat.isFile();
}).then(isFile => {
Expand Down
18 changes: 9 additions & 9 deletions src/omnisharp/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export interface LaunchTarget {

/**
* Returns a list of potential targets on which OmniSharp can be launched.
* This includes `project.json` files, `*.sln` files (if any `*.csproj` files are found), and the root folder
* This includes `project.json` files, `*.sln` and `*.slnf` files (if any `*.csproj` files are found), and the root folder
* (if it doesn't contain a `project.json` file, but `project.json` files exist). In addition, the root folder
* is included if there are any `*.csproj` files present, but a `*.sln* file is not found.
* is included if there are any `*.csproj` files present, but a `*.sln` or `*.slnf` file is not found.
*/
export async function findLaunchTargets(options: Options): Promise<LaunchTarget[]> {
if (!vscode.workspace.workspaceFolders) {
return Promise.resolve([]);
}

const projectFiles = await vscode.workspace.findFiles(
/*include*/ '{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
/*include*/ '{**/*.sln,**/*.slnf,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
/*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}',
/*maxResults*/ options.maxProjectResults);

Expand All @@ -57,14 +57,14 @@ export async function findLaunchTargets(options: Options): Promise<LaunchTarget[

function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
// The list of launch targets is calculated like so:
// * If there are .csproj files, .sln files are considered as launch targets.
// * If there are .csproj files, .sln and .slnf files are considered as launch targets.
// * Any project.json file is considered a launch target.
// * If there is no project.json file in a workspace folder, the workspace folder as added as a launch target.
// * Additionally, if there are .csproj files, but no .sln file, the root is added as a launch target.
// * Additionally, if there are .csproj files, but no .sln or .slnf file, the root is added as a launch target.
//
// TODO:
// * It should be possible to choose a .csproj as a launch target
// * It should be possible to choose a .sln file even when no .csproj files are found
// * It should be possible to choose a .sln or .slnf file even when no .csproj files are found
// within the root.

if (!Array.isArray(resources)) {
Expand Down Expand Up @@ -106,7 +106,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
let folderPath = folder.uri.fsPath;

resources.forEach(resource => {
// Add .sln files if there are .csproj files
// Add .sln and .slnf files if there are .csproj files
if (hasCsProjFiles && isSolution(resource)) {
hasSlnFile = true;
targets.push({
Expand Down Expand Up @@ -150,7 +150,7 @@ function resourcesToLaunchTargets(resources: vscode.Uri[]): LaunchTarget[] {
});

// Add the root folder under the following circumstances:
// * If there are .csproj files, but no .sln file, and none in the root.
// * If there are .csproj files, but no .sln or .slnf file, and none in the root.
// * If there are project.json files, but none in the root.
if ((hasCsProjFiles && !hasSlnFile) || (hasProjectJson && !hasProjectJsonAtRoot)) {
targets.push({
Expand Down Expand Up @@ -203,7 +203,7 @@ function isCSharpProject(resource: vscode.Uri): boolean {
}

function isSolution(resource: vscode.Uri): boolean {
return /\.sln$/i.test(resource.fsPath);
return /\.slnf?$/i.test(resource.fsPath);
}

function isProjectJson(resource: vscode.Uri): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ export class OmniSharpServer {
const options = this.optionProvider.GetLatestOptions();
return findLaunchTargets(options).then(async launchTargets => {
// If there aren't any potential launch targets, we create file watcher and try to
// start the server again once a *.sln, *.csproj, project.json, CSX or Cake file is created.
// start the server again once a *.sln, *.slnf, *.csproj, project.json, CSX or Cake file is created.
if (launchTargets.length === 0) {
return new Promise<void>((resolve, reject) => {
// 1st watch for files
let watcher = this.vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
let watcher = this.vscode.workspace.createFileSystemWatcher('{**/*.sln,**/*.slnf,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
/*ignoreCreateEvents*/ false,
/*ignoreChangeEvents*/ true,
/*ignoreDeleteEvents*/ true);
Expand Down
4 changes: 2 additions & 2 deletions test-plan.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Validating C# Extension for VS Code

#### Opening projects
When you open a directory in VS Code, the C# extension should look for a .csproj or .sln file in that directory and use "OmniSharp" to load it. If a .cs file is present and no .csproj or .sln file are present, Omnisharp should start but the intellisense should only appear when a change is made to the file.
When you open a directory in VS Code, the C# extension should look for a .csproj, .sln, or .slnf file in that directory and use "OmniSharp" to load it. If a .cs file is present and no .csproj, .sln, or .slnf file are present, Omnisharp should start but the intellisense should only appear when a change is made to the file.
If you look in "Output > Omnisharp Log" a bunch of information should be printed about what copy of MSBuild was used and what projects were load

Project types to test:
* Standalone csproj
* Directory containing .sln file that references csprojs--projects should be loaded
* Directory containing .sln or .slnf file that references csprojs--projects should be loaded
* .NET Core/.NET Standard csproj
* (Windows) Desktop .NET projects
* Unity projects
Expand Down