Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Folding #89

Open
seadoggie01 opened this issue Apr 28, 2022 · 12 comments
Open

Code Folding #89

seadoggie01 opened this issue Apr 28, 2022 · 12 comments

Comments

@seadoggie01
Copy link

Folding is inconsistent from SciTE

  • If, While, Switch, and For statements don't fold their respective closing keywords. Func to EndFunc are folded properly

  • Case and With sections aren't folded

  • The underscore causes extra newlines to be folded:

Global Enum	$__test, _
		$__test2, _
		$__test3



; Everything before this line gets folded
  • Comments spanning multiple lines aren't folded
@Danp2
Copy link

Danp2 commented Apr 29, 2022

If, While, Switch, and For statements don't fold their respective closing keywords. Func to EndFunc are folded properly

This is a simple fix that I will address in a PR.

Case and With sections aren't folded

I didn't check With, but Case seemed correct to me. Can you give an example where it isn't working as you expect?

@seadoggie01
Copy link
Author

seadoggie01 commented Apr 29, 2022

I didn't check With, but Case seemed correct to me. Can you give an example where it isn't working as you expect?

Apologies, I added a Case and With statement, but didn't populate the middle with code. Case functions properly but With doesn't collapse the EndWith

@Danp2
Copy link

Danp2 commented Apr 29, 2022

The underscore causes extra newlines to be folded:

Unsure how to correct this. Maybe @loganch will have some ideas.

Comments spanning multiple lines aren't folded

I think these are viewed as multiple single line comments, so no folding is available.

P.S. I've noticed a few other issues with folding --

  • #cs and #ce doesn't fold the same as Scite (#ce is visible)
  • No folding for #comments-start / #comments-end

@Danp2
Copy link

Danp2 commented Apr 29, 2022

The underscore causes extra newlines to be folded:

Look like this is corrected by adding "offSide": true to the folding definition in the language configuration file. Unsure if this will have any negative side effects.

@Danp2
Copy link

Danp2 commented Apr 30, 2022

No folding for #comments-start / #comments-end

I take that back. It does seem to fold if the contents are indented, but the folding appears off. It's like #comments-end is viewed as the start of a new folding region if the lines after it are indented. Same thing occurs with #cs..#ce.

For example --

Test()

Func Test()
	Local $sStr1


#cs
	Local $sStr2
	Local $sStr3
#ce

	Local $sStr4

EndFunc

@seadoggie01
Copy link
Author

I'm not sure how related syntax highlighting is to code-folding, so this may need to be a separate issue.
I've also noticed that using #cs with #comments-end doesn't stop the comment formatting to end.

@Danp2
Copy link

Danp2 commented Apr 30, 2022

@seadoggie01 That code was meant to be copy / pasted into VSCode so that you could observe the issue I was describing with #ce and folding.

@seadoggie01
Copy link
Author

Sorry, Danp2, I didn't word that quite right. Your code displays the same in VSCode for me too.

I was bringing up that if you paste this instead...

Test()

Func Test()
	Local $sStr1


#cs
	Local $sStr2
	Local $sStr3
#comments-end

	Local $sStr4

EndFunc

then you'll see that Local $sStr4 appears to be commented, even though it isn't :)

loganch added a commit that referenced this issue May 3, 2022
This corrects the issue with #comment-start/#comment-end/#cs/#ce failing to end syntax highlighting when mixed together, and adds proper code folding functionality when comments are added.

I was able to get the syntax highlighting for the blocks to work together by combining their Regex in the .tmLanguage file. To fix the folding I simply added them to folding.markers in the language configuration file.

Addresses issue #89.
@Danp2
Copy link

Danp2 commented Jun 11, 2022

I've found a problem with folding of If...Then structures, which don't require an EndIf. For example --

Func Test()
    Local $vResult = Default
	If $iErr Then $vResult = ""

	$vResult = True
EndFunc

The lines following the If statement are improperly hidden when you fold the If statement.

image

@loganch Suggestions on how to fix?

@loganch
Copy link
Owner

loganch commented Jun 12, 2022

I tried adding Then to the end markers for folding, but it still seems to not take effect unless it is on a separate line. Maybe using registerFoldingRangeProvider() might enable that, by setting the start and end for the same line in this case, but the documentation notes:

If multiple folding ranges start at the same position, only the range of the first registered provider is used. If a folding range overlaps with an other range that has a smaller position, it is also ignored.

To me, the first sentence makes it sound like the custom folding range could be overwritten by the "built in" folding markers, but the second sentence reads like the smaller range will work.

@Danp2
Copy link

Danp2 commented Jun 12, 2022

Not sure. I think that if and endif would need to be removed from the folding markers in autoit-language-configuration.json and reimplemented using registerFoldingRangeProvider() where you could distinguish between a single line If...Then and a multiline If....Then...Endif

Note that I recall seeing an If...Then that used an underscore to continue the statement on the next line, ie --

	If $iErr Then _
		$vResult = ""

so that could complicate identifying If...Then vs If...Then...Endif

@Akanada
Copy link

Akanada commented Jul 7, 2022

I think I have found another issue with code Folding. It seems to me every time the Word "Next" is used it leads also to a wrong folding even when used in a comment. I do Installer GUI Automation with AutoIt and "Next" is used very often to identify Controls.
For example, all these Lines lead to wrong folding inside of in my Code Functions and Regions.

ControlClick("Station-SW","The setup wizard will install Station-SW",'[NAME:buttonNext]',"primary")
ControlClick("Station-SW","Select the packages and features setup will install","Next","primary")
;~ ControlClick("Station-SW","The setup wizard will install Station-SW",'[NAME:buttonNext]',"primary")

loganch added a commit that referenced this issue Jul 16, 2022
Addresses @Akanada's problem in issue #89, which had Next within quotes acting as a folding marker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants