/// <param name="endToken">The final token of this node</param>
/// <param name="endLine">the endline number of this node</param>
protected void finishCurrentNode (int endTokenOffsetFromCurrentTokIdx = 0) {
- int count = tokIdx - currentNode.TokenIndexBase + endTokenOffsetFromCurrentTokIdx;
- currentNode.TokenCount = count < 0 ? null : count;
+ int lastTokOffset = tokIdx - currentNode.TokenIndexBase + endTokenOffsetFromCurrentTokIdx;
+ currentNode.lastTokenOfset = lastTokOffset < 0 ? null : lastTokOffset;
if (endTokenOffsetFromCurrentTokIdx < 0) {
Token lastTok = currentNode.LastTokenIndex.HasValue ?
Root.GetTokenByIndex(currentNode.LastTokenIndex.Value) :
Root.GetTokenByIndex(currentNode.TokenIndexBase);
+
currentNode.EndLine = lines.GetLocation(lastTok.End).Line;
+ }else{
+ currentNode.EndLine = currentLine;
}
- //currentNode.EndLine
- currentNode.EndLine = currentLine;
currentNode = currentNode.Parent;
}
- /*protected void setEndOfNode (int endTokenOffsetFromCurrentTokIdx = 0, int endLineOffsetFromCurrentLine = 0) {
- currentNode.TokenCount = tokIdx - currentNode.TokenIndexBase + endTokenOffsetFromCurrentTokIdx;
- currentNode.EndLine = currentLine + endLineOffsetFromCurrentLine;
- }*/
protected void setCurrentNodeEndLine (int endLine)
=> currentNode.EndLine = endLine;
protected bool skipTrivia(bool skipLineBreaks = true) {
StartLine = startLine;
TokenIndexBase = tokenBase;
if (lastTokenIdx.HasValue)
- TokenCount = lastTokenIdx - tokenBase;
+ lastTokenOfset = lastTokenIdx - tokenBase;
}
bool _isExpanded;
+ internal int? lastTokenOfset;
+ internal bool isFolded;
+ internal int lineCount;
+
public bool isExpanded {
get => _isExpanded;
public SyntaxNode Parent { get; private set; }
public int StartLine { get; private set; }
public virtual int LineCount => lineCount;
- public virtual bool IsComplete => TokenCount.HasValue;
+ public virtual bool IsComplete => lastTokenOfset.HasValue;
public virtual bool IsFoldable => IsComplete && !(Parent != Root && Parent.StartLine == StartLine) && lineCount > 1;
public virtual SyntaxRootNode Root => Parent.Root;
public virtual void UnfoldToTheTop () {
}
public virtual int TokenIndexBase { get; private set; }
- public virtual int? TokenCount { get; internal set; }
- public int? LastTokenIndex => TokenIndexBase + TokenCount;
- internal bool isFolded;
- internal int lineCount;
+ public virtual int TokenCount => lastTokenOfset.HasValue ? lastTokenOfset.Value + 1 : 0;
+ public int? LastTokenIndex => lastTokenOfset.HasValue ? TokenIndexBase + lastTokenOfset.Value : null;
public int EndLine {
internal set {
}
public TextSpan Span {
get {
- /*if (HasChilds) {
- return new TextSpan (children.First().Span.Start, children.Last().Span.End)
- }*/
- try {
- Token startTok = getTokenByIndex(TokenIndexBase);
- Token endTok = TokenCount.HasValue ? getTokenByIndex (TokenIndexBase+TokenCount.Value) : startTok;
- return new TextSpan (startTok.Start, endTok.End);
- }catch{
- System.Diagnostics.Debugger.Break ();
- }
- return default;
-
+ Token startTok = getTokenByIndex(TokenIndexBase);
+ Token endTok = LastTokenIndex.HasValue ? getTokenByIndex (LastTokenIndex.Value) : startTok;
+ return new TextSpan (startTok.Start, endTok.End);
}
}
public SyntaxNode AddChild (SyntaxNode child) {
child.Parent = null;
}
public IEnumerable<T> GetChilds<T> () => children.OfType<T>();
-
+ /*
public void Replace (SyntaxNode newNode) {
Parent.replaceChild (this, newNode);
}
int idx = children.IndexOf (oldNode);
children[idx] = newNode;
newNode.Parent = this;
- int tokIdxDiff = newNode.TokenCount.Value - oldNode.TokenCount.Value;
+ int tokIdxDiff = newNode.TokenCount - oldNode.TokenCount;
int lineDiff = newNode.EndLine - oldNode.EndLine;
if (tokIdxDiff == 0 && lineDiff == 0)
return;
idx = curNode.Parent.children.IndexOf (curNode);
curNode = curNode.Parent;
}
- }
+ }*/
void offset (int tokenOffset, int lineOffset) {
TokenIndexBase += tokenOffset;
StartLine += lineOffset;
protected readonly ReadOnlyMemory<char> source;
protected Token[] tokens;
public override int TokenIndexBase => 0;
- public override int? TokenCount { get => tokens == null ? default : Math.Max (0, tokens.Length - 1); internal set {} }
+ public override int TokenCount => tokens == null ? 0 : Math.Max (0, tokens.Length - 1);
public override SyntaxRootNode Root => this;
public override bool IsFoldable => false;
public override SyntaxNode NextSiblingOrParentsNextSibling => null;
int printedLines = 0;
- int curLine = (int)Math.Floor(ScrollY / lineHeight);
- pixY = -(ScrollY % lineHeight);
-
+ int linesToSkip = (int)Math.Floor(ScrollY / lineHeight);
IEnumerator<SyntaxNode> foldsEnum = doc.Root.VisibleFoldableNodes.GetEnumerator ();
bool notEndOfFolds = foldsEnum.MoveNext();
- while (curLine < doc.LinesCount && printedLines < Math.Min(visibleLines, doc.LinesCount)) {
-
+ while (notEndOfFolds && foldsEnum.Current.StartLine < linesToSkip) {
+ if (foldsEnum.Current.isFolded)
+ linesToSkip += foldsEnum.Current.LineCount-1;
+ notEndOfFolds = foldsEnum.MoveNext();
+ }
- while (notEndOfFolds && foldsEnum.Current.StartLine < curLine) {
- if (foldsEnum.Current.isFolded && curLine <= foldsEnum.Current.EndLine)
- curLine += foldsEnum.Current.LineCount - 1;
- notEndOfFolds = foldsEnum.MoveNext();
- }
+ int curLine = linesToSkip;
+ pixY = -(ScrollY % lineHeight);
- if (curLine >= doc.LinesCount)//could it occurs?
- break;
-
+ while (curLine < doc.LinesCount && printedLines < Math.Min(visibleLines, doc.LinesCount)) {
+
int encodedChar = 0;
TextLine curTxtLine = doc.GetLine (curLine);
int tokPtr = doc.FindTokenIndexIncludingPosition(curTxtLine.Start);
pixY += lineHeight;
printedLines++;
- if (curFoldStart && foldsEnum.Current.isFolded)
- curLine = foldsEnum.Current.EndLine + 1;
- else
+ if (curFoldStart && curLine == foldsEnum.Current.StartLine){
+ if (foldsEnum.Current.isFolded)
+ curLine += foldsEnum.Current.LineCount;
+ else
+ curLine++;
+ notEndOfFolds = foldsEnum.MoveNext();
+ while (notEndOfFolds && foldsEnum.Current.StartLine < curLine) {
+ /*if (foldsEnum.Current.isFolded && curLine <= foldsEnum.Current.EndLine)
+ curLine += foldsEnum.Current.LineCount;*/
+ notEndOfFolds = foldsEnum.MoveNext();
+ }
+ } else
curLine++;
}
tokIdx++;
}
while (currentNode.Parent != null) {
- if (!currentNode.TokenCount.HasValue)
+ if (!currentNode.LastTokenIndex.HasValue)
finishCurrentNode (-1);
else
currentNode = currentNode.Parent;
finishCurrentNode (); finishCurrentNode ();
} else {
addException ("Open/Close element name mismatch");
- finishCurrentNode (1);//finish eltEndTag->curNode is parent elt
+ finishCurrentNode ();//finish eltEndTag->curNode is parent elt
currentNode.RemoveChild(eltEndTag);
- finishCurrentNode (-eltEndTag.TokenCount.Value); //dont credit parent element with those tokens from the non matching end tag
- //curNode should be parent element of previous element
+ finishCurrentNode (-eltEndTag.TokenCount); //dont credit parent element with those tokens from the non matching end tag
+ //curNode should be parent element of previous element
while(currentNode is ElementSyntax esp) {
//eltEndTag is out of tree, so Name get threw exception
if (string.Equals(esp.StartTag.Name, eltEndTagName, StringComparison.Ordinal)) {
finishCurrentNode ();
break;
} else {
- finishCurrentNode (-eltEndTag.TokenCount.Value);
+ finishCurrentNode (-eltEndTag.TokenCount);
}
}
}
tokIdx++;
}
while (currentNode.Parent != null) {
- if (!currentNode.TokenCount.HasValue)
+ if (!currentNode.LastTokenIndex.HasValue)
finishCurrentNode (-1);
else
currentNode = currentNode.Parent;
}
+ //check why this is required..
setCurrentNodeEndLine (currentLine);
return Root;
}