Skip to content

Commit

Permalink
Fix caret affinity in GetReferencedSymbolsToLeftOfCaretAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Mar 30, 2021
1 parent fb2d906 commit d10df88
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,13 @@ private static async Task<ImmutableArray<ISymbol>> GetReferencedSymbolsToLeftOfC
CancellationToken cancellationToken)
{
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var token = await semanticModel.SyntaxTree.GetTouchingTokenAsync(caretPosition.Position, cancellationToken).ConfigureAwait(false);

// GetTouchingTokenAsync prefers to return tokens to the right of the caret. Adjust the caret position one
// to the left to avoid this.
if (caretPosition.Position == 0)
return ImmutableArray<ISymbol>.Empty;

var token = await semanticModel.SyntaxTree.GetTouchingTokenAsync(caretPosition.Position - 1, cancellationToken).ConfigureAwait(false);
var semanticInfo = semanticModel.GetSemanticInfo(token, document.Project.Solution.Workspace, cancellationToken);
return semanticInfo.ReferencedSymbols;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ public void Method()
VisualStudio.Editor.Verify.CurrentLineText("f.ToString()$$", assertCaretPosition: true);
}

[WpfFact]
public void TabTabBeforeSemicolon()
{
SetUpEditor(@"
public class Test
{
private object f;
public void Method()
{
$$;
}
}
");

VisualStudio.Editor.SendKeys("f.ToSt");

VisualStudio.Editor.SendKeys(VirtualKey.Tab);
VisualStudio.Editor.Verify.CurrentLineText("f.ToString$$;", assertCaretPosition: true);

VisualStudio.Editor.SendKeys(VirtualKey.Tab);
VisualStudio.Workspace.WaitForAllAsyncOperations(Helper.HangMitigatingTimeout, FeatureAttribute.SignatureHelp);
VisualStudio.Editor.Verify.CurrentLineText("f.ToString($$);", assertCaretPosition: true);

VisualStudio.Editor.SendKeys(VirtualKey.Tab);
VisualStudio.Editor.Verify.CurrentLineText("f.ToString()$$;", assertCaretPosition: true);
}

[WpfFact]
public void TabTabCompletionWithArguments()
{
Expand Down

0 comments on commit d10df88

Please sign in to comment.