本文整理汇总了C#中SnapshotSpan类的典型用法代码示例。如果您正苦于以下问题:C# SnapshotSpan类的具体用法?C# SnapshotSpan怎么用?C# SnapshotSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SnapshotSpan类属于命名空间,在下文中一共展示了SnapshotSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAndAddAdornment
void CreateAndAddAdornment(ITextViewLine line, SnapshotSpan span, Brush brush, bool extendToRight)
{
var markerGeometry = _view.TextViewLines.GetMarkerGeometry(span);
double left = 0;
double width = _view.ViewportWidth + _view.MaxTextRightCoordinate;
if (markerGeometry != null)
{
left = markerGeometry.Bounds.Left;
if (!extendToRight) width = markerGeometry.Bounds.Width;
}
Rect rect = new Rect(left, line.Top, width, line.Height);
RectangleGeometry geometry = new RectangleGeometry(rect);
GeometryDrawing drawing = new GeometryDrawing(brush, new Pen(), geometry);
drawing.Freeze();
DrawingImage drawingImage = new DrawingImage(drawing);
drawingImage.Freeze();
Image image = new Image();
image.Source = drawingImage;
Canvas.SetLeft(image, geometry.Bounds.Left);
Canvas.SetTop(image, geometry.Bounds.Top);
_layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
}
示例2: HasSuggestedActionsAsync
public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
{
return Task.Factory.StartNew(() =>
{
return !_view.Selection.IsEmpty;
});
}
示例3: EnterSelect
protected void EnterSelect(int start, int length)
{
var span = new SnapshotSpan(_textBuffer.CurrentSnapshot, start, length);
_textView.SelectAndMoveCaret(span);
_context.RunAll();
Assert.Equal(ModeKind.SelectCharacter, _vimBuffer.ModeKind);
}
示例4: GetClassificationSpans
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
IList<ClassificationSpan> spans = new List<ClassificationSpan>();
string text = span.GetText();
int index = text.IndexOf("#", StringComparison.Ordinal);
if (index > -1)
{
var result = new SnapshotSpan(span.Snapshot, span.Start + index, text.Length - index);
spans.Add(new ClassificationSpan(result, comment));
}
if (index == -1 || index > 0)
{
var trimmed = text.TrimStart();
var offset = text.Length - trimmed.Length;
string[] args = trimmed.Split(' ');
if (args.Length >= 2 && ValidKeywords.Contains(args[0].Trim().ToLowerInvariant()))
{
var result = new SnapshotSpan(span.Snapshot, span.Start + offset, args[0].Trim().Length);
spans.Add(new ClassificationSpan(result, keyword));
}
}
return spans;
}
示例5: GetSuggestedActions
public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
{
return
(
// code fixes
from tagSpan in _aggregator.GetTags(range)
where tagSpan.Tag is DiagnosticErrorTag
let diagnostic = tagSpan.Tag as DiagnosticErrorTag
from provider in _codeFixProviders
where provider.CanFix(diagnostic.Id)
let span = tagSpan.Span.GetSpans(_buffer).First()
from fix in provider.GetFixes(span)
group fix by provider into set
where set.Any()
select set as IEnumerable<CodeAction>
).Union(
// code refactorings
from provider in _refactoringProviders
from refactoring in provider.GetRefactorings(range)
group refactoring by provider into set
where set.Any()
select set as IEnumerable<CodeAction>
)
.Select(s => s.Select(ca => ca.ToSuggestedAction()))
.Select(s => new SuggestedActionSet(s))
;
}
示例6: TranslationAdornment
public TranslationAdornment(SnapshotSpan span, TranslationRequest request, Size viewportSize)
{
Span = span.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
Request = request;
Request.TranslationComplete += request_TranslationComplete;
InitializeComponent();
DataContext = this;
SetMaxSize(viewportSize);
_menu = spListBox.ContextMenu;
_menu.KeyUp += (sender, args) =>
{
if (args.Key == Key.Left || args.Key == Key.Escape)
{
CloseMenu();
}
};
_menu.Opened += (sender, args) => { _closeMenuRequested = false; };
_menu.Closed += (sender, args) => { _ignoreItemCommand = !_closeMenuRequested; };
ItemCommand = new RelayCommand<ItemCommandParameter>(ItemCommandExecute);
ItemOptionsCommand = new RelayCommand<ItemCommandParameter>(ItemOptionsCommandExecute);
MenuCommand = new RelayCommand<MenuItem>(MenuCommandExecute);
}
示例7: AugmentSignatureHelpSession
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures)
{
if (!session.TextView.Properties.ContainsProperty(SessionKey))
{
return;
}
// At the moment there is a bug in the javascript provider which causes it to
// repeatedly insert the same Signature values into an ISignatureHelpSession
// instance. There is no way, other than reflection, for us to prevent this
// from happening. Instead we just ensure that our provider runs after
// Javascript and then remove the values they add here
signatures.Clear();
// Map the trigger point down to our buffer.
var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot);
if (!subjectTriggerPoint.HasValue)
{
return;
}
var currentSnapshot = subjectTriggerPoint.Value.Snapshot;
var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0);
var applicableToSpan = currentSnapshot.CreateTrackingSpan(
querySpan.Start.Position,
0,
SpanTrackingMode.EdgeInclusive);
string encouragement = encouragements.GetRandomEncouragement();
if (encouragement != null)
{
var signature = new Signature(applicableToSpan, encouragement, "", "");
signatures.Add(signature);
}
}
示例8: ReplSpan
public ReplSpan(bool wasCommand, bool wasException, SnapshotSpan input, SnapshotSpan? output)
{
WasCommand = wasCommand;
WasException = wasException;
Input = input;
Output = output;
}
示例9: IsPreceededByEventAddSyntax
/// <summary>
/// Is the provided SnapshotPoint preceded by the '+= SomeEventType(Some_HandlerName' line
/// </summary>
private bool IsPreceededByEventAddSyntax(SnapshotSpan span)
{
// First find the last + character
var snapshot = span.Snapshot;
SnapshotPoint? plusPoint = null;
for (int i = span.Length - 1; i >= 0; i--)
{
var position = span.Start.Position + i;
var point = new SnapshotPoint(snapshot, position);
if (point.GetChar() == '+')
{
plusPoint = point;
break;
}
}
if (plusPoint == null)
{
return false;
}
var eventSpan = new SnapshotSpan(plusPoint.Value, span.End);
var eventText = eventSpan.GetText();
return
s_fullEventSyntaxRegex.IsMatch(eventText) ||
s_shortEventSyntaxRegex.IsMatch(eventText);
}
示例10: IsEventAddSelection
/// <summary>
/// Is the current selection that of the C# event add pattern?
/// </summary>
internal bool IsEventAddSelection(ITextView textView)
{
var textSelection = textView.Selection;
if (textSelection.IsEmpty || textSelection.Mode != TextSelectionMode.Stream)
{
return false;
}
var span = textView.Selection.StreamSelectionSpan.SnapshotSpan;
var lineRange = SnapshotLineRangeUtil.CreateForSpan(span);
if (lineRange.Count != 1)
{
return false;
}
// Include the character after the selection. Needed to disambiguate a couple
// of cases
var endPoint = span.End;
if (endPoint.Position < lineRange.End.Position)
{
endPoint = endPoint.Add(1);
}
var beforeSpan = new SnapshotSpan(lineRange.Start, endPoint);
return IsPreceededByEventAddSyntax(beforeSpan);
}
示例11: GetAllTags
private IEnumerable<SnapshotSpan> GetAllTags()
{
var snapshot = _textView.TextBuffer.CurrentSnapshot;
var snapshotSpan = new SnapshotSpan(snapshot, 0, snapshot.Length);
var tags = GetTags(snapshotSpan);
return tags;
}
示例12: CalculateDeletionStartFromStartPosition
private static int CalculateDeletionStartFromStartPosition(ITextSnapshot snapshot, int startPosition)
{
var position = startPosition - 1;
if (position < 0)
{
return 0;
}
while (true)
{
if (position > 0)
{
var ss = new SnapshotSpan(snapshot, position, 1);
var text = ss.GetText();
if (text != null && !"\r\n".Contains(text) && string.IsNullOrWhiteSpace(text))
{
--position;
continue;
}
++position;
}
return position;
}
}
示例13: GetClassificationSpans
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
var results = new List<ClassificationSpan>();
var snapshot = Buffer.CurrentSnapshot;
var stylesheet = Editor.Document.Stylesheet;
if (stylesheet != null)
{
try
{
foreach (var current in GetItems(stylesheet.Children, span))
{
if (current.Start > span.End)
break;
var type = ClassifierContextCache.Get(current.ClassifierType).GetClassification(Registry);
if (type == null)
continue;
var start = Math.Max(0, current.Start);
var length = Math.Min(snapshot.Length - start, current.Length);
results.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(start, length)), type));
}
}
catch (Exception ex)
{
Logger.Log(ex, "Failed to classify");
}
}
return results;
}
示例14: GetClassificationSpans
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
IList<ClassificationSpan> list = new List<ClassificationSpan>();
string text = span.GetText();
if (text.StartsWith("/// <binding"))
{
foreach (Match match in _binding.Matches(text))
{
var value = match.Groups["value"];
var result = new SnapshotSpan(span.Snapshot, span.Start + value.Index, value.Length);
list.Add(new ClassificationSpan(result, _formatDefinition));
}
}
else
{
int index = text.IndexOf(_searchText, StringComparison.Ordinal);
if (index == -1)
return list;
foreach (Match match in _task.Matches(text))
{
var name = match.Groups["name"];
var result = new SnapshotSpan(span.Snapshot, span.Start + name.Index, name.Length);
list.Add(new ClassificationSpan(result, _formatDefinition));
}
}
return list;
}
示例15: GetClassificationSpans
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) {
var result = new List<ClassificationSpan>();
var semanticModelResult = SemanticModelService.SemanticModelResult;
if(semanticModelResult == null) {
return result;
}
var classificationType = ClassificationTypeRegistryService.GetClassificationType(ClassificationTypeNames.DeadCode);
var extent = TextExtent.FromBounds(span.Start.Position, span.End.Position);
var diagnostics = semanticModelResult.CompilationUnit.Diagnostics;
var candidates = diagnostics.Where(diagnostic => diagnostic.Category == DiagnosticCategory.DeadCode)
.Where(d => d.Location.Extent.IntersectsWith(extent));
foreach (var diagnostic in candidates) {
var diagnosticSpan = new SnapshotSpan(semanticModelResult.Snapshot, new Span(diagnostic.Location.Start, diagnostic.Location.Length));
var classification = new ClassificationSpan(
diagnosticSpan.TranslateTo(span.Snapshot, SpanTrackingMode.EdgeExclusive),
classificationType);
result.Add(classification);
}
return result;
}