Skip to content

Bring to head of internal repo #28

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

Merged
merged 1 commit into from
Jul 9, 2024
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
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,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 | Ruby | C# |
| ------------------------- | ------ | ---------- | ---------- | --- | ---- | ----- | --- | ---- | --- |
| `@definition.class` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| `@definition.function` | ✓ | ✓[^3] | ✓ | ✓ | N/A | ✓ | ✓ | 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 | ✓ | N/A |
| `@definition.type` | N/A | ✓ | 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 | N/A |
| `@definition.package` | N/A | N/A | 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 | C# | Perl | Kotlin | Dart | Bash | C |
| ------------------------- | ------ | ---------- | ---------- | --- | ---- | ----- | --- | ---- | --- | ----- | ------ | ----- | ---- | --- |
| `@definition.class` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
| `@definition.function` | ✓ | ✓[^3] | ✓ | ✓ | N/A | ✓ | ✓ | N/A | N/A | ✓ | ✓ | ✓ | ✓ | ✓ |
| `@definition.method` | ✓[^1] | ✓[^3] | ✓ | ✓ | ✓ | ✓[^1] | ✓ | ✓ | ✓ | ✓[^1] | ✓ | ✓[^1] | ✓ | ✓ |
| `@definition.constructor` | ✓ | ✓ | ✓ | N/A | ✗ | ✗ | ✗ | ✗ | ✓ | ✗ | ✓ | ✗ | N/A | N/A |
| `@definition.interface` | N/A | ✓ | N/A | ✓ | ✓ | N/A | ✓ | ✗ | ✓ | N/A | | ✗ | N/A | N/A |
| `@definition.namespace` | N/A | ✓ | N/A | N/A | N/A | ✓ | ✓ | N/A | ✓ | ✗ | ✗ | N/A | N/A | N/A |
| `@definition.module` | N/A | ✓ | N/A | N/A | N/A | ✗ | N/A | ✓ | N/A | N/A | N/A | ✗ | N/A | N/A |
| `@definition.type` | N/A | ✓ | N/A | ✓ | N/A | ✗ | ✗ | N/A | N/A | N/A | N/A | ✗ | N/A | N/A |
| `@definition.constant` | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | N/A | ✗ |
| `@definition.enum` | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | N/A | ✓ | N/A | ✗ | ✗ | N/A | ✗ |
| `@definition.import` | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | N/A | ✓ | ✗ | ✓ | ✓ | ✗ | N/A | ✓ |
| `@definition.include` | N/A | N/A | N/A | N/A | N/A | ✗ | ✗ | N/A | 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 | N/A | N/A | N/A | N/A | N/A | N/A |
| `@reference.call` | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
| `@reference.class` | ✓[^2] | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | N/A | N/A |

| 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.14"
VERSION="v0.0.15"
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
26 changes: 26 additions & 0 deletions goldens/test.c.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Name: "runtime/parser.h"
Definition (definition.import):
#include "runtime/parser.h"



Name: parser__push
Parameters: (Parser* self, StackVersion version, Tree* tree,
TSStateId state)
Return type: void
Definition (definition.function):
static void parser__push(Parser* self, StackVersion version, Tree* tree,
TSStateId state) {
ts_stack_push(self->stack, version, tree, false, state);
ts_tree_release(tree);
}

Name: parser__lex
Parameters: (Parser* self, StackVersion version)
Return type: Tree
Definition (definition.function):
static Tree* parser__lex(Parser* self, StackVersion version) {
TSStateId parse_state = ts_stack_top_state(self->stack, version);
Length start_position = ts_stack_top_position(self->stack, version);
TSLexMode lex_mode = self->language->lex_modes[parse_state];
}
18 changes: 18 additions & 0 deletions goldens/test.cpp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ class Foo {
}
}

Name: Foo
Parameters: ()
Doc:
// Constructor comment.
Declaration (definition.function):
Foo() = default;
Lineage: [Foo]
Lineage types: [class]

Name: Foo
Parameters: (int /*unused*/)
Doc:
// Constructor comment.
Definition (definition.function):
explicit Foo(int /*unused*/) {}
Lineage: [Foo]
Lineage types: [class]

Name: foo
Parameters: ()
Return type: void
Expand Down
10 changes: 10 additions & 0 deletions goldens/test.cs.golden
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace Namespace {
// Comment Bar
public void Bar() => bar = 0;
}
// Comment IFoo.
public interface IFoo {}
}

Name: F
Expand Down Expand Up @@ -136,3 +138,11 @@ Definition (definition.method):
public void Bar() => bar = 0;
Lineage: [Namespace Class]
Lineage types: [namespace class]

Name: IFoo
Doc:
// Comment IFoo.
Definition (definition.interface):
public interface IFoo {}
Lineage: [Namespace]
Lineage types: [namespace]
71 changes: 71 additions & 0 deletions goldens/test.dart.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Name: foo
Parameters: ()
Definition (definition.function):
void foo()

Name: bar
Parameters: ()
Doc:
/// bar is a docstring
Definition (definition.function):
int bar()

