Closed FALLAI-Denis closed 3 years ago
There is no possible config to fold single line comments, yet.
Can you the update explicit-folding-0.13.0.vsix with the following config:
"folding":
{"cobol": [
{// Bloc commentaires
"beginRegex":"(?<=^.{6})\\*"
,"endRegex":"(?<=^.{6})[^*]"
,"nested": false
,"foldLastLine": false
// ,"kind": "comment"
}
]
}
Hi,
This was my first approach to the problem. But it didn't work because the ending regular expression conflicted with the other folding rules. It also generates a lot of "matches" (almost all lines of the source code).
It would seem that the same expression cannot participate in more than one folding rule, and / or be both a begin expression and an end expression in two different folding rules. The order in which the rules are declared also seems to matter: first come, first served.
I also discovered that it was often useless to code lookbehind and lookafter because after all only the line number is important and is used to define the ranges of the foldings areas. A priori this can even harm the performance of the execution of regular expressions without adding more value to the result.
The lookbehind and lookafter are in fact only useful to discriminate some particular use cases.
What is the purpose of the "DOCSTRING" type search if it does not apply to the current use case?
I will refine my tests and get back to you soon.
Docstrings are comment blocks in python (enclosed in """
). Since the begin/end are identical, it has to be managed differently than the regular begin/end. So I've just called that mode DOCSTRING
...
New test (limited to comment lines block), with last version 0.13.0
"folding":
{"cobol": [
{// Bloc commentaires
"beginRegex": "^.{6}\\*"
,"endRegex": "^.{6}[^*]"
//,"kind": "comment"
}
]
}
lang: cobol, regex: /(?<_0_0>^.{6}\*)|(?<_2_0>^.{6}[^*])/g
line: 1, offset: 0, type: END, match: , regex: 0
line: 2, offset: 0, type: END, match: , regex: 0
line: 3, offset: 0, type: BEGIN, match: *, regex: 0
line: 4, offset: 0, type: BEGIN, match: *, regex: 0
line: 5, offset: 0, type: BEGIN, match: *, regex: 0
line: 6, offset: 0, type: BEGIN, match: *, regex: 0
line: 7, offset: 0, type: BEGIN, match: *, regex: 0
line: 8, offset: 0, type: BEGIN, match: *, regex: 0
line: 9, offset: 0, type: BEGIN, match: *, regex: 0
line: 10, offset: 0, type: BEGIN, match: *, regex: 0
line: 11, offset: 0, type: BEGIN, match: *, regex: 0
line: 12, offset: 0, type: BEGIN, match: *, regex: 0
line: 13, offset: 0, type: BEGIN, match: *, regex: 0
line: 14, offset: 0, type: BEGIN, match: *, regex: 0
line: 15, offset: 0, type: END, match: , regex: 0
line: 16, offset: 0, type: END, match: , regex: 0
line: 17, offset: 0, type: END, match: , regex: 0
foldings: [{"start":13,"end":14,"kind":3},{"start":12,"end":15,"kind":3},{"start":11,"end":16,"kind":3}]
PS : works with "nested":false (don't understand why... but global regex not the same, look like "docstring". does endregex matter ?).
"folding":
{"cobol": [
{// Bloc commentaires
"beginRegex": "^.{6}\\*"
,"endRegex": "^.{6}[^*]"
,"nested": false
//,"kind": "comment"
}
]
}
lang: cobol, regex: /(?<_0_0>^.{6}\*)/g
line: 3, offset: 0, type: BEGIN, match: *, regex: 0
[nested] line: 15, offset: 0, type: END, match:
foldings: [{"start":2,"end":14,"kind":3}]
"nested": false
indicates there is no nested foldings inside the current folding. So when the beginRegex
is matched, it goes to another loop to just match the endRegex
.
You should use "foldLastLine": false
to not include the first line which isn't a comment (PROCEDURE DIVISION
).
Works fine.
"folding":
{"cobol": [
{// Bloc commentaires
"beginRegex": "^.{6}\\*"
,"endRegex": "^.{6}[^*]"
,"nested": false
,"foldLastLine": false
,"kind": "comment"
}
]
}
"Shift+Alt+A" ("Maj+Alt+A" with French Language Pack) has no effect on block comment lines... even with "kind": "comment".
I've published the updated extension. I've also improved the debug messages.
@FALLAI-Denis Thank you so much for your kind donation. You made my day! :smile:
This issue is resolved.
Describe the issue
I wanted to set up a recognition of blocks of "comment" lines. In COBOL, a comment is introduced indicating the "*" character in column 7 of the source line.
I declare an identical begin expression and end expression, which is recognized as a "docstring" by the extension.
For a group of contiguous lines, instead of having a single fold block for all of the lines, I have a fold every 2 lines.
To reproduce
Code Example
Settings
Expected behavior
A single folding for all the contiguous lines.
Screenshots
Additional context
The problem also seems to affect the operation of "separators": depending on the number of odd or even lines of "docstring", a "separator" type folding disappears before or after the "docstrings" block.
What is the difference between "docstring" and type "comment"? Is a "docstring" automatically a "comment" or must it be specified explicitly?