예제 #1
0
        public void Invoke()
        {
            if (AttachablesPackage.Manager != null)
            {
                try
                {
                    var line = m_span.GetEndPoint(m_snapshot).GetContainingLine();
                    var text = line.Extent.GetText();

                    text = text.Trim();
                    var match = TodoTagger.todoLineRegex.Match(text);
                    text = text.Substring(match.Index + match.Length);

                    var reminder = AttachablesPackage.Manager.AttachReminder(text.Trim(), m_path, FileLocation, line.LineNumber);

                    ITrackingPoint triggerPoint = m_snapshot.CreateTrackingPoint(
                        m_span.GetStartPoint(m_snapshot), PointTrackingMode.Positive);

                    AttachablesPackage.Manager.TrackReminder(triggerPoint, m_view, reminder);

                    m_enabled = false;
                    this.m_tagger.RaiseTagsChanged(m_span.GetSpan(m_snapshot));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
        }
예제 #2
0
        public void Invoke()
        {
            if (AttachablesPackage.Manager != null)
            {
                try
                {
                    var line = m_span.GetEndPoint(m_snapshot).GetContainingLine();
                    var text = line.Extent.GetText();



                    text = text.Trim();
                    var match = TodoTagger.todoLineRegex.Match(text);
                    text = text.Substring(match.Index + match.Length);


                    AttachablesPackage.Manager.WhenDateShowReminder(text.Trim(), DateTime.Now + m_delayBy, FileLocation, line.LineNumber);

                    m_enabled = false;
                    this.m_tagger.RaiseTagsChanged(m_span.GetSpan(m_snapshot));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
        }
        private void SaveCurrentTrackingData(Region sourceLocation)
        {
            try
            {
                if (!IsTracking())
                {
                    return;
                }

                ITextSnapshot textSnapshot = _trackingSpan.TextBuffer.CurrentSnapshot;
                SnapshotPoint startPoint   = _trackingSpan.GetStartPoint(textSnapshot);
                SnapshotPoint endPoint     = _trackingSpan.GetEndPoint(textSnapshot);

                var startLine = startPoint.GetContainingLine();
                var endLine   = endPoint.GetContainingLine();

                var textLineStart = _textView.GetTextViewLineContainingBufferPosition(startPoint);
                var textLineEnd   = _textView.GetTextViewLineContainingBufferPosition(endPoint);

                sourceLocation.StartColumn = startLine.Start.Position - textLineStart.Start.Position;
                sourceLocation.EndColumn   = endLine.End.Position - textLineEnd.Start.Position;
                sourceLocation.StartLine   = startLine.LineNumber + 1;
                sourceLocation.EndLine     = endLine.LineNumber + 1;
            }
            catch (InvalidOperationException)
            {
                // Editor throws InvalidOperationException in some cases -
                // We act like tracking isn't turned on if this is thrown to avoid
                // taking all of VS down.
            }
        }
 public static SpanInfo CreateFromBuffer(ITrackingSpan span)
 {
     return(new SpanInfo()
     {
         Span = span,
         Start = span.GetStartPoint(span.TextBuffer.CurrentSnapshot),
         End = span.GetEndPoint(span.TextBuffer.CurrentSnapshot)
     });
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplacementEdit"/> class.
        /// </summary>
        /// <param name="replacement">The SARIF replacement from which to construct the edit.</param>
        /// <param name="snapshot">The snapshot to which the edit will be applied.</param>
        public ReplacementEdit(ReplacementModel replacement, ITextSnapshot snapshot)
        {
            this.Text = replacement.InsertedString ?? string.Empty;

            ITrackingSpan replacementSpan = replacement.PersistentSpan.Span;
            SnapshotPoint start           = replacementSpan.GetStartPoint(snapshot);
            SnapshotPoint end             = replacementSpan.GetEndPoint(snapshot);

            this.Span = new SnapshotSpan(start, end);
        }
예제 #6
0
        public ReverseExpressionParser(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            _snapshot = snapshot;
            _buffer = buffer;
            _span = span;

            var loc = span.GetSpan(snapshot);
            var line = _curLine = snapshot.GetLineFromPosition(loc.Start);

            var targetSpan = new Span(line.Start.Position, span.GetEndPoint(snapshot).Position - line.Start.Position);
            _tokens = Classifier.GetClassificationSpans(new SnapshotSpan(snapshot, targetSpan));
        }
예제 #7
0
        private void ComputeApplicableToSpan(IEnumerable <ITrackingSpan> applicableToSpans)
        {
            // Requires UI thread for access to BufferGraph.
            IntellisenseUtilities.ThrowIfNotOnMainThread(this.JoinableTaskContext);

            ITrackingSpan newApplicableToSpan = Volatile.Read(ref this.applicableToSpan);

            foreach (var result in applicableToSpans)
            {
                var applicableToSpan = result;

                if (applicableToSpan != null)
                {
                    SnapshotSpan subjectAppSnapSpan = applicableToSpan.GetSpan(applicableToSpan.TextBuffer.CurrentSnapshot);

                    var surfaceAppSpans = this.TextView.BufferGraph.MapUpToBuffer(
                        subjectAppSnapSpan,
                        applicableToSpan.TrackingMode,
                        this.TextView.TextBuffer);

                    if (surfaceAppSpans.Count >= 1)
                    {
                        applicableToSpan = surfaceAppSpans[0].Snapshot.CreateTrackingSpan(surfaceAppSpans[0], applicableToSpan.TrackingMode);

                        newApplicableToSpan = IntellisenseUtilities.GetEncapsulatingSpan(
                            this.TextView,
                            newApplicableToSpan,
                            applicableToSpan);
                    }
                }
            }

            // Scope the applicableToSpan down to just the current line to ensure that interactions
            // with interactive controls such as lightbulb are not impeded by the tip appearing
            // far away from the mouse.
            if (newApplicableToSpan != null)
            {
                var currentSnapshot        = newApplicableToSpan.TextBuffer.CurrentSnapshot;
                var spanStart              = newApplicableToSpan.GetStartPoint(currentSnapshot);
                var spanEnd                = newApplicableToSpan.GetEndPoint(currentSnapshot);
                var triggerPointLine       = this.triggerPoint.GetPoint(currentSnapshot).GetContainingLine();
                var triggerPointLineExtent = triggerPointLine.Extent;
                var newStart               = Math.Max(triggerPointLineExtent.Start, spanStart);
                var newEnd = Math.Min(triggerPointLineExtent.End, spanEnd);
                if (newStart <= newEnd)
                {
                    newApplicableToSpan = currentSnapshot.CreateTrackingSpan(Span.FromBounds(newStart, newEnd), SpanTrackingMode.EdgeInclusive);
                }
            }

            Volatile.Write(ref this.applicableToSpan, newApplicableToSpan);
        }
예제 #8
0
        public ReverseExpressionParser(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            _snapshot = snapshot;
            _buffer   = buffer;
            _span     = span;

            var loc  = span.GetSpan(snapshot);
            var line = _curLine = snapshot.GetLineFromPosition(loc.Start);

            var targetSpan = new Span(line.Start.Position, span.GetEndPoint(snapshot).Position - line.Start.Position);

            _tokens = Classifier.GetClassificationSpans(new SnapshotSpan(snapshot, targetSpan));
        }
예제 #9
0
        public ReverseExpressionParser(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            _snapshot = snapshot;
            _buffer   = buffer;
            _span     = span;

            var loc  = span.GetSpan(snapshot);
            var line = _curLine = snapshot.GetLineFromPosition(loc.Start);

            var targetSpan = new Span(line.Start.Position, span.GetEndPoint(snapshot).Position - line.Start.Position);

            if (!_buffer.Properties.TryGetProperty(typeof(PythonClassifier), out _classifier) || _classifier == null)
            {
                throw new ArgumentException("Failed to get classifier from buffer");
            }
        }
예제 #10
0
        public ReverseExpressionParser(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            _snapshot = snapshot;
            _buffer   = buffer;
            _span     = span;

            var loc  = span.GetSpan(snapshot);
            var line = _curLine = snapshot.GetLineFromPosition(loc.Start);

            var targetSpan = new Span(line.Start.Position, span.GetEndPoint(snapshot).Position - line.Start.Position);

            _classifier = PythonTextBufferInfo.TryGetForBuffer(_buffer)?.Classifier;
            if (_classifier == null)
            {
                throw new ArgumentException(Strings.ReverseExpressionParserFailedToGetClassifierFromBufferException);
            }
        }
예제 #11
0
        public Genero4glReverseParser(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            _snapshot = snapshot;
            _buffer   = buffer;
            _span     = span;

            var loc  = span.GetSpan(snapshot);
            var line = _curLine = snapshot.GetLineFromPosition(loc.Start);

            var targetSpan = new Span(line.Start.Position, span.GetEndPoint(snapshot).Position - line.Start.Position);
            var snapSpan   = new SnapshotSpan(snapshot, targetSpan);

            if (Classifier != null)
            {
                _tokens     = Classifier.GetClassificationSpans(snapSpan);
                _tokenInfos = Classifier.GetTokens(snapSpan);
            }
        }
예제 #12
0
        public void Invoke()
        {
            if (AttachablesPackage.Manager != null)
            {
                try
                {
                    var line = m_span.GetEndPoint(m_snapshot).GetContainingLine();
                    var text = line.Extent.GetText();

                    text = ExtractTodoMessage(text);

                    AttachablesPackage.Manager.DueByReminder(text.Trim(), m_dueBy, m_friendly, FileLocation, line.LineNumber);

                    m_enabled = false;
                    this.m_tagger.RaiseTagsChanged(m_span.GetSpan(m_snapshot));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
        }
예제 #13
0
        void CalculateChange(TextContentChangedEventArgs e)
        {
#if DEBUG
            Util.LogTextChanges(e.Changes);
#endif

            if (_fullReparse == true)
            {
                return;
            }

            if (e.Changes.Count != 1)
            {
                _fullReparse = true;
                return;
            }

            ITextChange textChange = e.Changes[0];

            if (_editSpan == null)
            {
                _editSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(
                    textChange.NewPosition,
                    textChange.NewEnd - textChange.NewPosition,
                    SpanTrackingMode.EdgeInclusive);
#if DEBUG
                Util.Log("Created new edit span (" +
                         _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position + "," +
                         _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position + ") ",
                         _buffer.CurrentSnapshot.GetText(
                             _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position,
                             _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position -
                             _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position));
#endif
            }
            else
            {
                int oldEditStartPosition = _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position;
                int oldEditEndPosition   = _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position;
                // In many cases, new edit is auto-merged with old edit by tracking span. To be more'
                // specific, in all cases when new edit is adjacent to the old edit, it will be
                // auto-merged. We need to create a new tracking span only if the new edit was non-adjacent
                // to the old edit (i.e. a few characters before the old edit or a few characters after
                // the old edit).
                if (textChange.NewPosition < oldEditStartPosition ||
                    textChange.NewPosition > oldEditEndPosition)
                {
                    int newEditStartPosition = Math.Min(textChange.NewPosition, oldEditStartPosition);
                    int newEditEndPosition   = Math.Max(textChange.NewEnd, oldEditEndPosition);
                    _editSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(
                        newEditStartPosition,
                        newEditEndPosition - newEditStartPosition,
                        SpanTrackingMode.EdgeInclusive);
                }
#if DEBUG
                Util.Log("Updated edit span (" +
                         _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position + "," +
                         _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position + ") ",
                         _buffer.CurrentSnapshot.GetText(
                             _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position,
                             _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position -
                             _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position));
#endif
            }
        }
예제 #14
0
        private int HandleTyping(CommandID command, uint options, IntPtr pvIn, IntPtr pvOut)
        {
            // If we're in an automation function, *don't* trigger anything as a result of typing!
            if (VsShellUtilities.IsInAutomationFunction(this.provider.ServiceProvider))
            {
                return(this.PassThrough(command, options, pvIn, pvOut));
            }

            System.Diagnostics.Debug.Assert(command.Guid == VSConstants.VSStd2K);
            System.Diagnostics.Debug.Assert(command.ID == (int)VSConstants.VSStd2KCmdID.TYPECHAR ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.RETURN ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.TAB ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.BACKSPACE ||
                                            command.ID == (int)VSConstants.VSStd2KCmdID.DELETE);

            VSConstants.VSStd2KCmdID commandId = (VSConstants.VSStd2KCmdID)command.ID;
            char typedChar = char.MinValue;

            // Make sure the input is a typed character before getting it.
            if (commandId == VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvIn);
            }

            // Check for a commit character, and possibly commit a selection.
            if (commandId == VSConstants.VSStd2KCmdID.RETURN ||
                commandId == VSConstants.VSStd2KCmdID.TAB ||
                (commandId == VSConstants.VSStd2KCmdID.TYPECHAR && !CompletionSource.IsTokenTermCharacter(typedChar)))
            {
                if (this.session != null && !this.session.IsDismissed)
                {
                    // if the selection is fully selected, commit the current session
                    if (this.session.SelectedCompletionSet.SelectionStatus.IsSelected)
                    {
                        ITrackingSpan applicableSpan = this.session.SelectedCompletionSet.ApplicableTo;
                        this.session.Commit();

                        // If we ended with whitespace or '=', trigger another session!
                        char ch = (applicableSpan.GetEndPoint(applicableSpan.TextBuffer.CurrentSnapshot) - 1).GetChar();
                        if (char.IsWhiteSpace(ch) || ch == '=')
                        {
                            this.TriggerCompletion();
                        }

                        return(VSConstants.S_OK);    // don't add the commit character to the buffer
                    }
                    else
                    {
                        // if there is no selection, dismiss the session
                        this.session.Dismiss();
                    }
                }
            }

            // pass the command on through to the buffer to allow typing...
            int ret = this.PassThrough(command, options, pvIn, pvOut);

            if (commandId == VSConstants.VSStd2KCmdID.TYPECHAR && !typedChar.Equals(char.MinValue))
            {
                // If there is no active session, bring up completion
                if (this.session == null || this.session.IsDismissed)
                {
                    this.TriggerCompletion();
                }

                if (this.session != null && !this.session.IsDismissed)
                {
                    // the completion session is already active, so just filter
                    this.session.Filter();
                }
            }
            // else if BACKSPACE or DELETE, redo the filter...
            else if (commandId == VSConstants.VSStd2KCmdID.BACKSPACE ||
                     commandId == VSConstants.VSStd2KCmdID.DELETE)
            {
                if (this.session != null && !this.session.IsDismissed)
                {
                    this.session.Filter();
                }
            }

            return(ret);
        }
        public static CompletionAnalysis Make(IList <ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
        {
            Debug.Assert(tokens[0].Span.GetText() == "from");

            var  ns          = new List <string>();
            bool nsComplete  = false;
            bool seenImport  = false;
            bool seenName    = false;
            bool seenAs      = false;
            bool seenAlias   = false;
            bool includeStar = true;

            foreach (var token in tokens.Skip(1))
            {
                if (token == null || token.Span.End > span.GetEndPoint(textBuffer.CurrentSnapshot).Position)
                {
                    break;
                }

                if (!seenImport)
                {
                    if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier))
                    {
                        ns.Add(token.Span.GetText());
                        nsComplete = true;
                    }
                    else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Dot))
                    {
                        nsComplete = false;
                    }
                    seenImport = IsKeyword(token, "import");
                }
                else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma))
                {
                    seenName    = false;
                    seenAs      = false;
                    seenAlias   = false;
                    includeStar = false;
                }
                else if (token.Span.GetText() == "*")
                {
                    // Nothing comes after a star
                    return(EmptyCompletionContext);
                }
                else if (IsKeyword(token, "as"))
                {
                    seenAs = true;
                }
                else if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier))
                {
                    if (seenAlias)
                    {
                        return(EmptyCompletionContext);
                    }
                    else if (seenAs)
                    {
                        seenAlias = true;
                    }
                    else if (seenName)
                    {
                        return(EmptyCompletionContext);
                    }
                    else
                    {
                        seenName = true;
                    }
                }
                else
                {
                    includeStar = false;
                }
            }
            if (!seenImport)
            {
                if (nsComplete)
                {
                    return(new ImportKeywordCompletionAnalysis(span, textBuffer, options));
                }
                else
                {
                    return(ImportCompletionAnalysis.Make(tokens, span, textBuffer, options));
                }
            }

            if (!nsComplete || seenAlias || seenAs)
            {
                return(EmptyCompletionContext);
            }

            if (seenName)
            {
                return(new AsKeywordCompletionAnalysis(span, textBuffer, options));
            }

            return(new FromImportCompletionAnalysis(ns.ToArray(), includeStar, span, textBuffer, options));
        }
