diff --git a/README.md b/README.md index 5afdc93..b656a9c 100644 --- a/README.md +++ b/README.md @@ -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 | -| ------------------------- | ------ | ---------- | ---------- | --- | ---- | ------ | --- | ---- | -| `@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] | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | +| 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] | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | | Language | Supported injections | | -------- | ---------------------- | diff --git a/download_parse.sh b/download_parse.sh index d58c469..276e4bc 100755 --- a/download_parse.sh +++ b/download_parse.sh @@ -2,7 +2,7 @@ set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" -VERSION="v0.0.13" +VERSION="v0.0.14" rm -f parse.gz parse curl -Lo parse.gz "https://github.com/Exafunction/codeium-parse/releases/download/$VERSION/parse.gz" gzip -d parse.gz diff --git a/goldens.sh b/goldens.sh index 84493ad..6e6c5c7 100755 --- a/goldens.sh +++ b/goldens.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -euo pipefail +set -euxo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" for test_file in test_files/*; do diff --git a/goldens/test.cs.golden b/goldens/test.cs.golden new file mode 100644 index 0000000..2ef05af --- /dev/null +++ b/goldens/test.cs.golden @@ -0,0 +1,138 @@ +Name: Namespace +Definition (definition.namespace): +namespace Namespace { + // Comment A. + internal delegate void A(params int[] test); + // Comment F. + public struct F + where T : struct { + } + // Comment F. + [Nice] + private record F + where T1 : I1, I2, new() + where T2 : I2 {} + // Comment Teacher. + record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName); + // Comment B. + enum B { Ten = 10, Twenty = 20 } + // Comment F. + public class F : object, IAlpha, IOmega {} + // Comment Class. + public partial class Class + where TParam : class ?, notnull, F ? { + // Comment operator +. + public static int operator +(A a) { + return 0; + } + // Comment GetSet. + uint GetSet { get; set; } + // Comment Foo. + static extern Foo() => bar = 0; + // Comment ~Class. + extern ~Class() {} + // Comment Bar + public void Bar() => bar = 0; + } +} + +Name: F +Doc: +// Comment F. +Definition (definition.class): +public struct F + where T : struct { + } +Lineage: [Namespace] +Lineage types: [namespace] + +Name: F +Doc: +// Comment F. +Definition (definition.class): +[Nice] + private record F + where T1 : I1, I2, new() + where T2 : I2 {} +Lineage: [Namespace] +Lineage types: [namespace] + +Name: Teacher +Doc: +// Comment Teacher. +Declaration (definition.class): +record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName); +Lineage: [Namespace] +Lineage types: [namespace] + +Name: B +Doc: +// Comment B. +Definition (definition.enum): +enum B { Ten = 10, Twenty = 20 } +Lineage: [Namespace] +Lineage types: [namespace] + +Name: F +Doc: +// Comment F. +Definition (definition.class): +public class F : object, IAlpha, IOmega {} +Lineage: [Namespace] +Lineage types: [namespace] + +Name: Class +Doc: +// Comment Class. +Definition (definition.class): +public partial class Class + where TParam : class ?, notnull, F ? { + // Comment operator +. + public static int operator +(A a) { + return 0; + } + // Comment GetSet. + uint GetSet { get; set; } + // Comment Foo. + static extern Foo() => bar = 0; + // Comment ~Class. + extern ~Class() {} + // Comment Bar + public void Bar() => bar = 0; + } +Lineage: [Namespace] +Lineage types: [namespace] + +Name: + +Doc: +// Comment operator +. +Definition (definition.method): +public static int operator +(A a) { + return 0; + } +Lineage: [Namespace Class] +Lineage types: [namespace class] + +Name: Foo +Doc: +// Comment Foo. +Definition (definition.constructor): +static extern Foo() => bar = 0; +Lineage: [Namespace Class] +Lineage types: [namespace class] + +Name: Class +Doc: +// Comment ~Class. +Definition (definition.destructor): +extern ~Class() {} +Lineage: [Namespace Class] +Lineage types: [namespace class] + +Name: Bar +Doc: +// Comment Bar +Definition (definition.method): +public void Bar() => bar = 0; +Lineage: [Namespace Class] +Lineage types: [namespace class] diff --git a/queries/csharp_tags.scm b/queries/csharp_tags.scm new file mode 100644 index 0000000..9bbbe3e --- /dev/null +++ b/queries/csharp_tags.scm @@ -0,0 +1,76 @@ +(file_scoped_namespace_declaration + name: (identifier) @name) @definition.namespace +(namespace_declaration + name: (identifier) @name) @definition.namespace + +( + (comment)* @doc + . + (struct_declaration + name: (identifier) @name + body: (declaration_list) @body) @definition.class + (#select-adjacent! @doc @definition.class) +) + +( + (comment)* @doc + . + (record_declaration + name: (identifier) @name + body: (declaration_list)? @body) @definition.class + (#select-adjacent! @doc @definition.class) +) + +( + (comment)* @doc + . + (enum_declaration + name: (identifier) @name + body: (enum_member_declaration_list) @body) @definition.enum + (#select-adjacent! @doc @definition.enum) +) + +( + (comment)* @doc + . + (class_declaration + name: (identifier) @name + body: (declaration_list) @body) @definition.class + (#select-adjacent! @doc @definition.class) +) + +( + (comment)* @doc + . + (operator_declaration + operator: _ @name + body: (_) @body) @definition.method + (#select-adjacent! @doc @definition.method) +) + +( + (comment)* @doc + . + (constructor_declaration + name: (identifier) @name + body: (_) @body) @definition.constructor + (#select-adjacent! @doc @definition.constructor) +) + +( + (comment)* @doc + . + (destructor_declaration + name: (identifier) @name + body: (_) @body) @definition.destructor + (#select-adjacent! @doc @definition.destructor) +) + +( + (comment)* @doc + . + (method_declaration + name: (identifier) @name + body: (_) @body) @definition.method + (#select-adjacent! @doc @definition.method) +) diff --git a/test_files/test.cs b/test_files/test.cs new file mode 100644 index 0000000..28b6b5e --- /dev/null +++ b/test_files/test.cs @@ -0,0 +1,35 @@ +namespace Namespace { + // Comment A. + internal delegate void A(params int[] test); + // Comment F. + public struct F + where T : struct { + } + // Comment F. + [Nice] + private record F + where T1 : I1, I2, new() + where T2 : I2 {} + // Comment Teacher. + record Teacher(string FirstName, string LastName, string Subject) : Person(FirstName, LastName); + // Comment B. + enum B { Ten = 10, Twenty = 20 } + // Comment F. + public class F : object, IAlpha, IOmega {} + // Comment Class. + public partial class Class + where TParam : class ?, notnull, F ? { + // Comment operator +. + public static int operator +(A a) { + return 0; + } + // Comment GetSet. + uint GetSet { get; set; } + // Comment Foo. + static extern Foo() => bar = 0; + // Comment ~Class. + extern ~Class() {} + // Comment Bar + public void Bar() => bar = 0; + } +}