Skip to content

Commit

Permalink
Merge pull request #1761 from SirIntruder/fixIntellisenseServicePerfo…
Browse files Browse the repository at this point in the history
…mance

Optimize Intellisense performance
  • Loading branch information
filipw authored Apr 15, 2020
2 parents 1318036 + 7c9437e commit 08017b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ public static async Task<IEnumerable<ISymbol>> GetCompletionSymbolsAsync(this Co
}

// if the completion provider encoded symbols into Properties, we can return them
if (properties.ContainsKey(SymbolName) && properties.ContainsKey(SymbolKind))
if (properties.TryGetValue(SymbolName, out string symbolNameValue)
&& properties.TryGetValue(SymbolKind, out string symbolKindValue)
&& int.Parse(symbolKindValue) is int symbolKindInt)
{
return recommendedSymbols.Where(x => x.Name == properties[SymbolName] && (int)x.Kind == int.Parse(properties[SymbolKind])).Distinct();
return recommendedSymbols
.Where(x => (int)x.Kind == symbolKindInt && x.Name.Equals(symbolNameValue, StringComparison.OrdinalIgnoreCase))
.Distinct();
}

return Enumerable.Empty<ISymbol>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<IEnumerable<AutoCompleteResponse>> Handle(AutoCompleteRequest

// get recommended symbols to match them up later with SymbolCompletionProvider
var semanticModel = await document.GetSemanticModelAsync();
var recommendedSymbols = await Recommender.GetRecommendedSymbolsAtPositionAsync(semanticModel, position, _workspace);
var recommendedSymbols = (await Recommender.GetRecommendedSymbolsAtPositionAsync(semanticModel, position, _workspace)).ToArray();

var isSuggestionMode = completionList.SuggestionModeItem != null;
foreach (var item in completionList.Items)
Expand Down
9 changes: 5 additions & 4 deletions src/OmniSharp.Roslyn/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;

namespace OmniSharp.Extensions
Expand All @@ -16,12 +17,12 @@ public static bool IsValidCompletionStartsWithExactCase(this string completion,

public static bool IsValidCompletionStartsWithIgnoreCase(this string completion, string partial)
{
return completion.ToLower().StartsWith(partial.ToLower());
return completion.StartsWith(partial, StringComparison.OrdinalIgnoreCase);
}

public static bool IsCamelCaseMatch(this string completion, string partial)
{
return new string(completion.Where(c => c >= 'A' && c <= 'Z').ToArray()).StartsWith(partial.ToUpper());
return new string(completion.Where(c => c >= 'A' && c <= 'Z').ToArray()).StartsWith(partial, StringComparison.OrdinalIgnoreCase);
}

public static bool IsSubsequenceMatch(this string completion, string partial)
Expand All @@ -31,7 +32,7 @@ public static bool IsSubsequenceMatch(this string completion, string partial)
return true;
}

if (partial.Length > 1 && completion.ToLowerInvariant().Contains(partial.ToLowerInvariant()))
if (partial.Length > 1 && completion.IndexOf(partial, StringComparison.InvariantCultureIgnoreCase) >= 0)
{
return true;
}
Expand All @@ -54,7 +55,7 @@ private static bool FirstLetterMatches(string word, string match)
return false;
}

return char.ToLowerInvariant(word.First()) == char.ToLowerInvariant(match.First());
return char.ToLowerInvariant(word[0]) == char.ToLowerInvariant(match[0]);
}
}
}

0 comments on commit 08017b2

Please sign in to comment.