Skip to content
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
8 changes: 8 additions & 0 deletions pkg/lang/treesitter/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ var supplementalTagsQueries = map[string]string{
"cpp": strings.Join([]string{
"(namespace_definition name: (namespace_identifier) @name) @definition.module",
}, "\n"),
// gotreesitter's inferred C# tag query indexes interfaces, classes, and
// methods but drops `namespace_declaration` containers, the primary
// container for exported C# APIs. Capture both simple (identifier) and
// qualified namespace names as module definitions without disturbing any
// existing captures.
"c_sharp": strings.Join([]string{
"(namespace_declaration name: [(identifier) (qualified_name)] @name) @definition.module",
}, "\n"),
}

// ResolveTagsQuery returns the tree-sitter tags query canopy should use for a
Expand Down
52 changes: 52 additions & 0 deletions pkg/lang/treesitter/tags_csharp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package treesitter

import "testing"

const csharpNamespaceSample = `namespace Acme.Telemetry
{
public interface IClock
{
void Tick();
}

public class Clock : IClock
{
public void Tick() {}
}
}

namespace Utilities
{
public class Parser {}
}
`

func TestCSharpNamespaceDeclarationsIndexedAsModules(t *testing.T) {
entry := findEntryByExtension(t, ".cs")
parser, err := NewParser(entry)
if err != nil {
t.Fatalf("NewParser: %v", err)
}
summary, err := parser.Parse("sample.cs", []byte(csharpNamespaceSample))
if err != nil {
t.Fatalf("Parse: %v", err)
}

if !hasSymbol(summary, "interface_definition", "IClock") {
t.Error("missing C# interface IClock")
}
for _, cls := range []string{"Clock", "Parser"} {
if !hasSymbol(summary, "class_definition", cls) {
t.Errorf("missing C# class %s", cls)
}
}
if !hasSymbol(summary, "method_definition", "Tick") {
t.Error("missing C# methods Tick")
}
if !hasSymbol(summary, "module_definition", "Acme.Telemetry") {
t.Error("missing C# namespace Acme.Telemetry")
}
if !hasSymbol(summary, "module_definition", "Utilities") {
t.Error("missing C# namespace Utilities")
}
}
Loading