Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Operator function scope incorrectly #240

Open
1 task done
jerrykal opened this issue Jun 5, 2017 · 3 comments
Open
1 task done

Operator function scope incorrectly #240

jerrykal opened this issue Jun 5, 2017 · 3 comments

Comments

@jerrykal
Copy link
Contributor

jerrykal commented Jun 5, 2017

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
Copy link
Contributor

thomasjo commented Nov 3, 2018

@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 thomasjo added the bug label Nov 3, 2018
@thomasjo
Copy link
Contributor

thomasjo commented Nov 3, 2018

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
Copy link
Contributor

Ben3eeE commented Nov 3, 2018

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:

  • operator a separate node for operator because it's a keyword. And we want to scope it as keyword.control
  • operator_name is just the +

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants