コード例 #1
0
        private static bool IsWhitespaceAfter([NotNull] ITreeNode node)
        {
            ITokenNode nextToken = node.GetNextToken();

            return(nextToken != null &&
                   (nextToken.IsWhitespaceToken() || Char.IsWhiteSpace(nextToken.GetText()[0])));
        }
コード例 #2
0
        public static string GetDoubleQuotedStringValue(ITokenNode token)
        {
            var text = token.GetText();

            if (text.Length <= 1)
            {
                return(null);
            }

            char firstChar = text[0],
                 lastChar  = text[text.Length - 1];

            if (firstChar == '\"' || firstChar == '\'')
            {
                var value = (lastChar == firstChar) ? text.Substring(1, text.Length - 2) : text.Substring(1);
                return(TryConvertPresentationToValue(value, firstChar));
            }

            if (lastChar == '\"' || lastChar == '\'')
            {
                var value = text.Substring(0, text.Length - 1);
                return(TryConvertPresentationToValue(value, lastChar));
            }

            return(null);
        }
コード例 #3
0
        private static bool IsWhitespaceBefore([NotNull] ITreeNode node)
        {
            ITokenNode previousToken = node.GetPreviousToken();

            return(previousToken != null &&
                   (previousToken.IsWhitespaceToken() || Char.IsWhiteSpace(previousToken.GetText().Last())));
        }
