Skip to content

Commit

Permalink
small tab completion fix: tab completion to suggest only first from s…
Browse files Browse the repository at this point in the history
…hort name synonyms
  • Loading branch information
vlada-shubina committed Nov 23, 2022
1 parent e489aa8 commit 4cd8b15
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ internal partial class InstantiateCommand : BaseCommand<InstantiateCommandArgs>
{
private static readonly TimeSpan ConstraintEvaluationTimeout = TimeSpan.FromMilliseconds(1000);

internal static IEnumerable<CompletionItem> GetTemplateNameCompletions(string? tempalteName, IEnumerable<TemplateGroup> templateGroups, IEngineEnvironmentSettings environmentSettings)
internal static IEnumerable<CompletionItem> GetTemplateNameCompletions(string? templateName, IEnumerable<TemplateGroup> templateGroups, IEngineEnvironmentSettings environmentSettings)
{
TemplateConstraintManager constraintManager = new(environmentSettings);
if (string.IsNullOrWhiteSpace(tempalteName))
if (string.IsNullOrWhiteSpace(templateName))
{
return GetAllowedTemplateGroups(constraintManager, templateGroups)
.SelectMany(g => g.ShortNames, (g, shortName) => new CompletionItem(shortName, documentation: g.Description))
.Select(g => new CompletionItem(g.ShortNames[0], documentation: g.Description))
.Distinct()
.OrderBy(c => c.Label, StringComparer.OrdinalIgnoreCase)
.ToArray();
}

IEnumerable<TemplateGroup> matchingTemplateGroups = templateGroups.Where(t => t.ShortNames.Any(sn => sn.StartsWith(tempalteName, StringComparison.OrdinalIgnoreCase)));
IEnumerable<TemplateGroup> matchingTemplateGroups =
templateGroups.Where(t => t.ShortNames.Any(sn => sn.StartsWith(templateName, StringComparison.OrdinalIgnoreCase)));

return GetAllowedTemplateGroups(constraintManager, matchingTemplateGroups)
.SelectMany(g => g.ShortNames, (g, shortName) => new CompletionItem(shortName, documentation: g.Description))
.Where(c => c.Label.StartsWith(tempalteName))
.Select(g => new CompletionItem(g.ShortNames.First(sn => sn.StartsWith(templateName, StringComparison.OrdinalIgnoreCase)), documentation: g.Description))
.Distinct()
.OrderBy(c => c.Label, StringComparer.OrdinalIgnoreCase)
.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@
InsertText: sln,
Documentation: Create an empty solution containing no projects
},
{
Label: solution,
Kind: Value,
SortText: solution,
InsertText: solution,
Documentation: Create an empty solution containing no projects
},
{
Label: tool-manifest,
Kind: Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@
InsertText: sln,
Documentation: Create an empty solution containing no projects
},
{
Label: solution,
Kind: Value,
SortText: solution,
InsertText: solution,
Documentation: Create an empty solution containing no projects
},
{
Label: tool-manifest,
Kind: Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
Detail:
The target framework for the project.
Type: choice
net7.0 Target net7.0
Default: net7.0
net8.0 Target net8.0
Default: net8.0

},
{
Expand Down Expand Up @@ -114,8 +114,8 @@ Default: false
Detail:
The target framework for the project.
Type: choice
net7.0 Target net7.0
Default: net7.0
net8.0 Target net8.0
Default: net8.0

},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ nunit
nunit-test
page
proto
razor
razorclasslib
razorcomponent
react
sln
solution
tool-manifest
viewimports
viewstart
Expand Down

0 comments on commit 4cd8b15

Please sign in to comment.