Skip to content

Commit

Permalink
Merge pull request #990 from filipw/feature/subset-match
Browse files Browse the repository at this point in the history
Consider subset match valid for symbol lookups and completions
  • Loading branch information
DustinCampbell authored Oct 26, 2017
2 parents b27e083 + 86036fc commit fdb59d0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/OmniSharp.Roslyn/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static bool IsSubsequenceMatch(this string completion, string partial)
return true;
}

if (partial.Length > 1 && completion.ToLowerInvariant().Contains(partial.ToLowerInvariant()))
{
return true;
}

// Limit the number of results returned by making sure
// at least the first characters match.
// We can get far too many results back otherwise.
Expand Down
29 changes: 28 additions & 1 deletion tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,39 @@ private string NestedMethod() {}
var expected = new[]
{
"Method()",
"Method(string param)"
"Method(string param)",
"NestedMethod()"
};

Assert.Equal(expected, symbols);
}

[Fact]
public async Task Can_find_symbols_using_filter_with_subset_match()
{
const string code = @"
namespace Some.Long.Namespace
{
public class Options {}
public class Opossum {}
public interface IConfigurationOptions { }
public class ConfigurationOptions : IConfigurationOptions { }
}";

var usages = await FindSymbolsWithFilterAsync(code, "opti");
var symbols = usages.QuickFixes.Select(q => q.Text);

var expected = new[]
{
"Options",
"IConfigurationOptions",
"ConfigurationOptions"
};

Assert.Equal(expected, symbols);
}


private async Task<QuickFixResponse> FindSymbolsAsync(string code)
{
var testFile = new TestFile("dummy.cs", code);
Expand Down
17 changes: 17 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/IntellisenseFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ public Class1()
ContainsCompletions(completions.Select(c => c.CompletionText).Take(1), "NewGuid");
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task Returns_sub_sequence_completions_without_matching_firstletter(string filename)
{
const string input =
@"public class Class1 {
public Class1()
{
System.Guid.gu$$
}
}";

var completions = await FindCompletionsAsync(filename, input);
ContainsCompletions(completions.Select(c => c.CompletionText).Take(1), "NewGuid");
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
Expand Down

0 comments on commit fdb59d0

Please # to comment.