コード例 #4
0
        protected override void TryHighlightToLeft(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            TokenNodeType tokenType = selectedToken.GetTokenType();

            if (this.IsRightBracket(tokenType))
            {
                ITokenNode matchedToken;
                if (this.FindMatchingLeftBracket(selectedToken, out matchedToken))
                {
                    consumer.ConsumeMatchingBracesHighlighting(matchedToken.GetDocumentRange(), selectedToken.GetDocumentRange());
                    this.myLBraceDocumentRangeForIbh = matchedToken.GetDocumentRange();
                    this.myRBraceDocumentRangeForIbh = selectedToken.GetDocumentRange();
                    this.myHintTextGetter            = textControl => this.GetHintText(textControl, matchedToken);
                }
                else
                {
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                    if (matchedToken == null)
                    {
                        return;
                    }

                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", matchedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1));
                }
            }
            else
            {
                if (tokenType != NTriplesTokenType.STRING_LITERAL)
                {
                    return;
                }
                if (selectedToken.GetText()[0] == 64)
                {
                    if (!(treeOffset == selectedToken.GetTreeTextRange().EndOffset))
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1).Shift(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
                else
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().EndOffset)
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
        }
コード例 #5
0
        public override ISpecificCodeCompletionContext GetCompletionContext(CodeCompletionContext context)
        {
            TreeOffset startOffset = context.SelectedTreeRange.StartOffset;
            ITokenNode tokenNode   = GetTokenNode(context);

            if (tokenNode == null)
            {
                return(null);
            }

            int offset = tokenNode.GetTreeStartOffset().Offset;
            int start  = startOffset.Offset - offset;

            if (start <= 2)
            {
                return(null);
            }

            string text = tokenNode.GetText();

            if (start > text.Length)
            {
                return(null);
            }

            string commentText = text.Substring(2, start - 2);
            int    emojiStart  = commentText.LastIndexOf(':');

            if (emojiStart < 0)
            {
                return(null);
            }
            for (int index = emojiStart + 1; index < commentText.Length; ++index)
            {
                if ((index != emojiStart + 1 || !IsEmojiChar(commentText[index])) && (index <= emojiStart + 1 || !IsEmojiChar(commentText[index])))
                {
                    return(null);
                }
            }
            DocumentRange documentRange = context.File.GetDocumentRange(new TreeTextRange(new TreeOffset(offset + emojiStart + 2), new TreeOffset(offset + start)));

            if (!documentRange.IsValid())
            {
                return(null);
            }
            return(new ContextInDocComment(context, documentRange, new TextLookupRanges(documentRange.TextRange, documentRange.TextRange)));
        }
コード例 #6
0
        /// <summary>Analyzes the specified statement.</summary>
        /// <param name="node">The node.</param>
        /// <returns>Returns the suggestion base.</returns>
        public SuggestionBase[] Analyze(ITokenNode node)
        {
            var type = node.GetTokenType();
              if (!type.IsStringLiteral)
              {
            return null;
              }

              if (node.Language.Name != "CSHARP")
              {
            return null;
              }

              if (node.GetText() != "\"\"")
              {
            return null;
              }

              var parent = node.Parent;
              if (parent == null)
              {
            return null;
              }

              if (parent.Parent is ISwitchLabelStatement)
              {
            return null;
              }

              var attribute = node.GetContainingElement(typeof(IAttribute), true) as IAttribute;
              if (attribute != null)
              {
            return null;
              }

              var suggestions = new List<SuggestionBase>
              {
            new StringEmptySuggestion(this.solution, node)
              };

              return suggestions.ToArray();
        }
コード例 #7
0
        private static void HandleElement(ITextControl editor, ITreeNode element, int offset)
        {
            string stringToInsert = Clipboard.GetText();

            if (string.IsNullOrEmpty(stringToInsert))
            {
                return;
            }

            IDocCommentNode docCommentNode = element as IDocCommentNode;

            if (docCommentNode != null)
            {
                JetBrains.Util.dataStructures.TypedIntrinsics.Int32 <DocLine> currentLineNumber =
                    editor.Document.GetCoordsByOffset(editor.Caret.Offset()).Line;
                string currentLine = editor.Document.GetLineText(currentLineNumber);
                int    index       = currentLine.IndexOf("///", StringComparison.Ordinal);
                if (index < 0)
                {
                    return;
                }
                string prefix = currentLine.Substring(0, index);

                if (ShallEscape(docCommentNode, editor.Caret.Offset()) &&
                    JetBrains.UI.RichText.RichTextBlockToHtml.HtmlEncode(stringToInsert) != stringToInsert &&
                    MessageBox.ShowYesNo("Do you want the text to be escaped?"))
                {
                    stringToInsert = JetBrains.UI.RichText.RichTextBlockToHtml.HtmlEncode(stringToInsert);
                }

                stringToInsert = stringToInsert.Replace("\n", "\n" + prefix + "///");
            }

            ITokenNode token = element as ITokenNode;

            if (token != null)
            {
                if (token.GetTokenType() == CSharpTokenType.STRING_LITERAL &&
                    offset < token.GetTreeTextRange().EndOffset.Offset)
                {
                    string text = token.GetText();
                    if (text.StartsWith("@") && offset > token.GetTreeTextRange().StartOffset.Offset + 1)
                    {
                        stringToInsert = stringToInsert.Replace("\"", "\"\"");
                    }
                    else if (!text.StartsWith("@"))
                    {
                        stringToInsert = stringToInsert.
                                         Replace("\\", "\\\\").
                                         Replace("\a", "\\a").
                                         Replace("\b", "\\b").
                                         Replace("\f", "\\f").
                                         Replace("\n", "\\n").
                                         Replace("\r", "\\r").
                                         Replace("\t", "\\t").
                                         Replace("\v", "\\v").
                                         Replace("\'", "\\'").
                                         Replace("\"", "\\\"");
                    }
                }
            }

            editor.Document.InsertText(editor.Caret.Offset(), stringToInsert);
        }
コード例 #8
0
        public static void SpellCheck(IDocument document, ITokenNode token, ISpellChecker spellChecker,
                                      ISolution solution, DefaultHighlightingConsumer consumer, IContextBoundSettingsStore settingsStore, StringSettings settings)
        {
            if (spellChecker == null)
            {
                return;
            }

            string buffer    = unescape(token.GetText());
            ILexer wordLexer = new WordLexer(buffer);

            wordLexer.Start();
            while (wordLexer.TokenType != null)
            {
                string tokenText = wordLexer.GetCurrTokenText();
                if (SpellCheckUtil.ShouldSpellCheck(tokenText, settings.CompiledWordsToIgnore) &&
                    !spellChecker.TestWord(tokenText, true))
                {
                    IClassMemberDeclaration containingElement =
                        token.GetContainingNode <IClassMemberDeclaration>(false);
                    if (containingElement == null ||
                        !IdentifierResolver.IsIdentifier(containingElement, solution, tokenText))
                    {
                        CamelHumpLexer camelHumpLexer = new CamelHumpLexer(buffer, wordLexer.TokenStart, wordLexer.TokenEnd);
                        foreach (LexerToken humpToken in camelHumpLexer)
                        {
                            if (SpellCheckUtil.ShouldSpellCheck(humpToken.Value, settings.CompiledWordsToIgnore) &&
                                !spellChecker.TestWord(humpToken.Value, true))
                            {
                                //int start = token.GetTreeStartOffset().Offset + wordLexer.TokenStart;
                                //int end = start + tokenText.Length;

                                //TextRange range = new TextRange(start, end);
                                //DocumentRange documentRange = new DocumentRange(document, range);

                                DocumentRange documentRange =
                                    token.GetContainingFile().TranslateRangeForHighlighting(token.GetTreeTextRange());
                                documentRange = documentRange.ExtendLeft(-wordLexer.TokenStart);
                                documentRange = documentRange.ExtendRight(-1 * (documentRange.GetText().Length - tokenText.Length));

                                TextRange textRange = new TextRange(humpToken.Start - wordLexer.TokenStart,
                                                                    humpToken.End - wordLexer.TokenStart);

                                //string word = document.GetText(range);
                                string word = documentRange.GetText();
                                consumer.AddHighlighting(
                                    new StringSpellCheckHighlighting(
                                        word,
                                        documentRange,
                                        humpToken.Value,
                                        textRange,
                                        solution,
                                        spellChecker,
                                        settingsStore),
                                    documentRange);
                                break;
                            }
                        }
                    }
                }
                wordLexer.Advance();
            }
        }
        protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            TokenNodeType tokenType = selectedToken.GetTokenType();
            if (this.IsLeftBracket(tokenType))
            {
                ITokenNode matchedToken;
                if (this.FindMatchingRightBracket(selectedToken, out matchedToken))
                {
                    consumer.ConsumeMatchingBracesHighlighting(selectedToken.GetDocumentRange(), matchedToken.GetDocumentRange());
                }
                else
                {
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1));
                    if (matchedToken == null)
                    {
                        return;
                    }
                    consumer.ConsumeHighlighting(
                        "ReSharper Unmatched Brace", matchedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
            else
            {
                if (tokenType != NTriplesTokenType.STRING_LITERAL)
                {
                    return;
                }
                if (selectedToken.GetText()[0] == 64)
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().StartOffset.Shift(1))
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1).Shift(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
                else
                {
                    if (treeOffset != selectedToken.GetTreeTextRange().StartOffset)
                    {
                        return;
                    }

                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentRange().StartOffsetRange().ExtendRight(1),
                        selectedToken.GetDocumentRange().EndOffsetRange().ExtendLeft(1));
                }
            }
        }