예제 #16
0
 public int GetEndPoint(IEditorBufferSnapshot snapshot) => _span.GetEndPoint(snapshot.As <ITextSnapshot>());
예제 #17
0
        public static int GetCurrentEnd(this ITrackingSpan trackingSpan)
        {
            ITextSnapshot snapshot = trackingSpan.TextBuffer.CurrentSnapshot;

            return(trackingSpan.GetEndPoint(snapshot).Position);
        }
예제 #18
0
 public SnapshotPoint GetEndPoint(ITextSnapshot snapshot)
 {
     return(_referenceSpan.GetEndPoint(snapshot));
 }
예제 #19
0
        public static CompletionAnalysis Make(IList<ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) {
            Debug.Assert(tokens[0].Span.GetText() == "from");

            var ns = new List<string>();
            bool nsComplete = false;
            bool seenImport = false;
            bool seenName = false;
            bool seenAs = false;
            bool seenAlias = false;
            bool includeStar = true;
            foreach (var token in tokens.Skip(1)) {
                if (token == null || token.Span.End > span.GetEndPoint(textBuffer.CurrentSnapshot).Position) {
                    break;
                }

                if (!seenImport) {
                    if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) {
                        ns.Add(token.Span.GetText());
                        nsComplete = true;
                    } else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Dot)) {
                        nsComplete = false;
                    }
                    seenImport = IsKeyword(token, "import");
                } else if (token.ClassificationType.IsOfType(PythonPredefinedClassificationTypeNames.Comma)) {
                    seenName = false;
                    seenAs = false;
                    seenAlias = false;
                    includeStar = false;
                } else if (token.Span.GetText() == "*") {
                    // Nothing comes after a star
                    return EmptyCompletionContext;
                } else if (IsKeyword(token, "as")) {
                    seenAs = true;
                } else if (token.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) {
                    if (seenAlias) {
                        return EmptyCompletionContext;
                    } else if (seenAs) {
                        seenAlias = true;
                    } else if (seenName) {
                        return EmptyCompletionContext;
                    } else {
                        seenName = true;
                    }
                } else {
                    includeStar = false;
                }
            }
            if (!seenImport) {
                if (nsComplete) {
                    return new ImportKeywordCompletionAnalysis(span, textBuffer, options);
                } else {
                    return ImportCompletionAnalysis.Make(tokens, span, textBuffer, options);
                }
            }

            if (!nsComplete || seenAlias || seenAs) {
                return EmptyCompletionContext;
            }

            if (seenName) {
                return new AsKeywordCompletionAnalysis(span, textBuffer, options);
            }

            return new FromImportCompletionAnalysis(ns.ToArray(), includeStar, span, textBuffer, options);
        }