From e1fff889adc413f44b67e4729c49bfc27c8964cb Mon Sep 17 00:00:00 2001 From: Nicolas Vandeginste Date: Thu, 29 Feb 2024 18:48:43 +0100 Subject: [PATCH 1/2] Fix #36 --- .../CompletionProvider/SuggestMockProvider.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs b/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs index 716e4b1..f52e5a6 100644 --- a/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs +++ b/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs @@ -2,13 +2,16 @@ using Abc.MoqComplete.Services; using JetBrains.ProjectModel; using JetBrains.ReSharper.Feature.Services.CodeCompletion; +using JetBrains.ReSharper.Feature.Services.CodeCompletion.Infrastructure; using JetBrains.ReSharper.Feature.Services.CodeCompletion.Infrastructure.LookupItems; using JetBrains.ReSharper.Feature.Services.CSharp.CodeCompletion.Infrastructure; using JetBrains.ReSharper.Features.Intellisense.CodeCompletion.CSharp; using JetBrains.ReSharper.Features.Intellisense.CodeCompletion.CSharp.Rules; using JetBrains.ReSharper.Psi; using JetBrains.ReSharper.Psi.CSharp; +using JetBrains.ReSharper.Psi.CSharp.Tree; using JetBrains.ReSharper.Psi.ExpectedTypes; +using JetBrains.ReSharper.Psi.ExtensionsAPI.Tree; using JetBrains.ReSharper.Psi.Resources; using JetBrains.ReSharper.Psi.Util; @@ -50,7 +53,16 @@ protected override bool AddLookupItems(CSharpCodeCompletionContext context, IIte private static ILookupItem GetLookupItem(CSharpCodeCompletionContext context, string proposedCompletion) { var lookupItem = CSharpLookupItemFactory.Instance.CreateKeywordLookupItem(context, proposedCompletion, TailType.None, PsiSymbolsThemedIcons.Variable.Id); - lookupItem.WithInitializedRanges(context.CompletionRanges, context.BasicContext); + + var node = context.NodeInFile; + while (!(node is ICSharpArgument) && node != null) node = node?.Parent; + if (node != null) + { + var arg = (ICSharpArgument)node; + var range = arg.GetExtendedDocumentRange(); + lookupItem.SetRanges(context.CompletionRanges.WithReplaceRange(range)); + } + lookupItem.SetTopPriority(); return lookupItem; } From ddc9b886b03394f215f366bcc0374cbf6d3132d1 Mon Sep 17 00:00:00 2001 From: Nicolas Vandeginste Date: Tue, 12 Mar 2024 15:31:04 +0100 Subject: [PATCH 2/2] Fix PR feedback. --- .../Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs b/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs index f52e5a6..99d833b 100644 --- a/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs +++ b/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/SuggestMockProvider.cs @@ -62,6 +62,10 @@ private static ILookupItem GetLookupItem(CSharpCodeCompletionContext context, st var range = arg.GetExtendedDocumentRange(); lookupItem.SetRanges(context.CompletionRanges.WithReplaceRange(range)); } + else + { + lookupItem.WithInitializedRanges(context.CompletionRanges, context.BasicContext); + } lookupItem.SetTopPriority(); return lookupItem;