ScintillaOrg / lexilla

A library of language lexers for use with Scintilla
https://www.scintilla.org/Lexilla.html
Other
179 stars 64 forks source link

Fold Issue in Verilog mode #204

Closed ramamk closed 11 months ago

ramamk commented 1 year ago

Hi Team, I am using Notepad++ editor to develop the verilog code (VLSI HW RTL Language) . I have faced an issue and reported in community and they pointed to raise the issue in this website.

I will briefly explain the issue here, in the below image 1-11 and 13-23 are same piece of code just comment is removed. In verilog Begin-end blocks work same as {..........} curly braces in C language. However when i inserted comments with curly braces in verilog in the below context it is creating a fold map issue. Kindly correct it or let me know anything can be done at my end.

https://community.notepad-plus-plus.org/topic/24896/fold-issue-in-verilog-mode/2

image

nyamatongwe commented 1 year ago

Try changing the fold.comment property.

ramamk commented 1 year ago

I am new to this thing,Kindly tell me how to do that ,in which file I need to modify in notepad++ install directory

nyamatongwe commented 1 year ago

I do not know how to configure Notepad++ in this way. Lexilla provides capabilities in a way that can be used by programmers and its up to the Notepad++ developers how they expose that functionality to users.

mpheath commented 1 year ago
OP image as text ```verilog always@(posedge clk) begin if(rst)begin sig1<=1'b1; //{1{1'b1}}; end else begin sig1 <= 1'b0; end end end always@(posedge clk) begin if(rst)begin sig1<=1'b1; end else begin sig1 <= 1'b0; end end end ```

In Notepad++ PythonScript plugins startup.py , add this at the bottom of the script:

def onBufferActivated(args):
    if notepad.getCurrentLang() == LANGTYPE.VERILOG:
        editor.setProperty('fold.comment', 0)

notepad.callback(onBufferActivated, [NOTIFICATION.BUFFERACTIVATED])

Set PythonScript Configuration Intitialisation combo to ATSTARTUP so the code is active at Notepad++ startup.

This is what I see in Notepad++ with the fold.comment option set to 0 .

verilog

Line 3 does not have a fold.

ramamk commented 1 year ago

Just a follow up question , will it remove the ability to fold the multi line comments also ?

mpheath commented 1 year ago

@ramamk fold.comment affects all comment folding in the Verilog lexer.

This code folds at //{ and supposedly ends the fold at //} . https://github.com/ScintillaOrg/lexilla/blob/12348921861f02130d77beea9b1666531d29081d/lexers/LexVerilog.cxx#L864-L873

I am not sure why { and } is special for comments. It does not seem to be documented.

Add a space after // so it is // { and the fold disappears. Might be better to insert a space than disabling comment folding.

FYI, There is a bang comment //! to give a different style. Seems to be creative like the cpp lexer with different comment styles.

rdipardo commented 1 year ago

I am not sure why { and } is special for comments. It does not seem to be documented.

I think the intention was to implement something like fold.cpp.comment.explicit, along with other explicit borrowings from LexCPP, as acknowledged in the header comment:

https://github.com/ScintillaOrg/lexilla/blob/12348921861f02130d77beea9b1666531d29081d/lexers/LexCPP.cxx#L406-L414

ramamk commented 1 year ago

pls let me know if can close the issue, placing a space between //{ leads to // { and it resolved the fold issue thanks for pointing the work around @rdipardo . :)

mpheath commented 1 year ago

@ramamk You seem to have stumbled upon some comment features. You have the option to close the issue yourself if you are satisfied.

rdipardo commented 1 year ago

You seem to have stumbled upon some comment features.

"[F]eatures" may be an overstatement given the currently haphazard implementation. I think what's needed here is an enhancement rather than a bug fix. If that's not reason enough to reopen, it might be appropriate to pin the wontfix tag to better explain Lexilla's disposition.

mpheath commented 1 year ago

@rdipardo

You seem to have stumbled upon some comment features.

This statement is accurate as that is what happened. If you disagree with the comment implementation, then aim your sights on the implementation as I accept your response as an insult to my statement.

I consider documentation of these features might be suitable so users are aware of them at the very least.

ramamk commented 1 year ago

You seem to have stumbled upon some comment features. @mpheath

working with legacy code having tens of thousands of lines and folds aren't closing at correct place tracing the issue it self has taken 36hrs+. when we found the issue is with editor we felt Aaaahhh. That's the reason for opening the ticket here.

rdipardo commented 1 year ago

@mpheath

This statement is accurate as that is what happened. If you disagree with the comment implementation, then aim your sights on the implementation as I accept your response as an insult to my statement.

I consider documentation of these features might be suitable so users are aware of them at the very least.

There are obscure features that make sense when explained, like the optional keyword classes that activate folding in assembler files. When it's explained that a property may cause comments to be folded twice — once because they are comments, once more because the comment text begins with an open brace, which can't be configured — is that behaviour any less bizarre than it obviously appeared to everyone here? Of course this thread will be looked up by the next user to be surprised, hopefully preventing a duplicate. Is their surprise the intended effect of this feature, or is it just possible the source code has a rough edge somewhere?

Insisting the job is done after a bit of "customer service" is what's insulting, to the user who bothered to make the report, and to those who've given their free time looking at it. The Scintilla family of projects are models of stability and competent stewardship. SciTE is practically the perfect GUI editor (as distinct from Vim, the perfect editor, period). Subtle improvements are the only growth opportunities left, and rationalizing this lexer's fold options would be a more than subtle improvement.

ramamk commented 1 year ago

Hi Team, Found one more issue regarding same fold issue :( .

line number 7 fold should end at 12 but it is ending at 16. ifdef at 14 fold is closing with normal end keyword at 15 which should close with endif at 16 only. begin fold line number 11 is closing with endif line 12 which should close only with end at line 15.

image
zufuliu commented 1 year ago

I am not sure why { and } is special for comments. It does not seem to be documented.

I think the intention was to implement something like fold.cpp.comment.explicit, along with other explicit borrowings from LexCPP, as acknowledged in the header comment:

https://github.com/ScintillaOrg/lexilla/blob/12348921861f02130d77beea9b1666531d29081d/lexers/LexCPP.cxx#L406-L414

I think it worth to add a similar property (fold.verilog.comment.explicit?) to control the behavior, see other issues on Notepad++ regarding fold.cpp.comment.explicit (disabled since 2021): https://github.com/notepad-plus-plus/notepad-plus-plus/issues?q=is%3Aissue+fold.cpp.comment.explicit+is%3Aclosed

ramamk commented 1 year ago

Hi Team, Kindly let me know if there is any workaround for the below issue mentioned.

Hi Team, Found one more issue regarding same fold issue :( .

line number 7 fold should end at 12 but it is ending at 16. ifdef at 14 fold is closing with normal end keyword at 15 which should close with endif at 16 only. begin fold line number 11 is closing with endif line 12 which should close only with end at line 15.

image
nyamatongwe commented 11 months ago

The initial issue appears resolved so closing. Each problem should be reported as an individual isolated issue or this tracker will end up as a mess of semi-completed reports and diversions. Issues should not be reopened unless the initially reported issue reoccurs.