atom / language-c

C support in Atom
Other
117 stars 153 forks source link

Operator function scope incorrectly #240

Open jerrykal opened 7 years ago

jerrykal commented 7 years ago

Prerequisites

Description

The operator function like T operator+(const T &l, const T &r); scope incorrectly.

Steps to Reproduce

  1. Open an C++ file and type T operator+(const T &l, const T &r);
  2. Move the cursor to the operator operator and press ++P
  3. And then you can see the scope is keyword.control.cpp not entity.name.function.cpp

Expected behavior: The scope should be entity.name.function.cpp.

Actual behavior: The scope is keyword.control.cpp.

Versions

Atom: 1.18.0-beta2 OS: macOS Sierra

thomasjo commented 5 years ago

@maxbrunsfeld / @Ben3eeE As far as I can tell, this will have to be fixed in tree-sitter-cpp.

As discussed between @Ben3eeE and myself on Slack earlier, there can be an arbitrary amount of whitespace between the operator keyword and the operator name, e.g. T operator +(const T &l, const T &r);. Currently this gets parsed as math_expression "+".

thomasjo commented 5 years ago

Note that we must handle the operator keyword and the operator name (e.g. +) as two distinct entities, regardless of optional whitespace between. I suggest that the current scope — keyword.control.cpp — is reasonable for operator, but not for the entire operator+ expression. The + should be scoped as entity.name.function.cpp (or equivalent).

Ben3eeE commented 5 years ago

Right now tree-sitter parses the entire: operator+ as operator_name. If you add a space before the operator and the keyword operator it parses with ERROR and math_expression. operator is parsed as any identifier.

Am I correct in that it should be parsed as:

In language-c now operator is not a keyword and operator_name is not scoped at all.