Bug 335855 - code folding for python files misses some structures when body starts with empty lines
Summary: code folding for python files misses some structures when body starts with em...
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: folding (show other bugs)
Version: 20.08.2
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-05 21:44 UTC by Robert
Modified: 2022-12-11 17:59 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.102.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert 2014-06-05 21:44:42 UTC
Some python code structures are not recognised when there is a comment or a blank line for the first line of the body. This happens for if statements, else statements, while loops and functions definitions.

Reproducible: Always

Steps to Reproduce:
if a == 3:
    
    print 'a==3'

if a == 3:
    #
    print 'a==3'
    
def test():
    
    t = 5
    return t

def test():
    #test
    t = 5
    return t
Actual Results:  
No code folding marker appears.

Expected Results:  
a code folding marker should appear for these cases since this is acceptable python.
Comment 1 Buovjaga 2016-06-19 12:24:57 UTC
I get the folding marks for the blocks with a comment, but not for the ones with a blank line.

Arch Linux 64-bit
Kate 16.04.2
KDE Frameworks 5.22.0
Qt 5.6.1
xcb wm
Comment 2 Christoph Cullmann 2017-07-24 22:42:09 UTC
Valid bug, unfortunately ATM we only have one line look-ahead to 'know' if some line should start a new folding section.

This means in these cases, that heuristic will fail, as the indentation level is not increased (because empty lines are skipped for that).
Comment 3 Justin Zobel 2020-10-27 03:00:52 UTC
Still an issue as of 20.11.70
Comment 4 Christoph Cullmann 2022-10-31 18:50:50 UTC
Still happens, but nothing will change if nobody provides at patch.

I would consider this no real issue, as such code is strange, there is no reason to have empty lines after the start of such statements.

Naturally, if somebody provides a patch, this can be improved, all these things are just imperfect heuristics.

See on https://kate-editor.org/join-us/ how to contribute.
Comment 5 Christoph Cullmann 2022-12-10 20:06:31 UTC
https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/451

If somebody has time, please test this.
Comment 6 Christoph Cullmann 2022-12-11 15:53:09 UTC
Must confess the initial example is still broken in my branch...
Comment 7 Christoph Cullmann 2022-12-11 16:09:18 UTC
(In reply to Christoph Cullmann from comment #6)
> Must confess the initial example is still broken in my branch...

Should work now.