提交 29b07304 编写于 作者: C CyrusNajmabadi

Classified blocks of text.

上级 bbbf0735
......@@ -210,7 +210,7 @@ protected override void AddDescriptionForProperty(IPropertySymbol symbol)
{
return await Classifier.GetClassifiedSymbolDisplayPartsAsync(
semanticModel, equalsValue.Value.Span,
this.Workspace, this.CancellationToken).ConfigureAwait(false);
this.Workspace, cancellationToken: this.CancellationToken).ConfigureAwait(false);
}
}
......
......@@ -138,7 +138,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LanguageServices
If semanticModel IsNot Nothing Then
Return Await Classifier.GetClassifiedSymbolDisplayPartsAsync(
semanticModel, equalsValue.Value.Span,
Me.Workspace, Me.CancellationToken).ConfigureAwait(False)
Me.Workspace, cancellationToken:=Me.CancellationToken).ConfigureAwait(False)
End If
End If
......
......@@ -119,11 +119,7 @@ private object GetValue(string keyName)
return _boxedProjectGuid;
case StandardTableKeyNames.Text:
return _sourceText.Lines.GetLineFromPosition(SourceSpan.Start).ToString().Trim();
case StandardTableKeyNames.FullText:
// When we support classified lines, change this to:
// return GetEllisionBufferAroundReference();
// case StandardTableKeyNames.FullText:
return _sourceText.Lines.GetLineFromPosition(SourceSpan.Start).ToString().Trim();
case StandardTableKeyNames2.TextInlines:
......@@ -182,70 +178,6 @@ internal bool TryCreateToolTip(string columnName, out object toolTip)
toolTip = textBlock;
return true;
}
private FrameworkElement GetEllisionBufferAroundReference()
{
var snapshotSpanAndCloseAction = GetSnapshotSpanAroundReference();
if (snapshotSpanAndCloseAction == null)
{
return null;
}
var snapshotSpan = snapshotSpanAndCloseAction.Item1;
var closeAction = snapshotSpanAndCloseAction.Item2;
var content = new ElisionBufferDeferredContent(
snapshotSpan,
_presenter._projectionBufferFactoryService,
_presenter._editorOptionsFactoryService,
_presenter._textEditorFactoryService);
var element = content.Create();
return element;
}
private Tuple<SnapshotSpan, Action> GetSnapshotSpanAroundReference()
{
var snapshotAndCloseAction = GetTextSnapshotAndCloseAction();
var snapshot = snapshotAndCloseAction.Item1;
var closeAction = snapshotAndCloseAction.Item2;
var wholeSnapshotSpan = new TextSpan(0, snapshot.Length);
var finalSpan = this.SourceSpan.Intersection(wholeSnapshotSpan) ?? default(TextSpan);
var lineNumber = snapshot.GetLineNumberFromPosition(finalSpan.Start);
var firstLineNumber = Math.Max(0, lineNumber - 2);
var lastLineNumber = Math.Min(snapshot.LineCount - 1, lineNumber + 2);
var snapshotSpan = new SnapshotSpan(snapshot,
Span.FromBounds(
snapshot.GetLineFromLineNumber(firstLineNumber).Start,
snapshot.GetLineFromLineNumber(lastLineNumber).End));
return Tuple.Create(snapshotSpan, closeAction);
}
private Tuple<ITextSnapshot, Action> GetTextSnapshotAndCloseAction()
{
// Get the existing editor snapshot (if this is already open in an editor),
// otherwise create a new snapshot that we can display.
var snapshot = _sourceText.FindCorrespondingEditorTextSnapshot();
if (snapshot != null)
{
return Tuple.Create(snapshot, (Action)null);
}
return OpenInvisibleEditorAndGetTextSnapshot();
}
private Tuple<ITextSnapshot, Action> OpenInvisibleEditorAndGetTextSnapshot()
{
var editor = _workspace.OpenInvisibleEditor(this.Document.Id);
return Tuple.Create(
editor.TextBuffer.CurrentSnapshot,
(Action)(() => editor.Dispose()));
}
}
}
}
\ No newline at end of file
......@@ -219,10 +219,11 @@ private TextSpan GetLineSpanForReference(SourceText sourceText, TextSpan referen
private TextSpan GetRegionSpanForReference(SourceText sourceText, TextSpan referenceSpan)
{
var lineNumber = sourceText.Lines.GetLineFromPosition(referenceSpan.Start).LineNumber;
const int AdditionalLineCountPerSide = 3;
var firstLineNumber = Math.Max(0, lineNumber - 2);
var lastLineNumber = Math.Min(sourceText.Lines.Count - 1, lineNumber + 2);
var lineNumber = sourceText.Lines.GetLineFromPosition(referenceSpan.Start).LineNumber;
var firstLineNumber = Math.Max(0, lineNumber - AdditionalLineCountPerSide);
var lastLineNumber = Math.Min(sourceText.Lines.Count - 1, lineNumber + AdditionalLineCountPerSide);
return TextSpan.FromBounds(
sourceText.Lines[firstLineNumber].Start,
......@@ -235,7 +236,9 @@ private TextSpan GetRegionSpanForReference(SourceText sourceText, TextSpan refer
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var classifiedLineParts = await Classifier.GetClassifiedSymbolDisplayPartsAsync(
semanticModel, widenedSpan, document.Project.Solution.Workspace, cancellationToken).ConfigureAwait(false);
semanticModel, widenedSpan, document.Project.Solution.Workspace,
insertSourceTextInGaps: true,
cancellationToken: cancellationToken).ConfigureAwait(false);
var taggedText = classifiedLineParts.ToTaggedText();
......
......@@ -55,45 +55,57 @@ public static class Classifier
internal static async Task<List<SymbolDisplayPart>> GetClassifiedSymbolDisplayPartsAsync(
Document document,
TextSpan textSpan,
CancellationToken cancellationToken)
bool insertSourceTextInGaps = false,
CancellationToken cancellationToken = default(CancellationToken))
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
return await GetClassifiedSymbolDisplayPartsAsync(
semanticModel, textSpan,
document.Project.Solution.Workspace,
insertSourceTextInGaps,
cancellationToken).ConfigureAwait(false);
}
internal static async Task<List<SymbolDisplayPart>> GetClassifiedSymbolDisplayPartsAsync(
SemanticModel semanticModel, TextSpan textSpan, Workspace workspace, CancellationToken cancellationToken)
SemanticModel semanticModel, TextSpan textSpan, Workspace workspace,
bool insertSourceTextInGaps = false,
CancellationToken cancellationToken = default(CancellationToken))
{
var classifiedSpans = GetClassifiedSpans(semanticModel, textSpan, workspace, cancellationToken);
var sourceText = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
return ConvertClassifications(sourceText, classifiedSpans);
return ConvertClassifications(sourceText, textSpan.Start, classifiedSpans, insertSourceTextInGaps);
}
private static List<SymbolDisplayPart> ConvertClassifications(
SourceText sourceText, IEnumerable<ClassifiedSpan> classifiedSpans)
SourceText sourceText, int startPosition, IEnumerable<ClassifiedSpan> classifiedSpans, bool insertSourceTextInGaps = false)
{
var parts = new List<SymbolDisplayPart>();
ClassifiedSpan? lastSpan = null;
foreach (var span in classifiedSpans)
{
// If there is space between this span and the last one, then add a space.
if (lastSpan != null && lastSpan.Value.TextSpan.End != span.TextSpan.Start)
if (startPosition != span.TextSpan.Start)
{
parts.AddRange(Space());
if (insertSourceTextInGaps)
{
parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, null,
sourceText.ToString(TextSpan.FromBounds(
startPosition, span.TextSpan.Start))));
}
else
{
parts.AddRange(Space());
}
}
var kind = GetClassificationKind(span.ClassificationType);
if (kind != null)
{
parts.Add(new SymbolDisplayPart(kind.Value, null, sourceText.ToString(span.TextSpan)));
lastSpan = span;
startPosition = span.TextSpan.End;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册