-
Notifications
You must be signed in to change notification settings - Fork 419
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
Added support for excluding search paths via globbing patterns #1161
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d1c72b2
added new file options to OmniSharpOptions
filipw 8a0478e
added a new file system helper with support for globbing
filipw 3075e19
use globbing in scripting
filipw 36f4025
use globbing in cake
filipw 7836c1e
use globbing in msbuild
filipw 182c012
added FileSystemHelperFacts.cs
filipw 3af1fae
sort namespaces
filipw 7191634
moved FileOptions to a separate file
filipw 1d1ac86
Merge branch 'master' into feature/globbing
filipw 0381b98
Merge branch 'master' into feature/globbing
david-driscoll 3e8caf1
added **/.git/**/*
filipw 4f6b865
added SystemExcludeSearchPatterns
filipw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Linq; | ||
using Microsoft.Extensions.FileSystemGlobbing; | ||
using OmniSharp.Options; | ||
|
||
namespace OmniSharp.FileSystem | ||
{ | ||
[Export, Shared] | ||
public class FileSystemHelper | ||
{ | ||
private readonly OmniSharpOptions _omniSharpOptions; | ||
private readonly IOmniSharpEnvironment _omniSharpEnvironment; | ||
|
||
[ImportingConstructor] | ||
public FileSystemHelper(OmniSharpOptions omniSharpOptions, IOmniSharpEnvironment omniSharpEnvironment) | ||
{ | ||
_omniSharpOptions = omniSharpOptions; | ||
_omniSharpEnvironment = omniSharpEnvironment; | ||
} | ||
|
||
public IEnumerable<string> GetFiles(string includePattern) => GetFiles(includePattern, _omniSharpEnvironment.TargetDirectory); | ||
|
||
public IEnumerable<string> GetFiles(string includePattern, string targetDirectory) | ||
{ | ||
var matcher = new Matcher(); | ||
matcher.AddInclude(includePattern); | ||
|
||
if (_omniSharpOptions.FileOptions.ExcludeSearchPatterns != null && _omniSharpOptions.FileOptions.ExcludeSearchPatterns.Any()) | ||
{ | ||
matcher.AddExcludePatterns(_omniSharpOptions.FileOptions.ExcludeSearchPatterns); | ||
} | ||
|
||
return matcher.GetResultsInFullPath(targetDirectory); | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace OmniSharp.Options | ||
{ | ||
public class FileOptions | ||
{ | ||
public string[] ExcludeSearchPatterns { get; set; } = new[] { "**/node_modules/**/*", "**/bin/**/*", "**/obj/**/*" }; | ||
} | ||
} |
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
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
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,85 @@ | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.FileSystem; | ||
using OmniSharp.Options; | ||
using OmniSharp.Services; | ||
using System.Linq; | ||
using TestUtility; | ||
using Xunit; | ||
|
||
namespace OmniSharp.Tests | ||
{ | ||
public class FileSystemHelperFacts | ||
{ | ||
[Fact] | ||
public void FileSystemHelperFacts_CanExcludeSearchPath_File() | ||
{ | ||
var helper = CreateFileSystemHelper("**/ProjectWithSdkProperty.csproj"); | ||
|
||
var msbuildProjectFiles = helper.GetFiles("**/*.csproj"); | ||
Assert.NotEmpty(msbuildProjectFiles); | ||
|
||
var projectWithSdkProperty = msbuildProjectFiles.FirstOrDefault(p => p.Contains("ProjectWithSdkProperty")); | ||
Assert.Null(projectWithSdkProperty); | ||
} | ||
|
||
[Fact] | ||
public void FileSystemHelperFacts_CanExcludeSearchPath_MultipleFiles() | ||
{ | ||
var helper = CreateFileSystemHelper("**/MSTestProject.csproj", "**/NUnitTestProject.csproj"); | ||
|
||
var msbuildProjectFiles = helper.GetFiles("**/*.csproj"); | ||
Assert.NotEmpty(msbuildProjectFiles); | ||
|
||
var msTestProject = msbuildProjectFiles.FirstOrDefault(p => p.Contains("MSTestProject")); | ||
Assert.Null(msTestProject); | ||
|
||
var nunitTestProject = msbuildProjectFiles.FirstOrDefault(p => p.Contains("NUnitTestProject")); | ||
Assert.Null(nunitTestProject); | ||
} | ||
|
||
[Fact] | ||
public void FileSystemHelperFacts_CanExcludeSearchPath_Folder() | ||
{ | ||
var helper = CreateFileSystemHelper("**/ProjectWithSdkProperty/**/*"); | ||
|
||
var msbuildProjectFiles = helper.GetFiles("**/*.csproj"); | ||
Assert.NotEmpty(msbuildProjectFiles); | ||
|
||
var projectWithSdkProperty = msbuildProjectFiles.FirstOrDefault(p => p.Contains("ProjectWithSdkProperty")); | ||
Assert.Null(projectWithSdkProperty); | ||
} | ||
|
||
[Fact] | ||
public void FileSystemHelperFacts_CanExcludeSearchPath_MultipleFolders() | ||
{ | ||
var helper = CreateFileSystemHelper("**/MSTestProject/**/*", "**/NUnitTestProject/**/*"); | ||
|
||
var msbuildProjectFiles = helper.GetFiles("**/*.csproj"); | ||
Assert.NotEmpty(msbuildProjectFiles); | ||
|
||
var msTestProject = msbuildProjectFiles.FirstOrDefault(p => p.Contains("MSTestProject")); | ||
Assert.Null(msTestProject); | ||
|
||
var nunitTestProject = msbuildProjectFiles.FirstOrDefault(p => p.Contains("NUnitTestProject")); | ||
Assert.Null(nunitTestProject); | ||
} | ||
|
||
[Fact] | ||
public void FileSystemHelperFacts_CanHandleInvalidPath() | ||
{ | ||
var helper = CreateFileSystemHelper("!@@#$$@%&&*()_+"); | ||
|
||
var ex = Record.Exception(() => helper.GetFiles("**/*.csproj")); | ||
Assert.Null(ex); | ||
} | ||
|
||
private FileSystemHelper CreateFileSystemHelper(params string[] excludePatterns) | ||
{ | ||
var environment = new OmniSharpEnvironment(TestAssets.Instance.TestAssetsFolder, 1000, LogLevel.Information, null); | ||
var options = new OmniSharpOptions(); | ||
options.FileOptions.ExcludeSearchPatterns = excludePatterns; | ||
var helper = new FileSystemHelper(options, environment); | ||
return helper; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add search inclusions? (in the future perhaps?
Kinda feels like it would be sort of similar to how we used to be able to do things with project.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
"**/.git/**/*"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good one 👍