public void Add(object client, TrackingTag tag) { if (owner != client || Ready) { return; } data[tag.Start] = tag; }
/// <summary> /// Perform a binary search to find the tag whose start precedes a given location relative /// to a text snapshot. If the tags in the list are relative to another version of the /// text, their location will be mapped to the given snapshot. /// </summary> /// <param name="snapshot">Text snapshot</param> /// <param name="location">Location in the given snapshot</param> /// <returns> /// Index of the tag in the list; -1 indicates error /// </returns> public int FindTagAtLocation(ITextSnapshot snapshot, int location) { if (!Ready) { return(-1); } var firstTag = data.Values.FirstOrDefault(); if (firstTag == null) { return(-1); } bool sameVersion = (firstTag.Snapshot.Version.VersionNumber == snapshot.Version.VersionNumber); int?idx = null; if (sameVersion) { idx = data.Keys.BinarySearch(location); } else { if (location >= snapshot.Length) { return(-1); } var locationTag = new TrackingTag(snapshot, location, 1); var comparer = new TrackingTagComparer(snapshot); idx = data.Values.BinarySearch(locationTag, comparer); } if (idx == null) { return(-1); } if (idx < 0) { // location was not found; idx has the bitwise complement of the smallest element // that is after location, or the bitwise complement of the list count in case all // elements are before location. if (~idx == 0) // first tag starts after location { return(-1); } // Because we are looking for the nearest tag that starts before location, we will // return the element that precedes the one found idx = ~idx - 1; } return(idx.Value); }
protected override ClassificationTag GetClassification(TrackingTag tag) { var debugTag = tag as ExprTrackingTag; if (debugTag == null) { return(null); } return(new ExprTag(debugTag.Exprs, QmlClassificationType.Get(ClassificationType))); }
protected override ClassificationTag GetClassification(TrackingTag tag) { var syntaxTag = tag as QmlSyntaxTag; if (syntaxTag == null || syntaxTag.ClassificationType == null) { return(null); } return(new ClassificationTag(syntaxTag.ClassificationType)); }
protected override ErrorTag GetClassification(TrackingTag tag) { return(new ErrorTag("ERROR")); }
/// <summary> /// Conversion from TrackingTag to the type T of classification tag expected by the /// Visual Studio text editor extensibility. /// </summary> /// <param name="tag">TrackingTag to convert</param> /// <returns>Instance of T corresponding to the given TrackingTag</returns> protected abstract T GetClassification(TrackingTag tag);