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

Consider subset match valid for symbol lookups and completions #990

Merged
merged 3 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
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