Skip to content

Commit

Permalink
Merge pull request #4481 from JoeRobich/solution-filters
Browse files Browse the repository at this point in the history
Support solution filters (*.slnf)
  • Loading branch information
JoeRobich authored Apr 7, 2021
2 parents b6d16ba + 5e8f728 commit d820b2e
Show file tree
Hide file tree
Showing 35 changed files with 436 additions and 15 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@
],
"preLaunchTask": "buildDev"
},
{
"name": "Launch slnFilterWithCsproj Workspace Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"${workspaceRoot}/test/integrationTests/testAssets/slnFilterWithCsproj",
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
],
"env": {
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/slnFilterWithCsproj",
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
"OSVC_SUITE": "slnFilterWithCsproj"
},
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/dist/*.js"
],
"preLaunchTask": "buildDev"
},
{
"type": "node",
"request": "launch",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"test:integration": "gulp test:integration",
"test:integration:singleCsproj": "gulp test:integration:singleCsproj",
"test:integration:slnWithCsproj": "gulp test:integration:slnWithCsproj",
"test:integration:slnFilterWithCsproj": "gulp test:integration:slnFilterWithCsproj",
"test:release": "mocha --config ./.mocharc.jsonc test/releaseTests/**/*.test.ts",
"test:artifacts": "mocha --config ./.mocharc.jsonc test/artifactTests/**/*.test.ts",
"postinstall": "node ./node_modules/vscode/bin/install",
Expand Down Expand Up @@ -409,10 +410,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 @@ -52,17 +52,17 @@ export const disabledSchemes = new Set([

/**
* 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 @@ -76,14 +76,14 @@ export async function findLaunchTargets(options: Options): Promise<LaunchTarget[

export 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) || resources.length === 0) {
Expand Down Expand Up @@ -132,7 +132,7 @@ export 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 @@ -176,7 +176,7 @@ export 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 @@ -229,7 +229,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 @@ -498,11 +498,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
5 changes: 5 additions & 0 deletions tasks/testTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ gulp.task("test:integration:slnWithCsproj", async () => {
return runIntegrationTest("slnWithCsproj");
});

gulp.task("test:integration:slnFilterWithCsproj", async () => {
return runIntegrationTest("slnFilterWithCsproj");
});

gulp.task("test:integration:BasicRazorApp2_1", async () => {
return runIntegrationTest("BasicRazorApp2_1");
});
Expand All @@ -53,6 +57,7 @@ gulp.task(
"test:integration", gulp.series(
"test:integration:singleCsproj",
"test:integration:slnWithCsproj",
"test:integration:slnFilterWithCsproj",
"test:integration:BasicRazorApp2_1"
));

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
15 changes: 15 additions & 0 deletions test/integrationTests/testAssets/slnFilterWithCsproj.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ITestAssetWorkspace } from "./testAssets";

let workspace: ITestAssetWorkspace = {
description: "sln filter with a csproj's",
projects: [{
relativeFilePath: "src/app/app.csproj"
}]
};

export default workspace;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/obj/
**/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"omnisharp.defaultLaunchSolution": "SolutionFilter.slnf",
"omnisharp.path": "latest",
"omnisharp.enableRoslynAnalyzers": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D28FC441-C95D-47D2-8D5C-E401ABAD7C64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "app", "src\app\app.csproj", "{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lib", "src\lib\lib.csproj", "{717BE881-D74C-45FC-B55D-2085499E1BF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{4679428B-0CA0-4228-B8C0-B676B34A1B30}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Debug|x64.ActiveCfg = Debug|x64
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Debug|x64.Build.0 = Debug|x64
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Debug|x86.ActiveCfg = Debug|x86
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Debug|x86.Build.0 = Debug|x86
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Release|Any CPU.Build.0 = Release|Any CPU
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Release|x64.ActiveCfg = Release|x64
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Release|x64.Build.0 = Release|x64
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Release|x86.ActiveCfg = Release|x86
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3}.Release|x86.Build.0 = Release|x86
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Debug|x64.ActiveCfg = Debug|x64
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Debug|x64.Build.0 = Debug|x64
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Debug|x86.ActiveCfg = Debug|x86
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Debug|x86.Build.0 = Debug|x86
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Release|Any CPU.Build.0 = Release|Any CPU
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Release|x64.ActiveCfg = Release|x64
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Release|x64.Build.0 = Release|x64
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Release|x86.ActiveCfg = Release|x86
{717BE881-D74C-45FC-B55D-2085499E1BF8}.Release|x86.Build.0 = Release|x86
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Debug|x64.ActiveCfg = Debug|x64
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Debug|x64.Build.0 = Debug|x64
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Debug|x86.ActiveCfg = Debug|x86
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Debug|x86.Build.0 = Debug|x86
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Release|Any CPU.Build.0 = Release|Any CPU
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Release|x64.ActiveCfg = Release|x64
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Release|x64.Build.0 = Release|x64
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Release|x86.ActiveCfg = Release|x86
{4679428B-0CA0-4228-B8C0-B676B34A1B30}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D36E1CC9-62CA-45A3-8BD0-6ADC2767FFB3} = {D28FC441-C95D-47D2-8D5C-E401ABAD7C64}
{717BE881-D74C-45FC-B55D-2085499E1BF8} = {D28FC441-C95D-47D2-8D5C-E401ABAD7C64}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"solution": {
"path": "SolutionFile.sln",
"projects": [
"src\\app\\app.csproj"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class DocComments
{
///
string M(int param1, string param2)
{
return null;
}

/// <summary>

/// </summary>
void M2() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ReAnalyze
{
public interface ISomeInterface
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace app
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ReAnalyze
{
public class SomeInterfaceImpl: ISomeInterface
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\lib\lib.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace singleCsproj
{
class Completion
{
static void shouldHaveCompletions(string[] args)
{
Completion a = new Completion();
}

// override // Trailing space is intentional
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Test
{
public class Definition
{
public static string Foo { get; set; }

public void MyMethod()
{
Console.WriteLine(Foo);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.IO;

namespace Foo
{
public class FooBar
{
public void FooBarBar()
{
var notUsed = 3;
}
}
}
Loading

0 comments on commit d820b2e

Please sign in to comment.