public TreeTextRange GetNameRange() { var id = NameIdentifier; TreeOffset startOffset = id.GetTreeStartOffset(); return(new TreeTextRange(startOffset, startOffset + id.GetTextLength())); }
private static bool TestNode <T>(CSharpReparseContext context, string text, bool strictStart = false) where T : ITreeNode { var node = context.Parse(text); var tokenAt1 = node.FindTokenAt(new TreeOffset(context.WholeTextLength - 1)); var treeTextOffset = new TreeOffset(context.OriginalTextLength); var tokenAt2 = node.FindTokenAt(treeTextOffset); if (tokenAt1 == null || tokenAt2 == null) { return(false); } var errorNodeFinder = new ErrorNodeFinder(tokenAt1); errorNodeFinder.FindLastError(node); if (errorNodeFinder.Error != null && errorNodeFinder.Error.GetTreeStartOffset().Offset >= context.OriginalTextLength) { return(false); } ITreeNode commonParent = tokenAt2.FindCommonParent(tokenAt1); if (!(commonParent is T)) { return(false); } if (strictStart) { return(commonParent.GetTreeTextRange().StartOffset == treeTextOffset); } return(true); }
public bool Contains(TreeOffset offset) { var firstNode = myNodes[0]; ITreeNode lastNode = myNodes[myNodes.Length - 1]; /*if (myRule is BoundIndentingRule) * { * if (Nodes.Length > 2) * { * lastNode = myNodes[myNodes.Length - 2]; * } * else * { * return false; * } * }*/ if (myRule.Inside == IndentType.Both) { if (Nodes.Length > 2) { firstNode = myNodes[1]; lastNode = myNodes[myNodes.Length - 2]; } else { return(false); } return((offset.Offset >= firstNode.GetTreeTextRange().StartOffset.Offset) && (offset.Offset < lastNode.GetTreeTextRange().EndOffset.Offset)); } else if (myRule.Inside == IndentType.Right) { if (Nodes.Length > 1) { lastNode = myNodes[myNodes.Length - 2]; } else { return(false); } } else if (myRule.Inside == IndentType.Left) { if (Nodes.Length > 1) { firstNode = myNodes[1]; } else { return(false); } } var token = firstNode.GetPreviousToken(); while ((token != null) && (token.IsWhitespaceToken())) { firstNode = token; token = token.GetPrevToken(); } return((offset.Offset >= firstNode.GetTreeTextRange().StartOffset.Offset) && (offset.Offset < lastNode.GetTreeTextRange().EndOffset.Offset)); }
private static void ProcessT4FeatureBlock( [NotNull] IT4FeatureBlock featureBlock, [NotNull] CodeStructureElement parentElement, [NotNull] ICSharpFile cSharpFile, [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] CSharpCodeStructureProcessingState state ) { TreeTextRange t4Range = featureBlock.Code.GetTreeTextRange(); TreeTextRange cSharpRange = secondaryRangeTranslator.OriginalToGenerated(t4Range); if (!cSharpRange.IsValid()) { return; } TreeOffset cSharpStart = cSharpRange.StartOffset; TreeOffset cSharpEnd = cSharpRange.EndOffset; ITreeNode containingNode = cSharpFile.FindNodeAt(cSharpRange); if (containingNode == null) { return; } for (ITreeNode node = containingNode.FirstChild; node != null; node = node.NextSibling) { TreeOffset nodeStart = node.GetTreeStartOffset(); if (nodeStart >= cSharpStart && nodeStart < cSharpEnd) { ProcessCSharpNode(node, parentElement, state); } } }
public IGeneratorDataProvider CloneWithReplacedSelectedElement(ITreeNode selectedElement) { IPsiSourceFile sourceFile = selectedElement.GetSourceFile(); Debug.Assert(sourceFile != null, "psiSourceFile != null"); var psiFile = (ICSharpFile)sourceFile.GetPsiFile <CSharpLanguage>(selectedElement.GetDocumentRange()); TreeOffset treeStartOffset = selectedElement.GetTreeStartOffset(); Debug.Assert(psiFile != null, "psiFile != null"); return(new GeneratorDataProvider( this.Solution, selectedElement.GetProject(), this.PsiModule, this.PsiServices, sourceFile, psiFile, selectedElement, sourceFile.Document, selectedElement.GetTreeTextRange(), selectedElement.GetDocumentRange(), psiFile.FindTokenAt(treeStartOffset), treeStartOffset.Offset > 0 ? psiFile.FindNodeAt(treeStartOffset - 1) : null, this.ElementFactory )); }
public GherkinToken(TokenNodeType nodeType, [NotNull] IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) : base(nodeType, buffer, startOffset, endOffset) { _nodeType = nodeType; }
public TreeTextRange GetCommentRange() { TreeOffset startOffset = GetTreeStartOffset(); switch (CommentType) { case CommentType.EndOfLineComment: return(new TreeTextRange(startOffset + 2, startOffset + GetTextLength())); case CommentType.DocComment: return(new TreeTextRange(startOffset + 3, startOffset + GetTextLength())); case CommentType.MultilineComment: { string text = GetText(); int length = text.Length - (text.EndsWith("*/") ? 4 : 2); if (length <= 0) { return(TreeTextRange.InvalidRange); } return(new TreeTextRange(startOffset + 2, startOffset + 2 + length)); } } return(TreeTextRange.InvalidRange); }
/// <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); } } }
public TreeTextRange GetCommentRange() { TreeOffset startOffset = this.GetTreeStartOffset(); switch (this.CommentType) { case CommentType.END_OF_LINE_COMMENT: return(new TreeTextRange(startOffset + 2, startOffset + this.GetTextLength())); case CommentType.DOC_COMMENT: return(new TreeTextRange(startOffset + 3, startOffset + this.GetTextLength())); case CommentType.MULTILINE_COMMENT: { string text = this.GetText(); var length = text.Length - (text.EndsWith("*)") ? 4 : 2); if (length <= 0) { return(TreeTextRange.InvalidRange); } return(new TreeTextRange(startOffset + 2, startOffset + 2 + length)); } } return(TreeTextRange.InvalidRange); }
public IChameleonNode ReSync(CachingLexer cachingLexer, TreeTextRange changedRange, int insertedTextLen) { TreeOffset currStartOffset = GetTreeStartOffset(); int currLength = GetTextLength(); Logger.Assert(changedRange.StartOffset >= currStartOffset && changedRange.EndOffset <= (currStartOffset + currLength), "changedRange.StartOffset >= currStartOffset && changedRange.EndOffset <= (currStartOffset+currLength)"); int newLength = currLength - changedRange.Length + insertedTextLen; LanguageService languageService = Language.LanguageService(); if (languageService != null) { var parser = (IPsiParser)languageService.CreateParser(new ProjectedLexer(cachingLexer, new TextRange(currStartOffset.Offset, currStartOffset.Offset + newLength)), GetPsiModule(), GetSourceFile()); TreeElement newElement = parser.ParseStatement(); if (newElement.GetTextLength() == 0) { return(null); } if ((newElement.GetTextLength() == newLength) && (";".Equals(newElement.GetText().Substring(newElement.GetTextLength() - 1)))) { var psiFile = GetContainingNode <PsiFile>(); if (psiFile != null) { psiFile.ClearTables(); } return(newElement as IRuleDeclaration); } } return(null); }
private IncludeWithOffset FindIncludeAtOffset(TreeOffset offset, bool preferRoot) { // no includes, tree and document are matching if (_includes.Count == 0) return new IncludeWithOffset(offset.Offset); int includesLength = 0; int count = _includes.Count; for (int i = 0; i < count; i++) { IT4Include include = _includes[i]; TreeTextRange includeRange = include.GetTreeTextRange(); // the offset is before the include, in the root file if (offset < includeRange.StartOffset) return new IncludeWithOffset((offset - includesLength).Offset); // the offset is inside the include if (offset < includeRange.EndOffset) { // we're on an edge position: we can be just after the end of the root file, // or just at the beginning of an include; we make the choice using the preferRoot parameter if (offset == includeRange.StartOffset && preferRoot) return new IncludeWithOffset((offset - includesLength).Offset); return new IncludeWithOffset(offset - includeRange.StartOffset, include); } includesLength += includeRange.Length; } // the offset is after the include, in the root file return new IncludeWithOffset((offset - includesLength).Offset); }
/// <summary>Initializes a new instance of the <see cref="T4Token"/> class.</summary> /// <param name="nodeType">The token type.</param> /// <param name="buffer">The buffer holding the token text.</param> /// <param name="startOffset">The token starting offset in <paramref name="buffer"/>.</param> /// <param name="endOffset">The token ending offset in <paramref name="buffer"/>.</param> public T4Token( [NotNull] T4TokenNodeType nodeType, [NotNull] IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset ) : base(nodeType, buffer, startOffset, endOffset) { }
private static DocumentOffset GetDocumentOffset([NotNull] IFile file, TreeOffset treeOffset) { if (file == null) { throw new ArgumentNullException(nameof(file)); } return(GetDocumentRange(file, new TreeTextRange(treeOffset)).StartOffset); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { if (endOffset - startOffset > 2 && buffer[startOffset.Offset + 2] == '/' && (endOffset - startOffset == 3 || buffer[startOffset.Offset + 3] != '/')) { return(new DocComment(this, buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset)))); } return(new Comment(this, buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset)))); }
public void AddAnnotation(TreeOffset offset, IEnumerable <string> owners, IPsiSourceFile sourceFile) { var node = this; foreach (var owner in owners) { node = node.AddNamespaceNode(owner); } node.AddAnnotation(sourceFile, offset); }
private void AddAnnotation(IPsiSourceFile sourceFile, TreeOffset offset) { if (myAnnotations == null) { myAnnotations = new List <AttributedTypesTrieData>(1); } myAnnotations.Add(new AttributedTypesTrieData { SourceFile = sourceFile, Offset = offset.Offset }); }
public void AddAnnotation(string attributeName, TreeOffset offset, IEnumerable <string> ownerNamspaceNames, IPsiSourceFile sourceFile) { if (attributeName.EndsWith("Attribute")) { attributeName = attributeName.Substring(attributeName.Length - 9); } var node = EnsureNode(attributeName); node.AddAnnotation(offset, ownerNamspaceNames, sourceFile); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { if (Identifiers[this]) { return(new FSharpIdentifierToken(this, buffer, startOffset, endOffset)); } return(this != DEAD_CODE ? new FSharpToken(this, buffer, startOffset, endOffset) : new FSharpDeadCodeToken(this, buffer, startOffset, endOffset)); }
/// <summary> /// Appends a mapped node. /// </summary> /// <param name="treeNode">The tree node to add.</param> internal void AppendMapped([CanBeNull] ITreeNode treeNode) { if (treeNode == null) return; var startOffset = new TreeOffset(_builder.Length); treeNode.GetText(_builder); var endOffset = new TreeOffset(_builder.Length); _generatedRangeMap.Add( new TreeTextRange<Generated>(startOffset, endOffset), new TreeTextRange<Original>(treeNode.GetTreeTextRange())); }
/// <summary> /// Appends a mapped text. /// </summary> /// <param name="text">The text to add.</param> /// <param name="textRange">The original text range.</param> internal void AppendMapped([CanBeNull] string text, TreeTextRange textRange) { if (String.IsNullOrEmpty(text)) return; var startOffset = new TreeOffset(_builder.Length); _builder.Append(text); var endOffset = new TreeOffset(_builder.Length); _generatedRangeMap.Add( new TreeTextRange<Generated>(startOffset, endOffset), new TreeTextRange<Original>(textRange)); }
private IndentRange GetCurrentRangeForInsert(TreeOffset offset, IEnumerable <IndentRange> indentRanges) { IndentRange range = null; foreach (var indentRange in indentRanges) { if (indentRange.Contains(offset)) { range = GetCurrentRangeForInsert(offset, indentRange); } } return(range); }
private IndentRange GetCurrentRangeForInsert(TreeOffset offset, IndentRange indentRange) { if (indentRange.ChildRanges.Count() == 0) { return(indentRange); } var range = GetCurrentRangeForInsert(offset, indentRange.ChildRanges); if (range == null) { return(indentRange); } return(range); }
public TreeTextRange Translate(DocumentRange documentRange) { if (!documentRange.IsValid() || _sourceFile == null || !_sourceFile.IsValid()) { return(TreeTextRange.InvalidRange); } if (documentRange.Document != _sourceFile.Document) { foreach (IT4Include include in _includes) { if (include.DocumentRangeTranslator != null) { TreeTextRange textRange = include.DocumentRangeTranslator.Translate(documentRange); if (textRange.IsValid()) { return(textRange); } } } return(TreeTextRange.InvalidRange); } TextRange range = documentRange.TextRange; TreeOffset rootStartOffset = _root.GetTreeStartOffset(); // no includes, tree and document are matching if (_includes.Count == 0) { return(new TreeTextRange(rootStartOffset + range.StartOffset, rootStartOffset + range.EndOffset)); } TreeOffset startOffset = Translate(range.StartOffset); if (!startOffset.IsValid()) { return(TreeTextRange.InvalidRange); } TreeOffset endOffset = Translate(range.EndOffset); if (!endOffset.IsValid()) { return(TreeTextRange.InvalidRange); } return(new TreeTextRange(startOffset, endOffset)); }
/// <summary> /// Appends a mapped text. /// </summary> /// <param name="text">The text to add.</param> /// <param name="textRange">The original text range.</param> internal void AppendMapped([CanBeNull] string text, TreeTextRange textRange) { if (String.IsNullOrEmpty(text)) { return; } var startOffset = new TreeOffset(_builder.Length); _builder.Append(text); var endOffset = new TreeOffset(_builder.Length); _generatedRangeMap.Add( new TreeTextRange <Generated>(startOffset, endOffset), new TreeTextRange <Original>(textRange)); }
/// <summary> /// Appends a mapped node. /// </summary> /// <param name="treeNode">The tree node to add.</param> internal void AppendMapped([CanBeNull] ITreeNode treeNode) { if (treeNode == null) { return; } var startOffset = new TreeOffset(_builder.Length); treeNode.GetText(_builder); var endOffset = new TreeOffset(_builder.Length); _generatedRangeMap.Add( new TreeTextRange <Generated>(startOffset, endOffset), new TreeTextRange <Original>(treeNode.GetTreeTextRange())); }
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))); }
public bool ContainsNewLine(TreeOffset offset) { var firstNode = myNodes[0]; var lastNode = myNodes[myNodes.Length - 1]; /*if(myRule.Inside == IndentType.Both) * { * if (Nodes.Length > 2) * { * firstNode = myNodes[1]; * lastNode = myNodes[myNodes.Length - 2]; * } else * { * return false; * } * return ((offset.Offset >= firstNode.GetTreeTextRange().StartOffset.Offset) && (offset.Offset < lastNode.GetTreeTextRange().EndOffset.Offset)); * } else if(myRule.Inside == IndentType.Right) * { * if (Nodes.Length > 1) * { * lastNode = myNodes[myNodes.Length - 2]; * } * else * { * return false; * } * } else if(myRule.Inside == IndentType.Left) * { * if (Nodes.Length > 1) * { * firstNode = myNodes[1]; * } * else * { * return false; * } * }*/ var token = firstNode.GetPreviousToken(); while ((token != null) && (token.IsWhitespaceToken())) { firstNode = token; token = token.GetPrevToken(); } return((offset.Offset >= firstNode.GetTreeTextRange().StartOffset.Offset) && (offset.Offset < lastNode.GetTreeTextRange().EndOffset.Offset)); }
private TreeOffset Translate(int documentOffset) { int offset = 0; foreach (var include in Includes) { var includeRange = include.GetTreeTextRange(); var finalOffset = new TreeOffset(documentOffset + offset); // The matching file offset starts before the current include, we got it if (finalOffset < includeRange.StartOffset) { return(finalOffset); } offset += includeRange.Length; } // The offset is in the file, after the last include return(new TreeOffset(documentOffset + offset)); }
private IncludeWithOffset FindIncludeAtOffset(TreeOffset offset, bool preferRoot) { // no includes, tree and document are matching if (_includes.Count == 0) { return(new IncludeWithOffset(offset.Offset)); } int includesLength = 0; int count = _includes.Count; for (int i = 0; i < count; i++) { IT4Include include = _includes[i]; TreeTextRange includeRange = include.GetTreeTextRange(); // the offset is before the include, in the root file if (offset < includeRange.StartOffset) { return(new IncludeWithOffset((offset - includesLength).Offset)); } // the offset is inside the include if (offset < includeRange.EndOffset) { // we're on an edge position: we can be just after the end of the root file, // or just at the beginning of an include; we make the choice using the preferRoot parameter if (offset == includeRange.StartOffset && preferRoot) { return(new IncludeWithOffset((offset - includesLength).Offset)); } return(new IncludeWithOffset(offset - includeRange.StartOffset, include)); } includesLength += includeRange.Length; } // the offset is after the include, in the root file return(new IncludeWithOffset((offset - includesLength).Offset)); }
/// <summary> /// Initializes a new instance of the <see cref="T4Token"/> class. /// </summary> /// <param name="nodeType">The token type.</param> /// <param name="buffer">The buffer holding the token text.</param> /// <param name="startOffset">The token starting offset in <paramref name="buffer"/>.</param> /// <param name="endOffset">The token ending offset in <paramref name="buffer"/>.</param> public T4Token(T4TokenNodeType nodeType, IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) : base(nodeType, buffer, startOffset, endOffset) { }
// 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); } */ }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { throw new System.NotImplementedException(); }
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)); } } }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new NitraToken(NitraFakeTokenNodeType.Instance, buffer, startOffset, endOffset); }
public NitraToken(NodeType nodeType, [NotNull] IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) : base(nodeType, buffer, startOffset, endOffset) { }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new NamespaceSeparatorTokenElement(this); }
// 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); } */ }
private TreeOffset Translate(int documentOffset) { int offset = 0; foreach (IT4Include include in _includes) { TreeTextRange includeRange = include.GetTreeTextRange(); var finalOffset = new TreeOffset(documentOffset + offset); // the matching file offset starts before the include, we got it if (finalOffset < includeRange.StartOffset) return finalOffset; offset += includeRange.Length; } // the offset is in the file, after the last include return new TreeOffset(documentOffset + offset); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { if (endOffset - startOffset > 2 && buffer[startOffset.Offset + 2] == '/' && (endOffset - startOffset == 3 || buffer[startOffset.Offset + 3] != '/')) { return new DocComment(this, buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset))); } return new Comment(this, buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset))); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new ExpressionTailOperatorTokenElement(this); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new FixedTokenElement(this); }
/// <summary> /// Creates a new token having this token type. /// </summary> /// <param name="buffer">The buffer holding the token text.</param> /// <param name="startOffset">The token starting offset in <paramref name="buffer"/>.</param> /// <param name="endOffset">The token ending offset in <paramref name="buffer"/>.</param> /// <returns>A new instance of <see cref="T4Token"/>.</returns> public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new T4Token(this, buffer, startOffset, endOffset); }
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 override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new NTriplesGenericToken(this, buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset))); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return(new GenericTokenElement(this, buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset)))); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { throw new InvalidOperationException(); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return(new CgFixedLengthTokenNode(this)); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new VariableIdentifier(buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset))); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new DefaultAxisKeywordTokenElement(this); }
public override LeafElementBase Create(IBuffer buffer, TreeOffset startOffset, TreeOffset endOffset) { return new Whitespace(buffer.GetText(new TextRange(startOffset.Offset, endOffset.Offset))); }