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

Project import generated by Copybara. #23

Merged
merged 1 commit into from
Sep 19, 2023
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
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,23 @@ Queries try to follow the [conventions established by tree-sitter.](https://tree

Most captures also include documentation as `@doc`. `@definition.function` and `@definition.method` also capture `@codeium.parameters`.

| Top-level capture | Python | TypeScript | JavaScript | Go | Java | C++ | PHP |
| ---------------------- | ------ | ---------- | ---------- | --- | ---- | ------ | --- |
| `@definition.class` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| `@definition.function` | ✅ | ✅[^3] | ✅ | ✅ | N/A | ✅ | ✅ |
| `@definition.method` | ✅[^1] | ✅[^3] | ✅ | ✅ | ✅ | ✅[^1] | ✅ |
| `@definition.interface` | N/A | ✅ | N/A | ✅ | ✅ | N/A | ✅ |
| `@definition.namespace` | N/A | ✅ | N/A | N/A | N/A | ✅ | ✅ |
| `@definition.module` | N/A | ✅ | N/A | N/A | N/A | ❌ | N/A |
| `@definition.type` | N/A | ✅ | N/A | ✅ | N/A | ❌ | ❌ |
| `@definition.constant` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| `@definition.enum` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| `@definition.import` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | N/A |
| `@definition.include` | N/A | N/A | N/A | N/A | N/A | ❌ | ❌ |
| `@definition.package` | N/A | N/A | N/A | ✅ | ✅ | N/A | N/A |
| `@reference.call` | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| `@reference.class` | ✅[^2] | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Top-level capture | Python | TypeScript | JavaScript | Go | Java | C++ | PHP | Ruby |
| ------------------------- | ------ | ---------- | ---------- | --- | ---- | ------ | --- | ---- |
| `@definition.class` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| `@definition.function` | ✅ | ✅[^3] | ✅ | ✅ | N/A | ✅ | ✅ | N/A |
| `@definition.method` | ✅[^1] | ✅[^3] | ✅ | ✅ | ✅ | ✅[^1] | ✅ | ✅ |
| `@definition.constructor` | ✅ | ✅ | ✅ | N/A | ❌ | ❌ | ❌ | ❌ |
| `@definition.interface` | N/A | ✅ | N/A | ✅ | ✅ | N/A | ✅ | ❌ |
| `@definition.namespace` | N/A | ✅ | N/A | N/A | N/A | ✅ | ✅ | N/A |
| `@definition.module` | N/A | ✅ | N/A | N/A | N/A | ❌ | N/A | ✅ |
| `@definition.type` | N/A | ✅ | N/A | ✅ | N/A | ❌ | ❌ | N/A |
| `@definition.constant` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| `@definition.enum` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | N/A |
| `@definition.import` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | N/A | ✅ |
| `@definition.include` | N/A | N/A | N/A | N/A | N/A | ❌ | ❌ | N/A |
| `@definition.package` | N/A | N/A | N/A | ✅ | ✅ | N/A | N/A | N/A |
| `@reference.call` | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
| `@reference.class` | ✅[^2] | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |

| Language | Supported injections |
| -------- | ---------------------- |
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.12"
VERSION="v0.0.13"
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
4 changes: 4 additions & 0 deletions goldens/test.cpp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Name: Foo
Definition (definition.class):
class Foo {
public:
// Constructor comment.
Foo() = default;
// Constructor comment.
explicit Foo(int /*unused*/) {}
// foo
// foo2
void foo() {
Expand Down
5 changes: 3 additions & 2 deletions goldens/test.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Return type: string
Definition (definition.method):
func (p Pattern0) Method2(a string) string {
Pattern2()
s := &Pattern0{}
s := &Pattern0{a: "foo"}
s.Method("")
((*Pattern0)(s)).Method("")
var s2 any
Expand All @@ -72,8 +72,9 @@ Reference (reference.call):
Pattern2()

Name: Pattern0
Parameters: {a: "foo"}
Reference (reference.class):
Pattern0{}
Pattern0{a: "foo"}

Name: Method
Parent: s
Expand Down
2 changes: 2 additions & 0 deletions goldens/test.java.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Doc:
// Class Foo.
Definition (definition.class):
public class Foo {
// Constructor comment.
public Foo() {}
/** Foo1. */
static public void foo1(int x) {}
}
Expand Down
7 changes: 7 additions & 0 deletions goldens/test.js.golden
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class Pattern1a {
}
}

Name: constructor
Parameters: ()
Definition (definition.constructor):
constructor() {}
Lineage: [Pattern1a]
Lineage types: [class]

Name: pattern0
Parameters: (param1)
Doc:
Expand Down
11 changes: 11 additions & 0 deletions goldens/test.php.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Doc:
Definition (definition.class):
class FooClass implements FooInterface
{
// Constructor comment.
function __construct() {}
/**
* @param mixed $numbers
* @return string
Expand All @@ -46,6 +48,15 @@ class FooClass implements FooInterface
Lineage: [test]
Lineage types: [namespace]

Name: __construct
Parameters: ()
Doc:
// Constructor comment.
Definition (definition.method):
function __construct() {}
Lineage: [test FooClass]
Lineage types: [namespace class]

Name: encode
Parameters: (...$numbers)
Doc:
Expand Down
10 changes: 10 additions & 0 deletions goldens/test.py.golden
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ Doc:
Definition (definition.class):
class Pattern0:
"""Pattern 0 docstring."""
def __init__(self):
pass

Name: __init__
Parameters: (self)
Definition (definition.constructor):
def __init__(self):
pass
Lineage: [Pattern0]
Lineage types: [class]

Name: Pattern0NoDoc
Definition (definition.class):
Expand Down
5 changes: 5 additions & 0 deletions goldens/test.rb.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Doc:
# nothing strange here
Declaration (definition.class):
class SomeClass
def initialize
end
# In ruby, the parentheses can be omitted in many circumstances
# This is probably a job for the AST, but we'll add a test here anyway
def empty_parens()
Expand All @@ -17,6 +19,9 @@ end

Name: empty_parens
Parameters: ()
Doc:
# In ruby, the parentheses can be omitted in many circumstances
# This is probably a job for the AST, but we'll add a test here anyway
Definition (definition.method):
def empty_parens()
"Nice"
Expand Down
11 changes: 11 additions & 0 deletions goldens/test.tsx.golden
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,23 @@ Doc:
/** Foo comment. */
Definition (definition.class):
class Foo {
// Constructor comment.
constructor() {}
/** methodSignature comment. */
methodSignature(): void;
/** methodSignature comment. */
methodSignature(): void {}
}

Name: constructor
Parameters: ()
Doc:
// Constructor comment.
Definition (definition.constructor):
constructor() {}
Lineage: [Foo]
Lineage types: [class]

Name: methodSignature
Parameters: ()
Return type: void
Expand Down
3 changes: 2 additions & 1 deletion queries/go_tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
(qualified_type
package: (package_identifier) @parent
name: (type_identifier) @name)
]) @reference.class
]
(literal_value) @codeium.parameters) @reference.class

