| Summary: | Code folding not working properly for Python | ||
|---|---|---|---|
| Product: | [Applications] kate | Reporter: | Rohit sardana <junkie.rohit> |
| Component: | folding | Assignee: | KWrite Developers <kwrite-bugs-null> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | christoph, pify |
| Priority: | NOR | ||
| Version First Reported In: | 20.12.1 | ||
| Target Milestone: | --- | ||
| Platform: | Manjaro | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | Screenshot of part of the code Mentioned above | ||
The problem seems generic: as soon as there is an empty line between the line of code that defines a block (`def`, `if`...) and the code inside this block, the code fold is not proposed.
This code proposes 4 folds:
def test():
code = ""
if True:
code = ""
while False:
code = ""
test:
something
This code does not offer any fold:
def test():
code = ""
if True:
code = ""
while False:
code = ""
test:
something
This is fixed now. https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/451 |
Created attachment 135464 [details] Screenshot of part of the code Mentioned above SUMMARY Code folding for 'def' keyword in python, not working properly. Some instances of 'def' are left out of folding. STEPS TO REPRODUCE 1. This part shows code folding, def readable_bytes(n_bytes): symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') prefix = {} for i, s in enumerate(symbols): prefix[s] = 1 << (i + 1) * 10 for s in reversed(symbols): if n_bytes >= prefix[s]: value = int(float(n_bytes) / prefix[s]) return '%s%s' % (value, s) return "%sB" % n_bytes 2. This part doesn't show code folding, def get_processes_info(interval): global average_number global procs_cpu_average # Sleeps for "interval" time.sleep(interval) procs = [] for p in psutil.process_iter(): try: p.dict = p.as_dict([ 'pid', # Unique ID 'username', # Owner 'nice', # Priority 'memory_percent', # Memory usage 'cpu_percent', # CPU usage 'name', # Description 'status', # For splitting processes according to their status ]) ..... .... def print_header(procs): global this_user global cpu_cores global header_message global average_number global procs_cpu_average global change_priority_status # Function that returns the no. of pipeline characters and space characters (max. of 40) def count_pipelines(perc): dashes = "|" * int((float(perc) / 10 * 4.1)) empty_dashes = " " * (41 - len(dashes)) return dashes + empty_dashes ... .... ... 3. Above code is from "bpytop" source code on 'Github. OBSERVED RESULT Code folding should recognise 'def' keyword in python. EXPECTED RESULT Other editors correctly show Code folding. SOFTWARE/OS VERSIONS Linux/KDE Plasma: KDE Plasma (available in About System) KDE Plasma Version: 5.20.5 KDE Frameworks Version: 5.78.0 Qt Version: 5.15.2 ADDITIONAL INFORMATION