Ejemplo n.º 1
0
        public sealed override bool ShouldTriggerCompletion(SourceText text, int caretPosition, CompletionTrigger trigger, OptionSet options)
        {
            var lineStart = text.Lines.GetLineFromPosition(caretPosition).Start;

            // check if the line starts with {whitespace}#{whitespace}{DirectiveName}{whitespace}"

            var poundIndex = text.IndexOfNonWhiteSpace(lineStart, caretPosition - lineStart);

            if (poundIndex == -1 || text[poundIndex] != '#')
            {
                return(false);
            }

            var directiveNameStartIndex = text.IndexOfNonWhiteSpace(poundIndex + 1, caretPosition - poundIndex - 1);

            if (directiveNameStartIndex == -1 || !text.ContentEquals(directiveNameStartIndex, DirectiveName))
            {
                return(false);
            }

            var directiveNameEndIndex = directiveNameStartIndex + DirectiveName.Length;
            var quoteIndex            = text.IndexOfNonWhiteSpace(directiveNameEndIndex, caretPosition - directiveNameEndIndex);

            if (quoteIndex == -1 || text[quoteIndex] != '"')
            {
                return(false);
            }

            return(true);
        }