]> O.S.I.I.S - jp/crowedit.git/commitdiff
debug folds scrolling, node lengths
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 27 Feb 2025 18:40:18 +0000 (19:40 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 27 Feb 2025 18:40:18 +0000 (19:40 +0100)
CrowEditBase/src/Compiler/SyntaxAnalyser.cs
CrowEditBase/src/Compiler/SyntaxNode.cs
CrowEditBase/src/Compiler/SyntaxRootNode.cs
CrowEditBase/src/SourceEditor.cs
plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs
plugins/CEXmlPlugin/src/Parsing/XmlSyntaxAnalyser.cs

index 99bfe7cca3380e7929d3c36b865181cf55f4138f..98a4117a28369c7056c991ac362db7561faa297c 100644 (file)
@@ -82,22 +82,19 @@ namespace CrowEditBase
                /// <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) {
index 07d53638856d53f59d06e7ed31579a8fc4f00cbf..31b6f3b36ac7b71f1ded78c2fdc90418132392c6 100644 (file)
@@ -15,10 +15,14 @@ namespace CrowEditBase
                        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;
@@ -36,7 +40,7 @@ namespace CrowEditBase
                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 () {
@@ -110,10 +114,8 @@ namespace CrowEditBase
                }
 
                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 {
@@ -123,18 +125,9 @@ namespace CrowEditBase
                }
                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) {
@@ -147,7 +140,7 @@ namespace CrowEditBase
                        child.Parent = null;
                }
                public IEnumerable<T> GetChilds<T> () => children.OfType<T>();
-               
+               /*
                public void Replace (SyntaxNode newNode) {
                        Parent.replaceChild (this, newNode);
                }
@@ -155,7 +148,7 @@ namespace CrowEditBase
                        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;
@@ -171,7 +164,7 @@ namespace CrowEditBase
                                idx = curNode.Parent.children.IndexOf (curNode);
                                curNode = curNode.Parent;
                        }
-               }
+               }*/
                void offset (int tokenOffset, int lineOffset) {
                        TokenIndexBase += tokenOffset;
                        StartLine += lineOffset;
index 17d41f0fe8cecc9109ae475946aaa1c471129b9f..af0f9ab95a59addea12210e4048532eb367220c1 100644 (file)
@@ -14,7 +14,7 @@ namespace CrowEditBase
                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;
index ce947960698bb82d5f9fad8dbc16557395a444cf..9f9bf24df6a5d4f3d10f0eacaad337a3225a86e3 100644 (file)
@@ -618,25 +618,22 @@ namespace Crow
 
                                
                                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);
@@ -729,9 +726,18 @@ namespace Crow
                                        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++;
 
                                }
index a6045e55beb53e3b10f5493ea8b3731e31875f4b..ee7f780f1460959d7e7dfa6379e83593d7f9620f 100644 (file)
@@ -50,7 +50,7 @@ namespace CECrowPlugin.Style
                                tokIdx++;
                        }
                        while (currentNode.Parent != null) {
-                               if (!currentNode.TokenCount.HasValue)
+                               if (!currentNode.LastTokenIndex.HasValue)
                                        finishCurrentNode (-1);
                                else
                                        currentNode = currentNode.Parent;
index a455fed9dec6a3a67b2809157d68005371181d1c..770c99377f44d76acbcf6e2f2697ea20927efa2f 100644 (file)
@@ -86,10 +86,10 @@ namespace CrowEdit.Xml
                                                                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)) {
@@ -98,7 +98,7 @@ namespace CrowEdit.Xml
                                                                                finishCurrentNode ();
                                                                                break;
                                                                        } else {
-                                                                               finishCurrentNode (-eltEndTag.TokenCount.Value);
+                                                                               finishCurrentNode (-eltEndTag.TokenCount);
                                                                        }
                                                                }
                                                        }
@@ -140,11 +140,12 @@ namespace CrowEdit.Xml
                                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;
                }