コード例 #1
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));
                }
            }
        }
コード例 #2
0
        protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset)
        {
            var selectedTokenType = selectedToken.GetTokenType();

            if (IsLeftBracket(selectedTokenType))
            {
                ITokenNode matchedNode;
                if (FindMatchingRightBracket(selectedToken, out matchedNode))
                {
                    var singleChar = IsSingleCharToken(matchedNode);
                    consumer.ConsumeMatchingBracesHighlighting(selectedToken.GetDocumentRange(), matchedNode.GetDocumentRange(), singleChar);
                }
                else
                {
                    consumer.ConsumeHighlighting(HighlightingAttributeIds.UNMATCHED_BRACE, selectedToken.GetDocumentStartOffset().ExtendRight(1));

                    if (matchedNode != null)
                    {
                        consumer.ConsumeHighlighting(HighlightingAttributeIds.UNMATCHED_BRACE, matchedNode.GetDocumentEndOffset().ExtendLeft(1));
                    }
                }
            }
            else if (selectedTokenType == ShaderLabTokenType.STRING_LITERAL)
            {
                if (treeOffset == selectedToken.GetTreeTextRange().StartOffset)
                {
                    consumer.ConsumeMatchingBracesHighlighting(
                        selectedToken.GetDocumentStartOffset().ExtendRight(1), selectedToken.GetDocumentEndOffset().ExtendLeft(1));
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Executes QuickFix or ContextAction. Returns post-execute method.
        /// </summary>
        /// <returns>
        /// Action to execute after document and PSI transaction finish. Use to open TextControls, navigate caret, etc.
        /// </returns>
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            MissingTokenErrorElement errorElement = _highlighting.AssociatedNode;
            IFile file = errorElement.GetContainingFile();

            Assertion.AssertNotNull(file, "file != null");

            TreeTextRange modifiedRange;
            TextRange     hotspotRange;

            // replace the error token by the missing text
            using (file.CreateWriteLock()) {
                modifiedRange = errorElement.GetTreeTextRange();
                ITokenNode previousToken = errorElement.GetPreviousToken();
                if (previousToken != null && previousToken.GetTokenType() == T4TokenNodeTypes.NewLine)
                {
                    modifiedRange = modifiedRange.Join(previousToken.GetTreeTextRange());
                }
                Assertion.AssertNotNull(file, "file != null");

                Pair <string, TextRange> textWithHotspotRange = GetMissingTextWithHotspotRange(errorElement);
                hotspotRange = textWithHotspotRange.Second;

                file.ReParse(modifiedRange, textWithHotspotRange.First);
            }

            if (!hotspotRange.IsValid)
            {
                return(null);
            }

            // create a hotspot around a directive name or value, with basic completion invoked
            return(textControl => {
                int startOffset = file.GetDocumentRange(modifiedRange.StartOffset).TextRange.StartOffset;
                var finalRange = new TextRange(startOffset + hotspotRange.StartOffset, startOffset + hotspotRange.EndOffset);
                string fieldName = textControl.Document.GetText(finalRange);

                Shell.Instance
                .GetComponent <LiveTemplatesManager>()
                .CreateHotspotSessionAtopExistingText(
                    solution,
                    TextRange.InvalidRange,
                    textControl,
                    LiveTemplatesManager.EscapeAction.LeaveTextAndCaret,
                    new HotspotInfo(
                        new TemplateField(fieldName, new MacroCallExpression(new BasicCompletionMacro()), 0),
                        finalRange))
                .Execute();
            });
        }
コード例 #4
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);
        }
コード例 #5
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));
                }
            }
        }