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)); } } }
public static bool AddFoldingForBracedConstruct( [NotNull] this IHighlightingConsumer context, [CanBeNull] ITokenNode lbrace, [CanBeNull] ITokenNode rbrace, [CanBeNull] ITreeNode anchorToken = null, string placeholder = "{...}") { if (lbrace == null || rbrace == null) { return(false); } var start = lbrace.GetDocumentStartOffset(); var end = rbrace.GetDocumentEndOffset(); var anchorOffset = anchorToken?.GetDocumentEndOffset().Offset ?? -1; var document = start.Document; var endDocument = end.Document; if (document == null || end < start || document != endDocument) { return(false); } var foldingRange = new DocumentRange(start, end); if (anchorOffset != -1 && anchorOffset < start.Offset) { var offset = document.FindLastNewLineOffset(anchorOffset, start.Offset); foldingRange = foldingRange.SetStartTo(new DocumentOffset(document, offset)); } if (!foldingRange.IsNotEmptyNormalized()) { return(false); } if (foldingRange.CountNewLines() < 1) { return(false); } context.AddDefaultPriorityFolding("ReSharper Default Folding", foldingRange, placeholder); return(true); }
public int InsertBlockCommentPosition(ITokenNode tokenNode, int position) { return(position == tokenNode.GetDocumentStartOffset().Offset ? position : tokenNode.GetDocumentEndOffset().Offset); }
public TextRange GetBlockComment(ITokenNode tokenNode) { return(tokenNode.GetTokenType() == ShaderLabTokenType.MULTI_LINE_COMMENT ? new TextRange(tokenNode.GetDocumentStartOffset().Offset, tokenNode.GetDocumentEndOffset().Offset) : TextRange.InvalidRange); }