;; 6. Pattern 3 from tags.scm.
;; Restricted to just type aliases.
Expand Down
4 changes: 2 additions & 2 deletions queries/java_class_fields.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(class_body
([
(constructor_declaration)
]) @codeium.constructor
]) @definition.constructor
)
)

Expand All @@ -21,6 +21,6 @@
([
(constructor_declaration)
(compact_constructor_declaration)
]) @codeium.constructor
]) @definition.constructor
)
)
12 changes: 0 additions & 12 deletions queries/javascript_class_fields.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,3 @@
]) @field
)
)

(
(comment)* @doc
.
(_
name: (property_identifier) @name
parameters: (formal_parameters) @codeium.parameters
body: (_)? @body) @codeium.constructor
(#eq? @name "constructor")
(#has-type? @codeium.constructor method_definition method_signature abstract_method_signature)
(#select-adjacent! @doc @codeium.constructor)
)
11 changes: 11 additions & 0 deletions queries/javascript_constructors.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(
(comment)* @doc
.
(_
name: (property_identifier) @name
parameters: (formal_parameters) @codeium.parameters
body: (_)? @body) @definition.constructor
(#eq? @name "constructor")
(#has-type? @definition.constructor method_definition method_signature abstract_method_signature)
(#select-adjacent! @doc @definition.constructor)
)
4 changes: 4 additions & 0 deletions queries/markdown_injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(
(inline) @injection.content
(#set! injection.language markdown_inline)
)
7 changes: 0 additions & 7 deletions queries/python_class_fields.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,3 @@
(assignment) @field
))
)
(
(function_definition
name: (identifier) @name
parameters: (parameters) @codeium.parameters
body: (block . (expression_statement . (string) @doc .)?) @body) @codeium.constructor
(#eq? @name "__init__")
)
17 changes: 17 additions & 0 deletions queries/python_constructors.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(
(function_definition
name: (identifier) @name
parameters: (parameters) @codeium.parameters
body: (block . (expression_statement . (string) @doc .)?) @body) @definition.constructor
(#not-has-parent? @definition.constructor decorated_definition)
(#eq? @name "__init__")
)

(
(decorated_definition
definition: (function_definition
name: (identifier) @name
parameters: (parameters) @codeium.parameters
body: (block . (expression_statement . (string) @doc .)?) @body)) @definition.constructor
(#eq? @name "__init__")
)
1 change: 1 addition & 0 deletions queries/python_tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
name: (identifier) @name
parameters: (parameters) @codeium.parameters
body: (block . (expression_statement . (string) @doc .)?) @body)) @definition.function
(#not-eq? @name "__init__")
)
19 changes: 1 addition & 18 deletions queries/typescript_class_fields.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,8 @@
(object_type
[
(property_signature) @field
(construct_signature) @codeium.constructor
(construct_signature) @definition.constructor
(_)
]
)
)

(
(comment)* @doc
.
(_
name: (property_identifier) @name
parameters: (formal_parameters) @codeium.parameters
return_type: ([
(type_annotation (_) @codeium.return_type)
(asserts (_) @codeium.return_type)
(type_predicate_annotation (_) @codeium.return_type)
])?
body: (_)? @body) @codeium.constructor
(#eq? @name "constructor")
(#has-type? @codeium.constructor method_definition method_signature abstract_method_signature)
(#select-adjacent! @doc @codeium.constructor)
)
16 changes: 16 additions & 0 deletions queries/typescript_constructors.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(
(comment)* @doc
.
(_
name: (property_identifier) @name
parameters: (formal_parameters) @codeium.parameters
return_type: ([
(type_annotation (_) @codeium.return_type)
(asserts (_) @codeium.return_type)
(type_predicate_annotation (_) @codeium.return_type)
])?
body: (_)? @body) @definition.constructor
(#eq? @name "constructor")
(#has-type? @definition.constructor method_definition method_signature abstract_method_signature)
(#select-adjacent! @doc @definition.constructor)
)
4 changes: 4 additions & 0 deletions test_files/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct Foo3;

class Foo {
public:
// Constructor comment.
Foo() = default;
// Constructor comment.
explicit Foo(int /*unused*/) {}
// foo
// foo2
void foo() {
Expand Down
2 changes: 1 addition & 1 deletion test_files/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (p *Pattern0) Method(string) {}

func (p Pattern0) Method2(a string) string {
Pattern2()
s := &Pattern0{}
s := &Pattern0{a: "foo"}
s.Method("")
((*Pattern0)(s)).Method("")
var s2 any
Expand Down
2 changes: 2 additions & 0 deletions test_files/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Class Foo.
public class Foo {
// Constructor comment.
public Foo() {}
/** Foo1. */
static public void foo1(int x) {}
}
Expand Down
2 changes: 2 additions & 0 deletions test_files/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function encode(...$numbers);
// FooClass.
class FooClass implements FooInterface
{
// Constructor comment.
function __construct() {}
/**
* @param mixed $numbers
* @return string
Expand Down
2 changes: 2 additions & 0 deletions test_files/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class Pattern0:
"""Pattern 0 docstring."""
def __init__(self):
pass

class Pattern0NoDoc:
def pattern1(self):
Expand Down
2 changes: 2 additions & 0 deletions test_files/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This is just your standard class
# nothing strange here
class SomeClass
def initialize
end
# In ruby, the parentheses can be omitted in many circumstances
# This is probably a job for the AST, but we'll add a test here anyway
def empty_parens()
Expand Down
2 changes: 2 additions & 0 deletions test_files/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export declare function f4(): void;

/** Foo comment. */
class Foo {
// Constructor comment.
constructor() {}
/** methodSignature comment. */
methodSignature(): void;
/** methodSignature comment. */
Expand Down