提交 0797ef72 编写于 作者: A Ankita Khera

Various changes regarding testing, formatting, etc

上级 fdab9643
......@@ -45,7 +45,7 @@ private static UIElement CreateElement(string text)
Padding = new Thickness(0),
};
block.FontStyle = FontStyles.Normal;
// block.FontStyle = FontStyles.Normal;
block.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
......
......@@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.ExtractMethod;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
......@@ -43,19 +41,21 @@ public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSp
{
var tagsList = new List<ITagSpan<IntraTextAdornmentTag>>();
var dataTags = _tagAggregator.GetTags(spans);
foreach(var tag in dataTags)
if (spans.Count <= 0)
{
return tagsList;
}
foreach (var tag in dataTags)
{
if (spans.Count <= 0)
{
return tagsList;
}
var dataTagSpans = tag.Span.GetSpans(spans[0].Snapshot);
var textTag = tag.Tag;
if (dataTagSpans.Count > 0)
{
var dataTagSpan = dataTagSpans[0];
var adornmentSpan = new SnapshotSpan(dataTagSpan.Start, 0);
tagsList.Add(new TagSpan<IntraTextAdornmentTag>(adornmentSpan, new InlineParamNameHintsTag(textTag.TagName)));
tagsList.Add(new TagSpan<IntraTextAdornmentTag>(adornmentSpan, new InlineParamNameHintsTag(textTag.ParameterName)));
}
}
return tagsList;
......
......@@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints
/// can be used to create the UI tag
/// </summary>
[Export(typeof(ITaggerProvider))]
[ContentType("csharp")]
[ContentType(ContentTypeNames.CSharpContentType)]
[TagType(typeof(IntraTextAdornmentTag))]
[Name(nameof(InlineParamNameHintsTaggerProvider))]
class InlineParamNameHintsTaggerProvider : ITaggerProvider
......
......@@ -13,12 +13,11 @@ namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints
/// </summary>
class InlineParamNameHintDataTag : ITag
{
public readonly string TagName;
public readonly string ParameterName;
public InlineParamNameHintDataTag(string name)
{
TagName = name;
ParameterName = name;
}
}
}
......@@ -11,7 +11,6 @@
using Microsoft.CodeAnalysis.InlineParameterNameHints;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
......@@ -23,7 +22,7 @@ namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints
/// The TaggerProvider that calls upon the service in order to locate the spans and names
/// </summary>
[Export(typeof(ITaggerProvider))]
[ContentType("csharp")]
[ContentType(ContentTypeNames.CSharpContentType)]
[TagType(typeof(InlineParamNameHintDataTag))]
[Name(nameof(InlineParamNameHintsDataTaggerProvider))]
internal class InlineParamNameHintsDataTaggerProvider : AsynchronousTaggerProvider<InlineParamNameHintDataTag>
......@@ -53,7 +52,7 @@ protected override async Task ProduceTagsAsync(TaggerContext<InlineParamNameHint
foreach (var span in paramNameHintSpans)
{
context.AddTag(new TagSpan<InlineParamNameHintDataTag>(span.Span.ToSnapshotSpan(snapshotSpan.Snapshot), new InlineParamNameHintDataTag(span.Name))); //span.Item1.Length + 1, _format); //));
context.AddTag(new TagSpan<InlineParamNameHintDataTag>(new SnapshotSpan(snapshotSpan.Snapshot, span.Pos, 0), new InlineParamNameHintDataTag(span.Name))); //span.Item1.Length + 1, _format); //));
}
}
}
......
......@@ -16,11 +16,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineParameterNameHints
Public MustInherit Class AbstractInlineParamNameHintsTests
Protected Async Function VerifyParamHints(test As XElement, Optional optionIsEnabled As Boolean = True) As Tasks.Task
Await VerifyParamHints(test, optionIsEnabled, outOfProcess:=False)
Await VerifyParamHints(test, optionIsEnabled, outOfProcess:=True)
End Function
Private Async Function VerifyParamHints(test As XElement, optionIsEnabled As Boolean, outOfProcess As Boolean) As Tasks.Task
Using workspace = TestWorkspace.Create(test)
WpfTestRunner.RequireWpfFact($"{NameOf(AbstractInlineParamNameHintsTests)}.{NameOf(Me.VerifyParamHints)} creates asynchronous taggers")
......@@ -30,26 +25,31 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineParameterNameHints
workspace.GetService(Of IForegroundNotificationService))
Dim hostDocument = workspace.Documents.Single(Function(d) d.CursorPosition.HasValue)
Dim caretPosition = hostDocument.CursorPosition.Value
' Dim caretPosition = hostDocument.CursorPosition.Value
Dim snapshot = hostDocument.GetTextBuffer().CurrentSnapshot
Dim document = workspace.CurrentSolution.GetDocument(hostDocument.Id)
Dim context = New TaggerContext(Of InlineParamNameHintDataTag)(
document, snapshot, New SnapshotPoint(snapshot, caretPosition))
document, snapshot, New SnapshotPoint(snapshot, 0))
Await tagProducer.GetTestAccessor().ProduceTagsAsync(context)
Dim producedTags = From tag In context.tagSpans
Order By tag.Span.Start
Let spanName = tag.Tag.TagName
Select spanName + ":" + tag.Span.Span.ToTextSpan().ToString()
Let spanName = tag.Tag.ParameterName
Select spanName + ":" + tag.Span.Span.ToTextSpan().Start.ToString()
Dim expectedTags As New List(Of String)
For Each hostDocument In workspace.Documents
For Each nameAndSpans In hostDocument.AnnotatedSpans.OrderBy(Function(x) x.Value.First().Start)
For Each span In nameAndSpans.Value
expectedTags.Add(nameAndSpans.Key + ":" + span.ToString())
Next
Dim nameAndSpansList = hostDocument.AnnotatedSpans.SelectMany(
Function(name) name.Value,
Function(name, span) _
New With {.Name = name.Key,
.Span = span
})
For Each nameAndSpan In nameAndSpansList.OrderBy(Function(x) x.Span.Start)
expectedTags.Add(nameAndSpan.Name + ":" + nameAndSpan.Span.Start.ToString())
Next
Next
......
......@@ -6,6 +6,30 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineParameterNameHints
Public Class CSharpInlineParamNameHintsTests
Inherits AbstractInlineParamNameHintsTests
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestNoParameterSimpleCase() As Task
Dim input =
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class A
{
int testMethod()
{
return 5;
}
void Main()
{
$$testMethod();
}
}
</Document>
</Project>
</Workspace>
Await VerifyParamHints(input)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.InlineParameterNameHints)>
Public Async Function TestOneParameterSimpleCase() As Task
Dim input =
......
......@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Composition;
......@@ -30,14 +31,14 @@ public InlineParamNameHintsService()
{
}
public async Task<IEnumerable<NameAndSpan>> GetInlineParameterNameHintsAsync(
public async Task<IEnumerable<InlineParameterHint>> GetInlineParameterNameHintsAsync(
Document document,
TextSpan textSpan,
CancellationToken cancellationToken)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var node = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var spans = new List<NameAndSpan>();
var spans = new List<InlineParameterHint>();
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
......@@ -45,14 +46,14 @@ public InlineParamNameHintsService()
foreach (var invocation in invocations)
{
foreach (var argument in invo.ArgumentList.Arguments)
foreach (var argument in invocation.ArgumentList.Arguments)
{
if (argument.NameColon == null && IsExpressionWithNoName(argument.Expression))
{
var param = argument.DetermineParameter(semanticModel, cancellationToken: cancellationToken);
if (param != null)
{
spans.Add(new NameAndSpan(param.Name, argument.Span));
spans.Add(new InlineParameterHint(param.Name, argument.Span.Start));
}
}
}
......
......@@ -10,19 +10,19 @@
namespace Microsoft.CodeAnalysis.InlineParameterNameHints
{
readonly struct NameAndSpan
readonly struct InlineParameterHint
{
public NameAndSpan(string name, TextSpan span)
public InlineParameterHint(string name, int pos)
{
Name = name;
Span = span;
Pos = pos;
}
public string Name { get; }
public TextSpan Span { get; }
public int Pos { get; }
}
internal interface IInlineParamNameHintsService : ILanguageService
{
Task<IEnumerable<NameAndSpan>> GetInlineParameterNameHintsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken = default);
Task<IEnumerable<InlineParameterHint>> GetInlineParameterNameHintsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken = default);
}
}
......@@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Shared.Extensions;
#nullable enable
namespace Microsoft.CodeAnalysis.CSharp.Extensions
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册