From 7b004bdeb48e14d23d58df4ae2c35dd3353e90d8 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 25 Oct 2017 08:25:10 +0200 Subject: [PATCH 1/2] consider a subset match as valid --- src/OmniSharp.Roslyn/Extensions/StringExtensions.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs b/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs index aec86c914e..d7cbab2527 100644 --- a/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs +++ b/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs @@ -31,6 +31,11 @@ public static bool IsSubsequenceMatch(this string completion, string partial) return true; } + if (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. From 80222e5d6f383a1ef3b364d956721b33c907e680 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 25 Oct 2017 20:48:09 +0200 Subject: [PATCH 2/2] added tests --- .../Extensions/StringExtensions.cs | 2 +- .../FindSymbolsFacts.cs | 29 ++++++++++++++++++- .../IntellisenseFacts.cs | 17 +++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs b/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs index d7cbab2527..84d37e3777 100644 --- a/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs +++ b/src/OmniSharp.Roslyn/Extensions/StringExtensions.cs @@ -31,7 +31,7 @@ public static bool IsSubsequenceMatch(this string completion, string partial) return true; } - if (completion.ToLowerInvariant().Contains(partial.ToLowerInvariant())) + if (partial.Length > 1 && completion.ToLowerInvariant().Contains(partial.ToLowerInvariant())) { return true; } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs index 2513212dc9..f205ea4104 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs @@ -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 FindSymbolsAsync(string code) { var testFile = new TestFile("dummy.cs", code); diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/IntellisenseFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/IntellisenseFacts.cs index 13271dfb9f..e98f5e8c55 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/IntellisenseFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/IntellisenseFacts.cs @@ -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")]