Name: fooClassBar
Parameters: ()
Doc:
/// FCB docstring
Definition (definition.function):
int fooClassBar()
Lineage: [FooClass]
Lineage types: [class]

Name: FooClass
Definition (definition.class):
class FooClass {
int someField = 0;

// Constructor
FooClass() {
this.someField = 0;
}

/// FCB docstring
int fooClassBar() {
return 0;
}
}

Name: FooMixin
Definition (definition.class):
mixin FooMixin {
int barMixin() {
return 0;
}
}

Name: barMixin
Parameters: ()
Definition (definition.function):
int barMixin()
Lineage: [FooMixin]
Lineage types: [class]

Name: bar
Parameters: ()
Definition (definition.function):
int bar()
Lineage: [FooBar]
Lineage types: [class]

Name: FooBar
Definition (definition.class):
class FooBar extends FooClass with Foo {
int bar() {
return 0;
}
}

Name: main
Parameters: ()
Definition (definition.function):
void main()
55 changes: 55 additions & 0 deletions goldens/test.kt.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Name: kotlinx.coroutines
Named imports:
kotlinx.coroutines

Name: kotlinx.coroutines.sync
Named imports:
kotlinx.coroutines.sync

Name: Foo
Definition (definition.class):
class Foo(param1: Int, param2: Int) {
/**
* Constructor docstring
*
* @param param1
* @param param2
*/
constructor(param1: Int, param2: Int) {}

/** Method docstring */
fun methodWithDocstring(): void {}
}

Name: constructor
Parameters: (param1: Int, param2: Int)
Doc:
/**
* Constructor docstring
*
* @param param1
* @param param2
*/
Declaration (definition.constructor):
constructor(param1: Int, param2: Int) {}
Lineage: [Foo]
Lineage types: [class]

Name: methodWithDocstring
Parameters: ()
Doc:
/** Method docstring */
Definition (definition.function):
fun methodWithDocstring(): void {}
Lineage: [Foo]
Lineage types: [class]

Name: fib
Parameters: (n: Int)
Definition (definition.function):
fun fib(n: Int): Int {
if (n == 0 || n == 1) {
return n
}
return fib(n - 1) + fib(n - 2)
}
62 changes: 62 additions & 0 deletions goldens/test.pl.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Name: strict
Definition (definition.import):
use strict 1.0;

Name: feature
Definition (definition.import):
use feature 'class';

Name: FooClass
Definition (definition.class):
class FooClass {
field $someField = 42;

method bar {
say "The answer is $someField";
}
}

Name: bar
Definition (definition.function):
method bar {
say "The answer is $someField";
}
Lineage: [FooClass]
Lineage types: [class]

Name: foo2
Parameters: ()
Doc:
# foo2 comment
Definition (definition.function):
sub foo2 () {
my $foo = Foo.new;
$foo.bar
}

Name: new
Parameters: ($class, $firstName, $lastName)
Definition (definition.function):
sub new ($class, $firstName, $lastName) {
bless { firstName => $firstName, lastName => $lastName }, $class
}

Name: getFirstName
Parameters: ($self)
Definition (definition.function):
sub getFirstName($self) {
$self->{firstName}
}

Name: Average
Definition (definition.function):
sub Average {
# get total number of arguments passed.
$n = scalar(@_);
$sum = 0;
foreach $item (@_) {
$sum += $item;
}
$average = $sum / $n;
return $average;
}
39 changes: 39 additions & 0 deletions goldens/test.proto.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Name: b
Definition (definition.package):
package a.b;
Lineage: [a]
Lineage types: [package]

Name: TestService
Declaration (definition.class):
service TestService {
rpc Echo(EchoRequest) returns (EchoResponse) {}
}
Lineage: [a b]
Lineage types: [package package]

Name: Echo
Declaration (definition.function):
rpc Echo(EchoRequest) returns (EchoResponse) {}
Lineage: [a b TestService]
Lineage types: [package package class]

Name: EchoRequest
Doc:
// EchoRequest comment.
Definition (definition.class):
message EchoRequest {
string message = 1;
}
Lineage: [a b]
Lineage types: [package package]

Name: EchoResponse
Doc:
// EchoResponse comment.
Definition (definition.class):
message EchoResponse {
string message = 1;
}
Lineage: [a b]
Lineage types: [package package]
16 changes: 16 additions & 0 deletions goldens/test.sh.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Name: do_something
Definition (definition.function):
do_something() {
echo ok
}

Name: do_nothing
Definition (definition.function):
do_nothing() { return 0; }

Name: add
Definition (definition.function):
add() {
sum=$(($1 + $2))
echo $sum
}
10 changes: 10 additions & 0 deletions queries/bash_tags.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; Functions

(
(function_definition
name: (word) @name
body: (_) @body
) @definition.function
)

;; What else do we need here?
11 changes: 11 additions & 0 deletions queries/c_class_fields.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; C struct fields. Unlike for C++, there is no `class_specifier` here.

(
(struct_specifier
body: (
(field_declaration_list
(_) @field
)
)
)
)
Loading
Loading