Skip to content

Commit

Permalink
Project import generated by Copybara. (#21)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: ac6edd030a2f25c17973b5d7386cb9b5d74c9a5a

Co-authored-by: Copybara Bot <[email protected]>
  • Loading branch information
pqn and Copybara Bot committed Aug 3, 2023
1 parent 2ac0dca commit 7be8f1c
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 45 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Most captures also include documentation as `@doc`. `@definition.function` and `
| Language | Supported injections |
| -------- | ---------------------- |
| Vue | JavaScript, TypeScript |
| HTML | JavaScript |

[^1]: Currently functions and methods are not distinguished.
[^2]: Function calls and class instantiation are indistinguishable in Python.
Expand Down Expand Up @@ -157,6 +158,7 @@ html
java
javascript
json
julia
kotlin
latex
markdown
Expand Down
2 changes: 1 addition & 1 deletion download_parse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"
VERSION="v0.0.11"
VERSION="v0.0.12"
rm -f parse.gz parse
curl -Lo parse.gz "https://github.com/Exafunction/codeium-parse/releases/download/$VERSION/parse.gz"
gzip -d parse.gz
Expand Down
58 changes: 52 additions & 6 deletions goldens/test.cpp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,66 @@ Lineage types: [unknown]

Name: one_pointer
Parameters: ()
Return type: bool
Return type: bool*
Doc:
// one_pointer comment
Definition (definition.function):
bool* one_pointer() { return nullptr; }
Metadata:
return_type_suffix = *

Name: two_pointer
Parameters: ()
Return type: bool
Return type: bool**
Doc:
// two_pointer comment
Definition (definition.function):
bool** two_pointer() { return nullptr; }
Metadata:
return_type_suffix = **

Name: TemplatedFoo
Doc:
// Comment.
Definition (definition.class):
template <typename T>
class TemplatedFoo {
template <typename U>
void foo();
};

Name: foo
Parameters: ()
Return type: void
Declaration (definition.function):
template <typename U>
void foo();
Lineage: [TemplatedFoo]
Lineage types: [class]

Name: foo
Parameters: ()
Return type: void
Doc:
// Comment.
Definition (definition.function):
template <typename T>
template <typename U>
void TemplatedFoo<T>::foo() {}
Lineage: [TemplatedFoo<T>]
Lineage types: [unknown]

Name: foo<int>
Parameters: ()
Return type: void
Doc:
// Comment.
Definition (definition.function):
template <>
template <>
void TemplatedFoo<int>::foo<int>() {}
Lineage: [TemplatedFoo<int>]
Lineage types: [unknown]

Name: TemplatedFoo2<int>
Doc:
// Comment.
Definition (definition.class):
template <>
class TemplatedFoo2<int> {};
1 change: 1 addition & 0 deletions goldens/test.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Reference (reference.class):
Pattern0{}

Name: Method
Parent: s
Parameters: ("")
Reference (reference.call):
s.Method("")
Expand Down
4 changes: 4 additions & 0 deletions goldens/test.py.golden
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ def pattern1(param1):
'Pattern 1 docstring.'

Name: Pattern2a
Parameters: ()
Reference (reference.call):
Pattern2a()

Name: pattern2b
Parameters: (1)
Reference (reference.call):
pattern2b(1)

Name: foo
Parent: Pattern2a
Parameters: ()
Reference (reference.call):
Pattern2a.foo()

Expand Down
134 changes: 99 additions & 35 deletions queries/cpp_tags.scm
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
(
(comment)* @doc
.
(class_specifier
name: (_) @name
body: (field_declaration_list) @body
) @definition.class
(#select-adjacent! @doc @definition.class)
(#lineage-from-name! "::")
)
(
(comment)* @doc
.
(struct_specifier
(_
name: (_) @name
body: (field_declaration_list) @body
) @definition.class
(#has-type? @definition.class class_specifier struct_specifier)
(#not-has-parent? @definition.class template_declaration)
(#select-adjacent! @doc @definition.class)
(#lineage-from-name! "::")
)
Expand All @@ -24,49 +16,121 @@
.
(_
(_type_specifier) @codeium.return_type
declarator: (function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)
declarator: [
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)
(pointer_declarator
"*" @codeium.return_type
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters))
(pointer_declarator
"*" @codeium.return_type
(pointer_declarator
"*" @codeium.return_type
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)))
]
body: (_)? @body) @definition.function
(#has-type? @definition.function function_definition declaration)
(#not-has-parent? @definition.function template_declaration)
(#select-adjacent! @doc @definition.function)
(#lineage-from-name! "::")
)

(namespace_definition
name: (_) @name
(#lineage-from-name! "::")
) @definition.namespace

;; Copy to deal with single templates
(
(comment)* @doc
.
(_
(_type_specifier) @codeium.return_type
declarator: (pointer_declarator
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters))
body: (_)? @body) @definition.function
(#has-type? @definition.function function_definition declaration)
(#select-adjacent! @doc @definition.function)
(template_declaration
(_
name: (_) @name
body: (field_declaration_list) @body) @_) @definition.class
(#has-type? @_ class_specifier struct_specifier)
(#not-has-parent? @definition.class template_declaration)
(#select-adjacent! @doc @definition.class)
(#lineage-from-name! "::")
(#set! return_type_suffix "*")
)

(
(comment)* @doc
.
(_
(_type_specifier) @codeium.return_type
declarator: (pointer_declarator
(pointer_declarator
(template_declaration
(_
(_type_specifier) @codeium.return_type
declarator: [
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)))
body: (_)? @body) @definition.function
(#has-type? @definition.function function_definition declaration)
parameters: (parameter_list) @codeium.parameters)
(pointer_declarator
"*" @codeium.return_type
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters))
(pointer_declarator
"*" @codeium.return_type
(pointer_declarator
"*" @codeium.return_type
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)))
]
body: (_)? @body) @_) @definition.function
(#has-type? @_ function_definition declaration)
(#not-has-parent? @definition.function template_declaration)
(#select-adjacent! @doc @definition.function)
(#lineage-from-name! "::")
(#set! return_type_suffix "**")
)

(namespace_definition
name: (_) @name
;; Copy to deal with double templates
(
(comment)* @doc
.
(template_declaration
(template_declaration
(_
name: (_) @name
body: (field_declaration_list) @body) @_)) @definition.class
(#has-type? @_ class_specifier struct_specifier)
;; (#not-has-parent? @definition.class template_declaration)
(#select-adjacent! @doc @definition.class)
(#lineage-from-name! "::")
) @definition.namespace
)

(
(comment)* @doc
.
(template_declaration
(template_declaration
(_
(_type_specifier) @codeium.return_type
declarator: [
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)
(pointer_declarator
"*" @codeium.return_type
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters))
(pointer_declarator
"*" @codeium.return_type
(pointer_declarator
"*" @codeium.return_type
(function_declarator
declarator: (_) @name
parameters: (parameter_list) @codeium.parameters)))
]
body: (_)? @body) @_)) @definition.function
(#has-type? @_ function_definition declaration)
;; (#not-has-parent? @definition.function template_declaration)
(#select-adjacent! @doc @definition.function)
(#lineage-from-name! "::")
)
13 changes: 11 additions & 2 deletions queries/go_tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,22 @@
(call_expression
function: [
(identifier) @name
(selector_expression field: (field_identifier) @name)
(selector_expression
operand: (identifier) @parent
field: (field_identifier) @name)
(selector_expression
field: (field_identifier) @name)
]
arguments: (argument_list) @codeium.parameters) @reference.call

;; 5.
(composite_literal
type: (type_identifier) @name) @reference.class
type: [
(type_identifier) @name
(qualified_type
package: (package_identifier) @parent
name: (type_identifier) @name)
]) @reference.class

;; 6. Pattern 3 from tags.scm.
;; Restricted to just type aliases.
Expand Down
4 changes: 3 additions & 1 deletion queries/python_tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
function: [
(identifier) @name
(attribute
object: (identifier) @parent
attribute: (identifier) @name)
]) @reference.call
]
arguments: (argument_list) @codeium.parameters) @reference.call

(
(decorated_definition
Expand Down
25 changes: 25 additions & 0 deletions test_files/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,28 @@ bool bar::baz(const std::string& bing) {
bool* one_pointer() { return nullptr; }
// two_pointer comment
bool** two_pointer() { return nullptr; }

// Comment.
template <typename T>
class TemplatedFoo {
template <typename U>
void foo();
};

// Comment.
template <typename T>
template <typename U>
void TemplatedFoo<T>::foo() {}

// Comment.
template <>
template <>
void TemplatedFoo<int>::foo<int>() {}

// Comment.
template <typename T>
class TemplatedFoo2;

// Comment.
template <>
class TemplatedFoo2<int> {};

0 comments on commit 7be8f1c

Please sign in to comment.