-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2121 from JoeRobich/solution-filter
Support Solution filter (.slnf)
- Loading branch information
Showing
8 changed files
with
189 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/OmniSharp.MSBuild/SolutionParsing/SolutionFilterReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.IO; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace OmniSharp.MSBuild.SolutionParsing | ||
{ | ||
internal static class SolutionFilterReader | ||
{ | ||
public static bool IsSolutionFilterFilename(string filename) | ||
{ | ||
return Path.GetExtension(filename).Equals(".slnf", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
public static bool TryRead(string filterFilename, out string solutionFilename, out ImmutableHashSet<string> projectFilter) | ||
{ | ||
try | ||
{ | ||
var filterDirectory = Path.GetDirectoryName(filterFilename); | ||
|
||
var document = JObject.Parse(File.ReadAllText(filterFilename)); | ||
var solution = document["solution"]; | ||
// Convert directory separators to the platform's default, since that is what MSBuild provide us. | ||
var solutionPath = ((string)solution?["path"])?.Replace('\\', Path.DirectorySeparatorChar); | ||
|
||
solutionFilename = Path.GetFullPath(Path.Combine(filterDirectory, solutionPath)); | ||
if (!File.Exists(solutionFilename)) | ||
{ | ||
projectFilter = ImmutableHashSet<string>.Empty; | ||
return false; | ||
} | ||
|
||
// The base directory for projects is the solution folder. | ||
var solutionDirectory = Path.GetDirectoryName(solutionFilename); | ||
|
||
var filterProjects = ImmutableHashSet.CreateBuilder<string>(StringComparer.OrdinalIgnoreCase); | ||
var projects = (JArray)solution?["projects"] ?? new JArray(); | ||
foreach (string project in projects) | ||
{ | ||
// Convert directory separators to the platform's default, since that is what MSBuild provide us. | ||
var projectPath = project?.Replace('\\', Path.DirectorySeparatorChar); | ||
if (projectPath is null) | ||
{ | ||
projectFilter = ImmutableHashSet<string>.Empty; | ||
return false; | ||
} | ||
|
||
var projectFilename = Path.GetFullPath(Path.Combine(solutionDirectory, projectPath)); | ||
if (!File.Exists(projectFilename)) | ||
{ | ||
projectFilter = ImmutableHashSet<string>.Empty; | ||
return false; | ||
} | ||
|
||
// Fill the filter with the absolute project paths. | ||
filterProjects.Add(projectFilename); | ||
} | ||
|
||
projectFilter = filterProjects.ToImmutable(); | ||
return true; | ||
} | ||
catch | ||
{ | ||
solutionFilename = string.Empty; | ||
projectFilter = ImmutableHashSet<string>.Empty; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test-assets/test-projects/ProjectAndSolutionFilter/Project/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace ProjectAndSolution | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello World!"); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test-assets/test-projects/ProjectAndSolutionFilter/Project/ProjectAndSolutionFilter.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
test-assets/test-projects/ProjectAndSolutionFilter/ProjectAndSolutionFilter.slnf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"solution": { | ||
"path": "Solution\\ProjectAndSolutionFilter.sln", | ||
"projects": [ | ||
"..\\Project\\ProjectAndSolutionFilter.csproj" | ||
] | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
test-assets/test-projects/ProjectAndSolutionFilter/Solution/ProjectAndSolutionFilter.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectAndSolutionFilter", "..\Project\ProjectAndSolutionFilter.csproj", "{A4C2694D-AEB4-4CB1-8951-5290424EF883}" | ||
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 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Debug|x64.ActiveCfg = Debug|x64 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Debug|x64.Build.0 = Debug|x64 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Debug|x86.ActiveCfg = Debug|x86 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Debug|x86.Build.0 = Debug|x86 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Release|x64.ActiveCfg = Release|x64 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Release|x64.Build.0 = Release|x64 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Release|x86.ActiveCfg = Release|x86 | ||
{A4C2694D-AEB4-4CB1-8951-5290424EF883}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters