mirror of
https://github.com/ScintillaOrg/lexilla.git
synced 2025-05-08 19:06:45 +08:00
#277 Fix per-line folding in F# documents
This commit is contained in:
parent
37b834b32f
commit
ff40f9889d
@ -608,6 +608,10 @@
|
||||
<a href="https://github.com/ScintillaOrg/lexilla/issues/276">Issue #276</a>.
|
||||
</li>
|
||||
<li>
|
||||
F#: Fix per-line folding in F# documents.
|
||||
<a href="https://github.com/ScintillaOrg/lexilla/issues/277">Issue #277</a>.
|
||||
</li>
|
||||
<li>
|
||||
Lexer added for troff / nroff "troff".
|
||||
<a href="https://github.com/ScintillaOrg/lexilla/pull/264">Pull request #264</a>.
|
||||
</li>
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Lexer for F# 5.0
|
||||
* Copyright (c) 2021 Robert Di Pardo <dipardo.r@gmail.com>
|
||||
* Parts of LexerFSharp::Lex were adapted from LexCaml.cxx by Robert Roessler ("RR").
|
||||
* Parts of LexerFSharp::Fold were adapted from LexCPP.cxx by Neil Hodgson and Udo Lechner.
|
||||
* Parts of LexerFSharp::Fold were adapted from LexBash.cxx by Neil Hodgson and Kein-Hong Man.
|
||||
* The License.txt file describes the conditions under which this software may be distributed.
|
||||
*/
|
||||
// clang-format off
|
||||
@ -651,25 +651,24 @@ void SCI_METHOD LexerFSharp::Fold(Sci_PositionU start, Sci_Position length, int
|
||||
}
|
||||
|
||||
LexAccessor styler(pAccess);
|
||||
const Sci_Position startPos = static_cast<Sci_Position>(start);
|
||||
Sci_Position startPos = static_cast<Sci_Position>(start);
|
||||
const Sci_PositionU endPos = start + length;
|
||||
Sci_Position lineCurrent = styler.GetLine(startPos);
|
||||
if (lineCurrent > 0) {
|
||||
lineCurrent--;
|
||||
startPos = styler.LineStart(lineCurrent);
|
||||
initStyle = (startPos > 0) ? styler.StyleAt(startPos - 1) : SCE_FSHARP_DEFAULT;
|
||||
}
|
||||
Sci_Position lineNext = lineCurrent + 1;
|
||||
Sci_Position lineStartNext = styler.LineStart(lineNext);
|
||||
int style = initStyle;
|
||||
int styleNext = styler.StyleAt(startPos);
|
||||
char chNext = styler[startPos];
|
||||
int levelNext;
|
||||
int levelCurrent = SC_FOLDLEVELBASE;
|
||||
int levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
|
||||
int levelNext = levelCurrent;
|
||||
int visibleChars = 0;
|
||||
|
||||
if (lineCurrent > 0) {
|
||||
levelCurrent = styler.LevelAt(lineCurrent - 1) >> 0x10;
|
||||
}
|
||||
|
||||
levelNext = levelCurrent;
|
||||
|
||||
for (Sci_PositionU i = start; i < endPos; i++) {
|
||||
for (Sci_PositionU i = static_cast<Sci_PositionU>(startPos); i < endPos; i++) {
|
||||
const Sci_Position currentPos = static_cast<Sci_Position>(i);
|
||||
const bool atEOL = (currentPos == (lineStartNext - 1));
|
||||
const bool atLineOrDocEnd = (atEOL || (i == (endPos - 1)));
|
||||
@ -712,10 +711,6 @@ void SCI_METHOD LexerFSharp::Fold(Sci_PositionU start, Sci_Position length, int
|
||||
FoldLexicalGroup(styler, levelNext, lineCurrent, "open ", SCE_FSHARP_KEYWORD);
|
||||
}
|
||||
|
||||
if (!IsASpace(ch)) {
|
||||
visibleChars++;
|
||||
}
|
||||
|
||||
if (atLineOrDocEnd) {
|
||||
int levelUse = levelCurrent;
|
||||
int lev = levelUse | levelNext << 16;
|
||||
@ -723,7 +718,7 @@ void SCI_METHOD LexerFSharp::Fold(Sci_PositionU start, Sci_Position length, int
|
||||
if (visibleChars == 0 && options.foldCompact) {
|
||||
lev |= SC_FOLDLEVELWHITEFLAG;
|
||||
}
|
||||
if (levelUse < levelNext) {
|
||||
if ((levelUse < levelNext) && (visibleChars > 0)) {
|
||||
lev |= SC_FOLDLEVELHEADERFLAG;
|
||||
}
|
||||
if (lev != styler.LevelAt(lineCurrent)) {
|
||||
@ -735,12 +730,14 @@ void SCI_METHOD LexerFSharp::Fold(Sci_PositionU start, Sci_Position length, int
|
||||
lineNext = lineCurrent + 1;
|
||||
lineStartNext = styler.LineStart(lineNext);
|
||||
levelCurrent = levelNext;
|
||||
}
|
||||
|
||||
if (atEOL && (currentPos == (styler.Length() - 1))) {
|
||||
styler.SetLevel(lineCurrent, (levelCurrent | levelCurrent << 16) | SC_FOLDLEVELWHITEFLAG);
|
||||
}
|
||||
if (!IsASpace(ch)) {
|
||||
visibleChars++;
|
||||
}
|
||||
}
|
||||
const int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
|
||||
styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
|
||||
}
|
||||
|
||||
bool LineContains(LexAccessor &styler, const char *word, const Sci_Position start, const int chAttr) {
|
||||
|
@ -49,4 +49,4 @@
|
||||
0 400 400 printfn $"""%.2f {x}"""
|
||||
0 400 400 printfn $@"""%.2f {x}"""
|
||||
0 400 400 printfn @$"""%.2f {x}"""
|
||||
1 400 400
|
||||
0 400 0
|
@ -12,4 +12,4 @@
|
||||
0 401 400 | open FSharp.Reflection
|
||||
1 400 400
|
||||
0 400 400 () |> ignore
|
||||
1 400 400
|
||||
0 400 0
|
@ -44,4 +44,4 @@
|
||||
0 401 400 | *)
|
||||
2 400 401 + // Prints:
|
||||
0 401 400 | // "not an evaluated expression"
|
||||
1 400 400
|
||||
0 400 0
|
@ -83,4 +83,4 @@
|
||||
0 400 400 let b = +0b0111_111UL-0x100UL
|
||||
0 400 400 let c = -01.0F + +001.f
|
||||
0 400 400 let d = -0x100UL - +0b0111_111UL
|
||||
1 400 400
|
||||
0 400 0
|
@ -41,4 +41,3 @@ uint uint8 uint16 uint32 uint64 unit void voidptr voption
|
||||
fold.fsharp.preprocessor=1
|
||||
fold.comment=1
|
||||
|
||||
testlexers.per.line.disable=1
|
||||
|
@ -51,4 +51,4 @@
|
||||
0 400 400 unescapeWinPath "\\\"Program Files (x86)\\Windows NT\\Accessories\\\""
|
||||
0 400 400 |> System.IO.Directory.GetFiles
|
||||
0 400 400 |> printfn "%A"
|
||||
1 400 400
|
||||
0 400 0
|
Loading…
x
Reference in New Issue
Block a user