Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree-sitter running fixes (October) #789

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/language-c/grammars/modern-tree-sitter-c.cson
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ fileTypes: [
'c'
'h.in'
]

comments:
start: '// '
DeeDeeG marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions packages/language-c/grammars/modern-tree-sitter-cpp.cson
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parser: 'tree-sitter-cpp'
injectionRegex: '^(c|C)(\\+\\+|pp|PP)$'

treeSitter:
parserSource: 'github:tree-sitter/tree-sitter-cpp#a90f170f92d5d70e7c2d4183c146e61ba5f3a457'
grammar: 'tree-sitter-cpp/tree-sitter-cpp.wasm'
highlightsQuery: 'tree-sitter-cpp/highlights.scm'
tagsQuery: 'tree-sitter-cpp/tags.scm'
Expand Down Expand Up @@ -33,3 +34,6 @@ fileTypes: [
]

contentRegex: '\n\\s*(namespace|class|template)\\s+'

comments:
start: '// '
50 changes: 43 additions & 7 deletions packages/language-c/grammars/tree-sitter-cpp/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@

(primitive_type) @support.type.builtin.cpp

; Type parameters
(template_argument_list
(type_descriptor
type: (type_identifier) @variable.parameter.type.cpp
(#set! capture.final true)))
; Mark all function definition types with data…
(function_definition
type: (_) @_IGNORE_
(#set! functionDefinitionType true))

; …so that we can detect when a type identifier is part of a template/generic.
((type_identifier) @variable.parameter.type.cpp
(#is? test.descendantOfNodeWithData functionDefinitionType))

(class_specifier
(type_identifier) @entity.name.class.cpp
Expand Down Expand Up @@ -124,6 +126,15 @@
(function_declarator
(identifier) @entity.name.function.cpp)

(function_declarator
(destructor_name
(identifier) @entity.name.function.cpp))

; The "foo" in `void Bar::foo () {`.
(function_declarator
declarator: (qualified_identifier
name: (identifier) @entity.name.function.cpp))

(function_declarator
(field_identifier) @entity.name.function.method.cpp)

Expand All @@ -139,6 +150,19 @@
field: (field_identifier) @support.other.function.cpp)
(#set! capture.final true))

; The "foo" in `troz::foo(...)`.
(call_expression
function: (qualified_identifier
name: (identifier) @support.other.function.cpp)
(#set! capture.final true))

; The "foo" in `troz::foo<SomeType>(...)`.
(call_expression
function: (qualified_identifier
name: (template_function
name: (identifier) @support.other.function.cpp))
(#set! capture.final true))

(call_expression
(identifier) @support.other.function.cpp
(#set! capture.final true))
Expand Down Expand Up @@ -206,8 +230,14 @@
(assignment_expression
left: (identifier) @variable.other.assignment.cpp)

(reference_declarator
; The "foo" in `bar.foo = "baz"`.
(assignment_expression
left: (field_expression
field: (field_identifier) @variable.other.member.assignment.cpp))

((reference_declarator
(identifier) @variable.declaration.cpp)
(#is-not? test.descendantOfType parameter_declaration))

; Function parameters
; -------------------
Expand All @@ -222,6 +252,11 @@
declarator: (pointer_declarator
declarator: (identifier) @variable.parameter.cpp))

(parameter_declaration
declarator: (reference_declarator
(identifier) @variable.parameter.cpp))


; The "foo" in `const char foo[]` within a parameter list.
(parameter_declaration
declarator: (array_declarator
Expand Down Expand Up @@ -256,7 +291,6 @@
(null)
(true)
(false)
(nullptr)
] @constant.language._TYPE_.cpp

((identifier) @constant.cpp
Expand Down Expand Up @@ -315,6 +349,7 @@
"throw"
"using"
"namespace"
"class"
] @keyword.control._TYPE_.cpp

; OPERATORS
Expand All @@ -324,6 +359,7 @@
(abstract_pointer_declarator "*" @keyword.operator.pointer.cpp)
(pointer_expression "*" @keyword.operator.pointer.cpp)

(destructor_name "~" @keyword.operator.destructor.cpp)

"sizeof" @keyword.operator.sizeof.cpp
(pointer_expression "&" @keyword.operator.pointer.cpp)
Expand Down
Binary file not shown.
6 changes: 3 additions & 3 deletions src/wasm-tree-sitter-language-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3838,13 +3838,13 @@ class LanguageLayer {
if (existingInjectionMarkers.length > 0) {
// Enlarge our range to contain all of the injection zones in the
// affected buffer range.
let earliest, latest;
let earliest = range.start, latest = range.end;
for (let marker of existingInjectionMarkers) {
range = marker.getRange();
if (!earliest || range.start.compare(earliest) === -1) {
if (range.start.compare(earliest) === -1) {
earliest = range.start;
}
if (!latest || range.end.compare(latest) === 1) {
if (range.end.compare(latest) === 1) {
latest = range.end;
}
}
Expand Down