private static bool IsWhitespaceAfter([NotNull] ITreeNode node) { ITokenNode nextToken = node.GetNextToken(); return(nextToken != null && (nextToken.IsWhitespaceToken() || Char.IsWhiteSpace(nextToken.GetText()[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); }
/// <summary> /// Negative and positive signs must be spaced correctly. /// </summary> /// <param name="node"> /// The node to use. /// </param> /// <param name="tokenToCheck"> /// The token to check. /// </param> public static void NegativeAndPositiveSignsMustBeSpacedCorrectly(ITreeNode node, TokenNodeType tokenToCheck) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == tokenToCheck) { if (tokenNode.Parent is IOperatorExpression && !(tokenNode.Parent is IAdditiveExpression)) { ITokenNode nextToken = tokenNode.GetNextToken(); if (nextToken.IsWhitespace()) { using (WriteLockCookie.Create(true)) { // remove the whitespace or new line LowLevelModificationUtil.DeleteChild(nextToken); } } } } } if (currentNode.FirstChild != null) { NegativeAndPositiveSignsMustBeSpacedCorrectly(currentNode.FirstChild, tokenToCheck); } } }
/// <summary> /// Chained statement blocks must not be preceded by blank line. /// </summary> /// <param name="node"> /// The node. /// </param> private void ChainedStatementBlocksMustNotBePrecededByBlankLine(ITreeNode node) { // chained statement blocks are: // try catch finally // if else // so we'll be looking for catch finally and else List <TokenNodeType> searchTokens = new List <TokenNodeType> { CSharpTokenType.CATCH_KEYWORD, CSharpTokenType.FINALLY_KEYWORD, CSharpTokenType.ELSE_KEYWORD }; for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (searchTokens.Contains(tokenNode.GetTokenType())) { RemoveLineIfPreviousTokensAreNewLines(tokenNode); } } if (currentNode.FirstChild != null) { this.ChainedStatementBlocksMustNotBePrecededByBlankLine(currentNode.FirstChild); } } }
/// <summary> /// Element documentation headers must be preceded by blank line. /// </summary> /// <param name="node"> /// The node. /// </param> private void ElementDocumentationHeadersMustBePrecededByBlankLine(ITreeNode node) { // go back to first new line to the left // thisnew line must be immeidately preceded by a new line and if not insert one for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is IDocCommentNode) { ITokenNode token = currentNode as ITokenNode; ITokenNode firstNewLineToLeft = Utils.GetFirstNewLineTokenToLeft(token); if (firstNewLineToLeft != null) { ITokenNode tokenBeforeNewLine = firstNewLineToLeft.GetPrevToken(); // if we're the start of a code block then don't insert a new line. if (!tokenBeforeNewLine.IsNewLine() && tokenBeforeNewLine.GetTokenType() != CSharpTokenType.LBRACE && tokenBeforeNewLine.GetTokenType() != CSharpTokenType.END_OF_LINE_COMMENT) { firstNewLineToLeft.GetNextToken().InsertNewLineBefore(); } } } if (currentNode.FirstChild != null) { this.ElementDocumentationHeadersMustBePrecededByBlankLine(currentNode.FirstChild); } } }
/// <summary> /// The code must not contain multiple whitespace in a row. /// </summary> /// <param name="node"> /// The node. /// </param> public static void CodeMustNotContainMultipleWhitespaceInARow(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode currentToken = currentNode as ITokenNode; ITokenNode previousToken = currentToken.GetPrevToken(); if (previousToken != null) { if (currentToken.GetTokenType() == CSharpTokenType.WHITE_SPACE && previousToken.GetTokenType() == CSharpTokenType.WHITE_SPACE) { using (WriteLockCookie.Create(true)) { LowLevelModificationUtil.DeleteChild(currentToken); } } } } if (currentNode.FirstChild != null) { CodeMustNotContainMultipleWhitespaceInARow(currentNode.FirstChild); } } }
/// <summary> /// Preprocessor keywords must not be preceded by space. /// </summary> /// <param name="node"> /// The node to use. /// </param> public static void PreprocessorKeywordsMustNotBePrecededBySpace(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is IPreprocessorDirective) { IPreprocessorDirective preprocessorDirectiveNode = currentNode as IPreprocessorDirective; TreeOffset directiveTokenNodeOffset = preprocessorDirectiveNode.Directive.GetTreeStartOffset(); TreeOffset numberSignTokenNodeOffset = preprocessorDirectiveNode.NumberSign.GetTreeStartOffset(); if (directiveTokenNodeOffset - 1 != numberSignTokenNodeOffset) { // There is a gap between them ITokenNode tokenNode = preprocessorDirectiveNode.NumberSign; ITokenNode nextToken = tokenNode.GetNextToken(); using (WriteLockCookie.Create(true)) { // remove the whitespace or new line LowLevelModificationUtil.DeleteChild(nextToken); } } } if (currentNode.FirstChild != null) { PreprocessorKeywordsMustNotBePrecededBySpace(currentNode.FirstChild); } } }
/// <summary> /// Block statements must not contain embedded comments. /// </summary> /// <param name="node"> /// The node to process. /// </param> private void BlockStatementsMustNotContainEmbeddedComments(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == CSharpTokenType.LBRACE) { ITokenNode previousTokenNode = Utils.GetFirstNonWhitespaceTokenToLeft(tokenNode); if (previousTokenNode.GetTokenType() == CSharpTokenType.END_OF_LINE_COMMENT) { ICommentNode commentNode = previousTokenNode.GetContainingNode <ICommentNode>(true); MoveCommentInsideNextOpenCurlyBracket(commentNode); } } } if (currentNode.FirstChild != null) { this.BlockStatementsMustNotContainEmbeddedComments(currentNode.FirstChild); } } }
/// <summary> /// Code must not contain empty statements. /// </summary> /// <param name="node"> /// The node to process. /// </param> private void CodeMustNotContainEmptyStatements(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == CSharpTokenType.SEMICOLON && !(tokenNode.Parent is IForStatement)) { ITokenNode nextNonWhitespaceToken = Utils.GetFirstNonWhitespaceTokenToRight(tokenNode); while (nextNonWhitespaceToken.GetTokenType() == CSharpTokenType.SEMICOLON) { using (WriteLockCookie.Create(true)) { if (nextNonWhitespaceToken.GetNextToken().GetTokenType() == CSharpTokenType.WHITE_SPACE) { LowLevelModificationUtil.DeleteChild(nextNonWhitespaceToken.GetNextToken()); } // remove the spare semi colon LowLevelModificationUtil.DeleteChild(nextNonWhitespaceToken); nextNonWhitespaceToken = Utils.GetFirstNonWhitespaceTokenToRight(tokenNode); } } } } if (currentNode.FirstChild != null) { this.CodeMustNotContainEmptyStatements(currentNode.FirstChild); } } }
/// <summary> /// Block statements must not contain embedded regions. /// </summary> /// <param name="node"> /// The node to process. /// </param> private void BlockStatementsMustNotContainEmbeddedRegions(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == CSharpTokenType.LBRACE) { ITokenNode previousTokenNode = Utils.GetFirstNonWhitespaceTokenToLeft(tokenNode); ITokenNode previousTokenNode2 = previousTokenNode.GetPrevToken(); if (previousTokenNode.GetTokenType() == CSharpTokenType.PP_MESSAGE && previousTokenNode2.GetTokenType() == CSharpTokenType.PP_START_REGION) { IStartRegion startRegionNode = previousTokenNode.GetContainingNode <IStartRegion>(true); if (startRegionNode != null) { MoveRegionInsideNextOpenCurlyBracket(startRegionNode); } } } } if (currentNode.FirstChild != null) { this.BlockStatementsMustNotContainEmbeddedRegions(currentNode.FirstChild); } } }
/// <summary> /// Do not place regions within elements. /// </summary> /// <param name="node"> /// The node to process. /// </param> private void DoNotPlaceRegionsWithinElements(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == CSharpTokenType.PP_START_REGION) { IStartRegion startRegionNode = tokenNode.GetContainingNode <IStartRegion>(true); if (startRegionNode != null) { if (startRegionNode.Parent is IBlock) { // we're in a block so remove the end and start region IEndRegion endRegionNode = startRegionNode.EndRegion; using (WriteLockCookie.Create(true)) { LowLevelModificationUtil.DeleteChild(endRegionNode); LowLevelModificationUtil.DeleteChild(startRegionNode); } } } } } if (currentNode.FirstChild != null) { this.DoNotPlaceRegionsWithinElements(currentNode.FirstChild); } } }
private static bool IsWhitespaceBefore([NotNull] ITreeNode node) { ITokenNode previousToken = node.GetPreviousToken(); return(previousToken != null && (previousToken.IsWhitespaceToken() || Char.IsWhiteSpace(previousToken.GetText().Last()))); }
private void MakeFormat(FormattingRange range, IEnumerable <string> space) { PsiFormatterHelper.ReplaceSpaces(range.First, range.Last, space); // TODO: Move antiglueing logic into CalcSpaces() ITokenNode nextToken; ITokenNode prevToken = range.First.FindLastTokenIn(); if (prevToken != null) { nextToken = prevToken.GetNextToken(); } else { nextToken = range.First.NextSibling.FindFirstTokenIn(); if (nextToken != null) { prevToken = nextToken.GetPrevToken(); } } if (prevToken != null && nextToken != null) { ITokenNode separator = Context.CodeFormatter.GetMinimalSeparator(prevToken, nextToken); if (separator != null) { LowLevelModificationUtil.AddChildAfter(range.First, separator); } } }
/// <summary> /// Comments must be preceded by blank line. /// </summary> /// <param name="node"> /// The node. /// </param> private void CommentsMustBePreceededByBlankLine(ITreeNode node) { ITreeNode siblingMinus2; ITreeNode siblingMinus1; ITreeNode siblingMinus3; for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ICommentNode && !(currentNode is IDocCommentNode)) { if (Utils.IsFirstNodeOnLine(currentNode) && !(currentNode.Parent is ICSharpFile)) { siblingMinus1 = currentNode.PrevSibling; if (siblingMinus1 != null) { siblingMinus2 = siblingMinus1.PrevSibling; if (siblingMinus2 != null) { siblingMinus3 = siblingMinus2.PrevSibling; ITokenNode siblingMinus3Token = siblingMinus3 as ITokenNode; IWhitespaceNode siblingMinus2WhitespaceNode = siblingMinus2 as IWhitespaceNode; IWhitespaceNode siblingMinus3WhitespaceNode = siblingMinus3 as IWhitespaceNode; ICommentNode siblingMinus3CommentNode = siblingMinus3 as ICommentNode; if (siblingMinus3CommentNode != null) { // if the previous sibling is a comment then it doesn't need a new line. continue; } if (siblingMinus3Token != null && siblingMinus3Token.GetTokenType() == TokenType.LBRACE) { // if we're the start of a code block then don't insert a new line. continue; } if (siblingMinus2WhitespaceNode == null || siblingMinus3WhitespaceNode == null || !siblingMinus2WhitespaceNode.IsNewLine || !siblingMinus3WhitespaceNode.IsNewLine) { currentNode.InsertNewLineBefore(); ////CSharpFormatterHelper.FormatterInstance.Format(currentNode.Parent); ICSharpCodeFormatter codeFormatter = (ICSharpCodeFormatter)CSharpLanguage.Instance.LanguageService().CodeFormatter; codeFormatter.Format(currentNode.Parent); } } } } } if (currentNode.FirstChild != null) { this.CommentsMustBePreceededByBlankLine(currentNode.FirstChild); } } }
/// <summary> /// Curly brackets for multi line statements must not share line. /// </summary> /// <param name="node"> /// The node. /// </param> public void CurlyBracketsForMultiLineStatementsMustNotShareLine(ITreeNode node) { int offsetColumn = 0; for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == CSharpTokenType.LBRACE) { // check to see if this LBRACE { is on a line with another non whitespace token if (tokenNode.Parent is ICreationExpressionInitializer) { ICreationExpressionInitializer creationExpressionInitializerNode = tokenNode.Parent as ICreationExpressionInitializer; if (creationExpressionInitializerNode != null) { ITokenNode leftBrace = creationExpressionInitializerNode.LBrace; ITokenNode rightBrace = creationExpressionInitializerNode.RBrace; ICreationExpression creationExpressionNode = tokenNode.GetContainingNode <ICreationExpression>(true); if (creationExpressionNode != null) { ITreeNode first = creationExpressionNode.FirstChild; ITreeNode last = creationExpressionNode.LastChild; if (Utils.HasLineBreakBetween(first, last)) { if (Utils.TokenHasNonWhitespaceTokenToRightOnSameLine(leftBrace)) { // We'll be 4-1 honest. offsetColumn = Utils.GetOffsetToStartOfLine(leftBrace); ITreeNode newLine = leftBrace.InsertNewLineAfter(); Utils.InsertWhitespaceAfter(newLine, offsetColumn + 3); } if (rightBrace != null) { // check to see if this RBRACE { is on a line with another non whitespace token if (Utils.TokenHasNonWhitespaceTokenToLeftOnSameLine(rightBrace)) { ITreeNode newLine = rightBrace.InsertNewLineBefore(); Utils.InsertWhitespaceAfter(newLine, offsetColumn); } } } } } } } } if (currentNode.FirstChild != null) { this.CurlyBracketsForMultiLineStatementsMustNotShareLine(currentNode.FirstChild); } } }
internal AsyncVoidFunctionExpressionHighlighting( [NotNull] string message, [NotNull] ITokenNode asyncKeyword, [NotNull] Action removeAsyncModifier) : base(message) { this.asyncKeyword = asyncKeyword; this.removeAsyncModifier = removeAsyncModifier; }
internal InternalConstructorVisibilityHighlighting( [NotNull] string message, [NotNull] ITokenNode modifierTokenNode, [NotNull] IConstructorDeclaration constructorDeclaration, AccessRights visibility) : base(message) { this.modifierTokenNode = modifierTokenNode; ConstructorDeclaration = constructorDeclaration; Visibility = visibility; }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { ITreeNode node = _highlighting.AssociatedNode; using (node.CreateWriteLock()) { ITokenNode nextToken = node.GetNextToken(); ITreeNode end = nextToken != null && nextToken.GetTokenType() == T4TokenNodeTypes.NewLine ? nextToken : node; ModificationUtil.DeleteChildRange(node, end); } return(null); }
/// <summary> /// Commas must be spaced correctly. /// </summary> /// <param name="node"> /// The node to use. /// </param> public void EqualsMustBeSpacedCorrectly(ITreeNode node) { List <TokenNodeType> tokensThatCanBeLeftSideOfEquals = new List <TokenNodeType> { CSharpTokenType.WHITE_SPACE, CSharpTokenType.NE, CSharpTokenType.LT, CSharpTokenType.GT }; const string WhiteSpace = " "; for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ITokenNode tokenNode = currentNode as ITokenNode; if (tokenNode.GetTokenType() == CSharpTokenType.EQ) { ITokenNode nextToken = tokenNode.GetNextToken(); ITokenNode previousToken = tokenNode.GetPrevToken(); if (!nextToken.IsWhitespace()) { using (WriteLockCookie.Create(true)) { // insert a space LeafElementBase leafElement = TreeElementFactory.CreateLeafElement( CSharpTokenType.WHITE_SPACE, new JetBrains.Text.StringBuffer(WhiteSpace), 0, WhiteSpace.Length); LowLevelModificationUtil.AddChildBefore(nextToken, new ITreeNode[] { leafElement }); } } if (!tokensThatCanBeLeftSideOfEquals.Contains(previousToken.GetTokenType())) { using (WriteLockCookie.Create(true)) { // insert a space LeafElementBase leafElement = TreeElementFactory.CreateLeafElement( CSharpTokenType.WHITE_SPACE, new JetBrains.Text.StringBuffer(WhiteSpace), 0, WhiteSpace.Length); LowLevelModificationUtil.AddChildBefore(tokenNode, new ITreeNode[] { leafElement }); } } } } if (currentNode.FirstChild != null) { this.EqualsMustBeSpacedCorrectly(currentNode.FirstChild); } } }
public override ITokenNode GetMinimalSeparator(ITokenNode leftToken, ITokenNode rightToken) { if (leftToken is IWhitespaceNode || leftToken.GetTokenType() == PsiTokenType.WHITE_SPACE) { return null; } if (leftToken.GetTokenType() == PsiTokenType.END_OF_LINE_COMMENT && rightToken.GetTokenType() != PsiTokenType.NEW_LINE) { return PsiFormatterHelper.CreateNewLine("\r\n"); } if (rightToken is IWhitespaceNode || rightToken.GetTokenType() == PsiTokenType.WHITE_SPACE) { return null; } if (leftToken.GetTokenType() == PsiTokenType.LBRACE || leftToken.GetTokenType() == PsiTokenType.RBRACE || leftToken.GetTokenType() == PsiTokenType.RBRACE || leftToken.GetTokenType() == PsiTokenType.RBRACKET || leftToken.GetTokenType() == PsiTokenType.LPARENTH || leftToken.GetTokenType() == PsiTokenType.RPARENTH || leftToken.GetTokenType() == PsiTokenType.LT || leftToken.GetTokenType() == PsiTokenType.GT) { return null; } if (rightToken.GetTokenType() == PsiTokenType.LBRACE || rightToken.GetTokenType() == PsiTokenType.RBRACE || rightToken.GetTokenType() == PsiTokenType.RBRACE || rightToken.GetTokenType() == PsiTokenType.RBRACKET || rightToken.GetTokenType() == PsiTokenType.LPARENTH || rightToken.GetTokenType() == PsiTokenType.RPARENTH || rightToken.GetTokenType() == PsiTokenType.LT || rightToken.GetTokenType() == PsiTokenType.GT) { return null; } if (rightToken.GetTokenType() == PsiTokenType.ASTERISK || rightToken.GetTokenType() == PsiTokenType.QUEST) { return null; } if ((leftToken.GetTokenType() == PsiTokenType.COLON || leftToken.GetTokenType() == PsiTokenType.SEMICOLON) && (!(rightToken.GetTokenType() == PsiTokenType.C_STYLE_COMMENT || rightToken.GetTokenType() == PsiTokenType.END_OF_LINE_COMMENT))) { return PsiFormatterHelper.CreateNewLine("\r\n"); } TokenNodeType tokenType1 = leftToken.GetTokenType(); TokenNodeType tokenType2 = rightToken.GetTokenType(); if (myGlueingCache.Get(new TokenTypePair(tokenType1, tokenType2))) { return tokenType1 == PsiTokenType.END_OF_LINE_COMMENT ? PsiFormatterHelper.CreateNewLine("\r\n") : PsiFormatterHelper.CreateSpace(" "); } return null; }
public override ITokenNode GetMinimalSeparator(ITokenNode leftToken, ITokenNode rightToken) { if (leftToken is IWhitespaceNode || leftToken.GetTokenType() == PsiTokenType.WHITE_SPACE) { return(null); } if (leftToken.GetTokenType() == PsiTokenType.END_OF_LINE_COMMENT && rightToken.GetTokenType() != PsiTokenType.NEW_LINE) { return(PsiFormatterHelper.CreateNewLine("\r\n")); } if (rightToken is IWhitespaceNode || rightToken.GetTokenType() == PsiTokenType.WHITE_SPACE) { return(null); } if (leftToken.GetTokenType() == PsiTokenType.LBRACE || leftToken.GetTokenType() == PsiTokenType.RBRACE || leftToken.GetTokenType() == PsiTokenType.RBRACE || leftToken.GetTokenType() == PsiTokenType.RBRACKET || leftToken.GetTokenType() == PsiTokenType.LPARENTH || leftToken.GetTokenType() == PsiTokenType.RPARENTH || leftToken.GetTokenType() == PsiTokenType.LT || leftToken.GetTokenType() == PsiTokenType.GT) { return(null); } if (rightToken.GetTokenType() == PsiTokenType.LBRACE || rightToken.GetTokenType() == PsiTokenType.RBRACE || rightToken.GetTokenType() == PsiTokenType.RBRACE || rightToken.GetTokenType() == PsiTokenType.RBRACKET || rightToken.GetTokenType() == PsiTokenType.LPARENTH || rightToken.GetTokenType() == PsiTokenType.RPARENTH || rightToken.GetTokenType() == PsiTokenType.LT || rightToken.GetTokenType() == PsiTokenType.GT) { return(null); } if (rightToken.GetTokenType() == PsiTokenType.ASTERISK || rightToken.GetTokenType() == PsiTokenType.QUEST) { return(null); } if ((leftToken.GetTokenType() == PsiTokenType.COLON || leftToken.GetTokenType() == PsiTokenType.SEMICOLON) && (!(rightToken.GetTokenType() == PsiTokenType.C_STYLE_COMMENT || rightToken.GetTokenType() == PsiTokenType.END_OF_LINE_COMMENT))) { return(PsiFormatterHelper.CreateNewLine("\r\n")); } TokenNodeType tokenType1 = leftToken.GetTokenType(); TokenNodeType tokenType2 = rightToken.GetTokenType(); if (myGlueingCache.Get(new TokenTypePair(tokenType1, tokenType2))) { return (tokenType1 == PsiTokenType.END_OF_LINE_COMMENT ? PsiFormatterHelper.CreateNewLine("\r\n") : PsiFormatterHelper.CreateSpace(" ")); } return(null); }
static void TryGetContainerTypeAndAsyncKeyword( [NotNull] IParametersOwnerDeclaration container, [CanBeNull] out IType type, [CanBeNull] out ITokenNode asyncKeyword, [CanBeNull] out Action removeAsync, [CanBeNull] out IAttributesOwnerDeclaration attributesOwnerDeclaration) { switch (container) { case IMethodDeclaration methodDeclaration: type = methodDeclaration.Type; asyncKeyword = methodDeclaration.ModifiersList?.Modifiers.FirstOrDefault( node => node?.GetTokenType() == CSharpTokenType.ASYNC_KEYWORD); removeAsync = () => methodDeclaration.SetAsync(false); attributesOwnerDeclaration = type.IsValueTask() || type.IsGenericValueTask() || methodDeclaration.IsNullableAnnotationsContextEnabled() ? null : methodDeclaration; return; case ILambdaExpression lambdaExpression: type = lambdaExpression.ReturnType; asyncKeyword = lambdaExpression.AsyncKeyword; removeAsync = () => lambdaExpression.SetAsync(false); attributesOwnerDeclaration = null; return; case IAnonymousMethodExpression anonymousMethodExpression: type = anonymousMethodExpression.ReturnType; asyncKeyword = anonymousMethodExpression.AsyncKeyword; removeAsync = () => anonymousMethodExpression.SetAsync(false); attributesOwnerDeclaration = null; return; case ILocalFunctionDeclaration localFunctionDeclaration: type = localFunctionDeclaration.Type; asyncKeyword = localFunctionDeclaration.ModifiersList?.Modifiers.FirstOrDefault( node => node?.GetTokenType() == CSharpTokenType.ASYNC_KEYWORD); removeAsync = () => localFunctionDeclaration.SetAsync(false); attributesOwnerDeclaration = null; return; default: type = null; asyncKeyword = null; removeAsync = null; attributesOwnerDeclaration = null; return; } }
/// <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(); }); }
/// <summary> /// Remove empty comments. /// </summary> /// <param name="node"> /// The node to process. /// </param> public static void RemoveEmptyComments(ITreeNode node) { // we don't remove empty lines from Element Doc Comments in here // the DeclarationHeader types take care of that. for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is ITokenNode) { ICommentNode commentNode = currentNode as ICommentNode; if (commentNode != null && !(commentNode is IDocCommentNode)) { if (commentNode.CommentText.Trim() == string.Empty) { ITokenNode leftToken = Utils.GetFirstNewLineTokenToLeft((ITokenNode)currentNode); ITokenNode rightToken = Utils.GetFirstNewLineTokenToRight((ITokenNode)currentNode); if (leftToken == null) { leftToken = (ITokenNode)currentNode; } else { leftToken = leftToken.GetNextToken(); } if (rightToken == null) { rightToken = (ITokenNode)currentNode; } else { currentNode = rightToken.GetNextToken(); } using (WriteLockCookie.Create(true)) { LowLevelModificationUtil.DeleteChildRange(leftToken, rightToken); } } } } if (currentNode != null && currentNode.FirstChild != null) { RemoveEmptyComments(currentNode.FirstChild); } } }
public static bool CanUseImplicitLineContinuationBetween([NotNull] ITokenNode leftNode, [NotNull] ITokenNode rightNode) { Assertion.Assert(leftNode != null, "leftNode != null"); Assertion.Assert(rightNode != null, "rightNode != null"); var leftNodeParent = leftNode.Parent; Assertion.Assert(leftNodeParent != null, "leftNodeParent != null"); var leftNodeGrandParent = leftNodeParent.Parent; Assertion.Assert(leftNodeGrandParent != null, "leftNodeGrandParent != null"); var rightNodeParent = rightNode.Parent; Assertion.Assert(rightNodeParent != null, "rightNodeParent != null"); if (!leftNodeParent.IsVB10Supported()) { return(false); } var leftNodeTokenType = leftNode.GetTokenType(); var rightNodeTokenType = rightNode.GetTokenType(); return (leftNodeTokenType == VBTokenType.COMMA || leftNodeTokenType == VBTokenType.LPARENTH || rightNodeTokenType == VBTokenType.RPARENTH || leftNodeTokenType == VBTokenType.LBRACE || leftNodeTokenType == VBTokenType.RBRACE || rightNodeTokenType == VBTokenType.RBRACE || leftNodeTokenType == VBTokenType.EQ || leftNodeTokenType == VBTokenType.IN_KEYWORD || leftNodeTokenType == VBTokenType.FROM_KEYWORD || leftNodeParent is IQueryOperator || rightNodeParent is IQueryOperator || (leftNodeTokenType == VBTokenType.WITH_KEYWORD && leftNodeParent is IAnonymousObjectInitializer) || (leftNodeParent is IAttributeList && (leftNodeTokenType == VBTokenType.LT || leftNodeTokenType == VBTokenType.GT)) || (leftNodeGrandParent is IAttribute && (leftNodeTokenType == VBTokenType.LPARENTH || leftNodeTokenType == VBTokenType.RPARENTH)) || (leftNodeGrandParent is IPositionalArgument && rightNodeTokenType == VBTokenType.RPARENTH) || leftNodeTokenType == VBTokenType.XML_SCRIPLET_START || leftNodeTokenType == VBTokenType.XML_SCRIPLET_END || rightNodeTokenType == VBTokenType.XML_SCRIPLET_END || (leftNodeParent is IReferenceExpression && leftNodeTokenType == VBTokenType.DOT) || (leftNodeParent is IReferenceName && leftNodeTokenType == VBTokenType.DOT) || (leftNodeParent is IVBXmlMemberAccessExpression && leftNodeTokenType == VBTokenType.DOT && rightNodeTokenType != VBTokenType.DOT) || (leftNodeParent is IVBXmlMemberAccessExpression && leftNodeTokenType == VBTokenType.AT) || (leftNodeParent is IAttributeList && VBFileNavigator.GetByGlobalAttributes(leftNodeParent as IAttributeList) == null) || (OurOperatorSigns[leftNodeTokenType] && (leftNodeParent is IVBExpression || leftNodeParent is IAssignmentStatement))); }
public static AccessRights GetAccessRights([CanBeNull] ITokenNode accessModifier) { var modifierTokenType = accessModifier?.GetTokenType(); if (modifierTokenType == FSharpTokenType.PRIVATE) { return(AccessRights.PRIVATE); } if (modifierTokenType == FSharpTokenType.INTERNAL) { return(AccessRights.INTERNAL); } return(AccessRights.PUBLIC); }
/// <summary> /// Remove line if previous tokens are new lines. /// </summary> /// <param name="tokenNode"> /// The token node. /// </param> private static void RemoveLineIfPreviousTokensAreNewLines(ITokenNode tokenNode) { // first prev token will be whitespace padding out the line ITokenNode prevToken1 = tokenNode.GetPrevToken(); ITokenNode prevToken2 = prevToken1.GetPrevToken(); ITokenNode prevToken3 = prevToken2.GetPrevToken(); IWhitespaceNode prevToken2WhiteSpaceNode = prevToken2 as IWhitespaceNode; IWhitespaceNode prevToken3WhiteSpaceNode = prevToken3 as IWhitespaceNode; if (prevToken2WhiteSpaceNode != null && prevToken2WhiteSpaceNode.IsNewLine && prevToken3WhiteSpaceNode != null && prevToken3WhiteSpaceNode.IsNewLine) { Utils.RemoveNewLineBefore(tokenNode); } }
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))); }
private static ICSharpInvocationReference FindInvocationReference([NotNull] IReference reference) { if (reference is ICSharpInvocationReference invocationReference) { return(invocationReference); } ITreeNode treeNode = reference.GetTreeNode(); var argumentsOwner = treeNode.GetContainingNode <ICSharpArgumentsOwner>(); ITokenNode lBound = argumentsOwner?.LBound; if (lBound != null && treeNode.GetTreeEndOffset() <= lBound.GetTreeStartOffset()) { return(argumentsOwner.Reference); } return(null); }
/// <summary> /// Delete child range. /// </summary> /// <param name="first"> /// The first token to delete. /// </param> /// <param name="last"> /// The last token to delete. /// </param> private static void DeleteChildRange(ITokenNode first, ITokenNode last) { using (WriteLockCookie.Create(true)) { List <ITokenNode> a = new List <ITokenNode>(); ITokenNode tokenNodeToStopAt = last.GetNextToken(); for (ITokenNode foundToken = first; foundToken != tokenNodeToStopAt; foundToken = foundToken.GetNextToken()) { a.Add(foundToken); } foreach (ITokenNode tokenNode in a) { LowLevelModificationUtil.DeleteChild(tokenNode); } } }
/// <summary> /// Moves the IStartRegion specified inside the next open curly bracket and moves the corresponding end region inside too. /// </summary> /// <param name="startRegionNode"> /// The node to move. /// </param> public static void MoveRegionInsideNextOpenCurlyBracket(IStartRegion startRegionNode) { using (WriteLockCookie.Create(true)) { ITokenNode newLocationTokenNode = Utils.GetFirstNonWhitespaceTokenToRight(startRegionNode.Message); // if its a start region there is probably a corresponding end region // find it, and move it inside the block // find the position to delete from ITokenNode startOfTokensToDelete = Utils.GetFirstNewLineTokenToLeft(startRegionNode.NumberSign); ITokenNode endOfTokensToDelete = Utils.GetFirstNewLineTokenToRight(startRegionNode.Message); ITokenNode startOfTokensToFormat = startOfTokensToDelete.GetPrevToken(); IEndRegion endRegionNode = startRegionNode.EndRegion; IStartRegion newStartRegion = startRegionNode.Copy(null); ITokenNode firstNonWhitespaceAfterBracket = Utils.GetFirstNonWhitespaceTokenToRight(newLocationTokenNode); LowLevelModificationUtil.AddChildBefore(firstNonWhitespaceAfterBracket, new[] { newStartRegion }); newStartRegion.InsertNewLineAfter(); LowLevelModificationUtil.DeleteChildRange(startOfTokensToDelete, endOfTokensToDelete); IStartRegion endOfTokensToFormat = newStartRegion; if (endRegionNode != null) { startOfTokensToDelete = Utils.GetFirstNewLineTokenToLeft(endRegionNode.NumberSign); endOfTokensToDelete = Utils.GetFirstNewLineTokenToRight(endRegionNode.NumberSign); IEndRegion newEndRegionNode = endRegionNode.Copy(null); ITokenNode newLineToken = Utils.GetFirstNonWhitespaceTokenToLeft(endRegionNode.NumberSign); LowLevelModificationUtil.AddChildBefore(newLineToken, new[] { newEndRegionNode }); newEndRegionNode.InsertNewLineAfter(); LowLevelModificationUtil.DeleteChildRange(startOfTokensToDelete, endOfTokensToDelete); endOfTokensToFormat = (IStartRegion)newLineToken; } ////CSharpFormatterHelper.FormatterInstance.Format(startOfTokensToFormat, endOfTokensToFormat); ICSharpCodeFormatter codeFormatter = (ICSharpCodeFormatter)CSharpLanguage.Instance.LanguageService().CodeFormatter; codeFormatter.Format(startOfTokensToFormat, endOfTokensToFormat); } }
/// <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(); }
/// <summary> /// Moves the comment token specified after the next available non whitespace char (normally an open curly bracket). /// </summary> /// <param name="commentTokenNode"> /// The comment token to move. /// </param> public static void MoveCommentInsideNextOpenCurlyBracket(ITokenNode commentTokenNode) { using (WriteLockCookie.Create(true)) { // move comment inside block curly bracket here // we copy it, then insert it and then delete the copied one ITokenNode startOfTokensToDelete = Utils.GetFirstNonWhitespaceTokenToLeft(commentTokenNode).GetNextToken(); ITokenNode endOfTokensToDelete = Utils.GetFirstNewLineTokenToRight(commentTokenNode); ITokenNode startOfTokensToFormat = startOfTokensToDelete.GetPrevToken(); ITokenNode openCurlyBracketTokenNode = Utils.GetFirstNonWhitespaceTokenToRight(commentTokenNode); ITokenNode newCommentTokenNode = commentTokenNode.CopyElement(null); ITokenNode tokenNodeToInsertAfter = Utils.GetFirstNewLineTokenToRight(openCurlyBracketTokenNode); LowLevelModificationUtil.AddChildAfter(tokenNodeToInsertAfter, new[] { newCommentTokenNode }); LowLevelModificationUtil.AddChildAfter(newCommentTokenNode, newCommentTokenNode.InsertNewLineAfter()); DeleteChildRange(startOfTokensToDelete, endOfTokensToDelete); ITokenNode endOfTokensToFormat = newCommentTokenNode; CSharpFormatterHelper.FormatterInstance.Format(startOfTokensToFormat, endOfTokensToFormat); } }
public override ITokenNode GetMinimalSeparator(ITokenNode leftToken, ITokenNode rightToken) { return SecretFormatterHelper.CreateSpace(" "); }
public void Visit(ITokenNode node) { VisitLog.Add(node.ToString()); }
public UseImplicitLineContinuationHighlighting(ITokenNode tokenNode) { TokenNode = tokenNode; }
public RemoveByValKeywordHighlighting(ITokenNode tokenNode) { TokenNode = tokenNode; }
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)); } } }
/// <summary> /// Gets the first non-whitespace token that occurs after the token passed in. /// </summary> /// <param name="tokenNode"> /// The TokenNode to start at. /// </param> /// <returns> /// The first non-whitespace token. /// </returns> public static ITokenNode GetFirstNonWhitespaceTokenToRight(ITokenNode tokenNode) { ITokenNode currentToken = tokenNode.GetNextToken(); while (currentToken != null && currentToken.IsWhitespace()) { currentToken = currentToken.GetNextToken(); } return currentToken; }
/// <summary> /// Gets the first non-whitespace token that occurs after the token passed in. /// </summary> /// <param name="tokenNode"> /// The TokenNode to start at. /// </param> /// <returns> /// The first non-whitespace token. /// </returns> public static ITokenNode GetFirstNewLineTokenToRight(ITokenNode tokenNode) { ITokenNode currentToken = tokenNode.GetNextToken(); while (!currentToken.IsNewLine() && currentToken != null) { currentToken = currentToken.GetNextToken(); } return currentToken; }
/// <summary> /// True if the token is followed on the same line with a non-whitespace token. /// </summary> /// <param name="tokenNode"> /// THe token to start at. /// </param> /// <returns> /// True or false. /// </returns> public static bool TokenHasNonWhitespaceTokenToRightOnSameLine(ITokenNode tokenNode) { ITokenNode currentToken = tokenNode.GetNextToken(); if (currentToken == null) { return false; } while (currentToken.IsWhitespace() && !currentToken.IsNewLine() && currentToken != null) { currentToken = currentToken.GetNextToken(); } return currentToken != null && !currentToken.IsNewLine(); }
public override bool IsWhitespaceToken(ITokenNode token) { return token.IsWhitespaceToken(); }
// We have left brace. We'll find all right braces. // '[caret]LBRACE' protected override void TryHighlightToRight(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset) { if (selectedToken.GetTokenType() != CSharpTokenType.STRING_LITERAL) return; if (ExistingTreeNodes.ExistingTrees.Count == 0) return; DocumentRange lBraceRange = myProvider.DocumentCaret.ExtendRight(1); ITreeNode node = GetNodeFromRange(lBraceRange); string lang = GetLanguageFromNode(node); if (String.IsNullOrEmpty(lang)) return; string lBrother = node.UserData.GetData(Constants.YcTokenName); string rBrother = LanguageHelper.GetBrother(lang, lBrother, Brother.Right); if (String.IsNullOrEmpty(rBrother)) return; int leftNumber = Int32.Parse(node.UserData.GetData(Constants.YcTokNumber)); int rightNumber = LanguageHelper.GetNumberFromYcName(lang, rBrother); var helper = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance; IEnumerable<DocumentRange> ranges = helper.GetPairedRanges(lang, leftNumber, rightNumber, lBraceRange, true); foreach (DocumentRange range in ranges) { MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, lBraceRange, range); } /* * need for measurement Console.WriteLine(); Stopwatch timer = new Stopwatch(); timer.Start(); List<ITreeNode> forest = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance.GetForestWithToken(lang, lBraceRange); var lBraceTextRange = new TreeTextRange(treeOffset, 1); var rightRanges = new List<DocumentRange>(); foreach (ITreeNode tree in forest) { var lbraceNode = tree.FindNodeAt(lBraceTextRange); //if (lbraceNode == null) ////in general, this should not be. But while such a situation occurs // continue; var rBraceNode = lbraceNode.NextSibling; while (rBraceNode != null && rBraceNode.UserData.GetData(Constants.YcTokenName) != rBrother) { var text = rBraceNode.UserData.GetData(Constants.YcTokenName); if (string.IsNullOrEmpty(text)) Console.WriteLine(); rBraceNode = rBraceNode.NextSibling; } if (rBraceNode != null) rightRanges.Add(rBraceNode.GetNavigationRange()); } timer.Stop(); measure.Add(timer.Elapsed); if (measure.Count == 10) { using (var str = new StreamWriter(String.Format(newName, measure.Count))) { foreach (TimeSpan span in measure) { str.WriteLine(span); } } } foreach (DocumentRange range in rightRanges) { MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, lBraceRange, range); } */ }
public override bool IsWhitespaceToken(ITokenNode token) => token.IsWhitespaceToken();
/// <summary>Initializes a new instance of the <see cref="StringEmptySuggestion"/> class.</summary> /// <param name="solution">The solution.</param> /// <param name="node">The node.</param> public StringEmptySuggestion(ISolution solution, ITokenNode node) : base(NAME, node, node.GetDocumentRange(), "Empty string literals (\"\") should be string.Empty [Agent Johnson]") { this._solution = solution; this._node = node; }
/// <summary> /// Delete child range. /// </summary> /// <param name="first"> /// The first token to delete. /// </param> /// <param name="last"> /// The last token to delete. /// </param> private static void DeleteChildRange(ITokenNode first, ITokenNode last) { using (WriteLockCookie.Create(true)) { List<ITokenNode> a = new List<ITokenNode>(); ITokenNode tokenNodeToStopAt = last.GetNextToken(); for (ITokenNode foundToken = first; foundToken != tokenNodeToStopAt; foundToken = foundToken.GetNextToken()) { a.Add(foundToken); } foreach (ITokenNode tokenNode in a) { LowLevelModificationUtil.DeleteChild(tokenNode); } } }
public override bool IsTokenSkipped(ITokenNode node) { return base.IsTokenSkipped(node); }
public override ITokenNode GetMinimalSeparator(ITokenNode leftToken, ITokenNode rightToken) => null;
// We have right brace. We'll find all left braces. // 'RBRACE[caret]' protected override void TryHighlightToLeft(MatchingHighlightingsConsumer consumer, ITokenNode selectedToken, TreeOffset treeOffset) { if (selectedToken.GetTokenType() != CSharpTokenType.STRING_LITERAL) return; if (ExistingTreeNodes.ExistingTrees.Count == 0) return; DocumentRange rBraceRange = myProvider.DocumentCaret.ExtendLeft(1); ITreeNode node = GetNodeFromRange(rBraceRange); string lang = GetLanguageFromNode(node); if (String.IsNullOrEmpty(lang)) return; string rBrother = node.UserData.GetData(Constants.YcTokenName); string lbrother = LanguageHelper.GetBrother(lang, rBrother, Brother.Left); if (String.IsNullOrEmpty(lbrother)) return; int leftNumber = LanguageHelper.GetNumberFromYcName(lang, lbrother); int rightNumber = Int32.Parse(node.UserData.GetData(Constants.YcTokNumber)); var helper = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance; IEnumerable<DocumentRange> ranges = helper.GetPairedRanges(lang, leftNumber, rightNumber, rBraceRange, false); foreach (DocumentRange range in ranges) { MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, range, rBraceRange); } /* * need for measurement List<ITreeNode> forest = Helper.ReSharperHelper<DocumentRange, ITreeNode>.Instance.GetForestWithToken(lang, rBraceRange); var lBraceTextRange = new TreeTextRange(treeOffset.Shift(-1), 1); var leftRanges = new List<DocumentRange>(); foreach (ITreeNode tree in forest) { var rBraceNode = tree.FindNodeAt(lBraceTextRange); //if (rBraceNode == null) // //in general, this should not be. But while such a situation occurs // continue; var lbraceNode = rBraceNode.PrevSibling; while (lbraceNode != null && lbraceNode.UserData.GetData(Constants.YcTokenName) != lbrother) { lbraceNode = lbraceNode.PrevSibling; } if (lbraceNode != null) leftRanges.Add(lbraceNode.GetNavigationRange()); } foreach (DocumentRange range in leftRanges) { MatchingBracesContextHighlightersUtil.ConsumeMatchingBracesHighlighting(consumer, range, rBraceRange); } */ }
/// <summary> /// Returns the count of whitespace at the front of the line provided. /// </summary> /// <param name="tokenNode"> /// The tokenNode to start at. /// </param> /// <returns> /// The count of the leftmost whitespace. /// </returns> public static int GetOffsetToStartOfLine(ITokenNode tokenNode) { ITokenNode firstTokenOnLine = Utils.GetFirstNewLineTokenToLeft(tokenNode).GetNextToken(); TreeOffset startPosition = firstTokenOnLine.GetTreeStartOffset(); return tokenNode.GetTreeStartOffset() - startPosition; }
private void Scan(IState scan, int j, ITokenNode tokenNode) { int i = scan.Origin; var currentSymbol = scan.PostDotSymbol; var lexerRule = currentSymbol as ILexerRule; var token = tokenNode.Token; if (token.TokenType == lexerRule.TokenType) { var nextState = scan.NextState(); var parseNode = CreateParseNode( nextState, scan.ParseNode, tokenNode, j + 1); nextState.ParseNode = parseNode; if (_chart.Enqueue(j + 1, nextState)) LogScan(j + 1, nextState, token); } }
public UseShortCircuitOperatorsHighlighting(ITokenNode tokenNode) { TokenNode = tokenNode; }