Bug 419423 - improve highlighting for custom operator implementations
Summary: improve highlighting for custom operator implementations
Status: REOPENED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: 5.5.0
Platform: Fedora RPMs Linux
: NOR major
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-30 15:44 UTC by kogiokkafrms
Modified: 2020-04-02 16:47 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Incorrect syntax-highlighting of operator[] (dark theme) (74.36 KB, image/png)
2020-03-30 15:44 UTC, kogiokkafrms
Details
Incorrect syntax-highlighting of operator[] (light theme) (79.67 KB, image/png)
2020-03-30 15:45 UTC, kogiokkafrms
Details
operator bool() of a while loop (46.73 KB, image/png)
2020-03-31 14:40 UTC, kogiokkafrms
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kogiokkafrms 2020-03-30 15:44:03 UTC
Created attachment 127110 [details]
Incorrect syntax-highlighting of operator[] (dark theme)

SUMMARY
The square brackets of operator[] of C++ containers have different syntax-highlighting colors.

STEPS TO REPRODUCE
Example snippet:
<main.cc>
----------
#include <array>
#include <map>
#include <vector>

int
main()
{
  std::array<std::array<float, 3>, 3> mat{
    { { 1.f, 0.f, 0.f }, { 0.f, 1.f, 0.f }, { 0.f, 0.f, 1.f } }
  };
  std::vector<float> vec{ 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f };

  std::map<int, int> m{
    { 1, 1 },
    { 2, 4 },
    { 3, 9 },
  };

  printf("%.3f, %.3f, %.3f\n", mat[0][0], mat[1][1], mat[2][2]);
  printf("%.3f, %.3f, %.3f\n", vec[0 * 3 + 0], vec[1 * 3 + 1], vec[2 * 3 + 2]);
  printf("%d, %d, %d\n", m[1], m[2], m[3]);
  return 0;
}

OBSERVED RESULT
See the screenshots in the attachment. (Looks more obvious in dark themes.)

EXPECTED RESULT
The square brackets of operator[] should have the same color.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma
KDE Plasma Version: 5.17.5
KDE Frameworks Version: 5.67.0
Qt Version: 5.13.2

ADDITIONAL INFORMATION
Comment 1 kogiokkafrms 2020-03-30 15:45:00 UTC
Created attachment 127111 [details]
Incorrect syntax-highlighting of operator[] (light theme)
Comment 2 Francis Herne 2020-03-30 21:49:40 UTC
Thank you for the report.

This is expected behaviour; it's a use of the containers' `operator[]` method and highlighted as such.

(you can also ctrl-click to jump to its definition, hover to view the info tooltip for that method, etc.)

As mentioned in the previous report, it would be nice if the closing bracket was also highlighted, but that may be awkward to implement.

*** This bug has been marked as a duplicate of bug 372875 ***
Comment 3 Francis Herne 2020-03-30 21:52:52 UTC
I suppose we could keep this open and say the closing bracket /not/ being highlighted is a bug...

It's been like this for a long time though (and also in Python) and not many people seem to mind.
Comment 4 kogiokkafrms 2020-03-31 14:07:17 UTC
Thanks for your fast reply and explanation.

I would argue that this is something worth the time fixing, although I don't know how hard it would be in terms of technical reasons. After reading both the bug reports, I think we at least agree that this is not a desired result. Even if I am convinced it's not a bug from now on, newcomers will still think it is, since it's really an unusual choice and against human instinct.

Most users just want a working tool and get their job done. If they find something get in their way, for example, "annoying inconsistent syntax-highlighting", they might just leave for other tools without reporting or commenting on the issue. I'm not like a marketing manager or something, but that's my two cents on possible reasons why people seem don't mind.
Comment 5 kogiokkafrms 2020-03-31 14:37:23 UTC
Just let you know I would love to contribute to the development if there are no enough time or people in the team, so I'll mark this issue reopened. I will need some direction for the start though.

I notice that while loop parenthesis can also get inconsistent coloring, just for the record:
-------------------------
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

int
main()
{
  std::string const greeting = "Hello:World:!";
  std::istringstream iss(greeting);
  std::string token;
  while (std::getline(iss, token, ':')) {
    std::cout << token << std::endl;
  }
}
-------------------------

Before this issue being resolved, maybe there are some workarounds like disabling the syntax-highlighting for all operator functions?
Comment 6 kogiokkafrms 2020-03-31 14:40:33 UTC
Created attachment 127140 [details]
operator bool() of a while loop
Comment 7 Sven Brauch 2020-03-31 17:30:21 UTC
The parenthesis in your loop is highlighting for the operator bool() of the iterator.

This is a feature and users will be angry if you remove it (and rightfully so). The functionality to highlight and inspect implicit invocations of operators is a very nice feature most other editors or IDEs lack.

It can be argued that the presentation is not optimal. Maybe something better could be crafted by using KTextEditor's InlineNoteInterface.
Comment 8 kogiokkafrms 2020-04-02 02:34:08 UTC
So workaround like disabling syntax-highlighting for operators is a no go. But saying the second bracket/parenthesis not highlighted is still a valid bug report , isn't it? It's an undesired result, although it won't be fix in the near future due to technical reasons.