Beispiel #1
0
        /// <summary>
        /// Trigger completion.
        /// </summary>
        private void TriggerCompletion()
        {
            // the caret must be in a non-projection location
            var caretPoint = textView.Caret.Position.Point.GetPoint(textBuffer => (!textBuffer.ContentType.IsOfType("projection")), PositionAffinity.Predecessor);

            if (!caretPoint.HasValue)
            {
                return;
            }

            var cp       = (SnapshotPoint)caretPoint;
            var position = cp.Position;

            // check for "//" before the current cursor position in this line
            var line = ((SnapshotPoint)caretPoint).Snapshot.GetLineFromPosition(((SnapshotPoint)caretPoint).Position);

            // get the text of this line
            var text = line.GetText();

            // get only the text portion which is left of the actual position
            text = text.Substring(0, position - line.Start.Position);

            // if there is a comment starting, don't do auto completion
            if (text.IndexOf("//", StringComparison.CurrentCultureIgnoreCase) != -1)
            {
                return;
            }

            var lex = new Lexer(cp.Snapshot.GetText());

            lex.AnalyzeForCommentsOnly();

            var res = lex.Tokens.FirstOrDefault(x => x.Position < cp.Position && x.Position + x.Length >= cp.Position);

            if (res != null)
            {
                return;
            }

            session = provider.CompletionBroker.CreateCompletionSession(textView, caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive), true);

            // subscribe to the Dismissed event on the session
            session.Dismissed += OnSessionDismissed;
            session.Start();
        }