Add more precise tag for function/class declaration names #1

Merged
BrianHung merged 1 commit from patch-1 into main 2021-01-13 09:03:23 +01:00
BrianHung commented 2021-01-13 02:06:53 +01:00 (Migrated from github.com)

Similar to github.com/codemirror/lang-python@162be8f40a.

I referenced the tests from lezer-parser/javascript, which has tests for FunctionDeclaration/VariableDefinition and ClassDeclaration/VariableDefinition.

For the pull request, I am assuming that for purposes of syntax highlighting that ClassDefinition/VariableName and FunctionDefinition/VariableName in python should give the same output as ClassDeclaration/VariableDefinition and FunctionDeclaration/VariableDefinition in javascript.

Even though in javascript there is both VariableDefinition and VariableName, while in python there's only VariableName. This is a slight deviation from codemirror 5 since both function definition names and function parameter names are given the same cm-def span.

The alternative for FunctionDeclaration/VariableDefinition, instead of

"FunctionDeclaration/VariableDefinition": t.function(t.definition(t.variableName))

can be

VariableDefinition: t.definition(t.variableName), // already exists
"FunctionDeclaration/VariableDefinition": t.function(t.definition(t.definition(t.variableName)))

The drawback for this is if you wanted to highlight function definition names in both python and javascript, you would have to have an additional tag:

  {tag: [tags.function(tags.definition(tags.variableName)), tags.function(tags.definition(tags.definition(tags.variableName)))],
   color: "#6f42c1"},
Similar to https://github.com/codemirror/lang-python/commit/162be8f40aebb19334cf229d52e918e626a060ec. I referenced the tests from [`lezer-parser/javascript`](https://github.com/lezer-parser/javascript/blob/master/test/statement.txt), which has tests for `FunctionDeclaration/VariableDefinition` and `ClassDeclaration/VariableDefinition`. For the pull request, I am assuming that for purposes of syntax highlighting that `ClassDefinition/VariableName` and `FunctionDefinition/VariableName` in python should give the same output as `ClassDeclaration/VariableDefinition` and `FunctionDeclaration/VariableDefinition` in javascript. Even though in javascript there is both `VariableDefinition` and `VariableName`, while in python there's only `VariableName`. This is a slight deviation from codemirror 5 since both function definition names and function parameter names are given the same `cm-def` span. The alternative for `FunctionDeclaration/VariableDefinition`, instead of ```js "FunctionDeclaration/VariableDefinition": t.function(t.definition(t.variableName)) ``` can be ```js VariableDefinition: t.definition(t.variableName), // already exists "FunctionDeclaration/VariableDefinition": t.function(t.definition(t.definition(t.variableName))) ``` The drawback for this is if you wanted to highlight function definition names in both python and javascript, you would have to have an additional tag: ```js {tag: [tags.function(tags.definition(tags.variableName)), tags.function(tags.definition(tags.definition(tags.variableName)))], color: "#6f42c1"}, ```
marijnh commented 2021-01-13 09:02:45 +01:00 (Migrated from github.com)

Applying a tag modifier twice is a no-op, so t.defintion(t.defintion(x)) equals t.definition(x). The patch looks good as it is.

Applying a tag modifier twice is a no-op, so `t.defintion(t.defintion(x))` equals `t.definition(x)`. The patch looks good as it is.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/lang-javascript!1
No description provided.