Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

SCIP ctags: add kinds for C#, Python, Ruby #57879

Merged
merged 12 commits into from
Oct 26, 2023
Merged
29 changes: 13 additions & 16 deletions docker-images/syntax-highlighter/Cargo.Bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions docker-images/syntax-highlighter/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker-images/syntax-highlighter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tree-sitter = "0.20.9"
tree-sitter-highlight = "0.20.1"

# Since there is no version tag, we pin the dependency to a specific revision
scip = { git = "https://github.com/sourcegraph/scip", rev="1bf111e1cf175569970e95566b379fb2a548d70a" }
scip = "0.3.1"
protobuf = "3"


Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
(using_directive (qualified_name) @descriptor.type)

(class_declaration name: (_) @descriptor.type) @scope
(interface_declaration name: (_) @descriptor.type) @scope
(enum_declaration name: (_) @descriptor.type) @scope
(struct_declaration name: (_) @descriptor.type) @scope
(namespace_declaration name: (_) @descriptor.namespace) @scope
(class_declaration name: (_) @descriptor.type @kind.class) @scope
(interface_declaration name: (_) @descriptor.type @kind.interface) @scope
(enum_declaration name: (_) @descriptor.type @kind.enum) @scope
(struct_declaration name: (_) @descriptor.type @kind.struct) @scope
(namespace_declaration name: (_) @descriptor.namespace @kind.namespace) @scope

; Counter-intuitive name; it can actually be global
(local_function_statement name: (_) @descriptor.method)
(method_declaration name: (_) @descriptor.method)
(constructor_declaration name: (_) @descriptor.method)
(local_function_statement name: (_) @descriptor.method @kind.function)
(method_declaration name: (_) @descriptor.method @kind.method)
(constructor_declaration name: (_) @descriptor.method @kind.constructor)

(block) @local

(field_declaration (variable_declaration (variable_declarator (identifier) @descriptor.term)))
(event_field_declaration (variable_declaration (variable_declarator (identifier) @descriptor.term)))
(property_declaration name: (identifier) @descriptor.term)
(enum_member_declaration name: (_) @descriptor.term)
(delegate_declaration name: (identifier) @descriptor.method)
(field_declaration (variable_declaration (variable_declarator (identifier) @descriptor.term @kind.field)))
(event_field_declaration (variable_declaration (variable_declarator (identifier) @kind.event @descriptor.term)))
(property_declaration name: (identifier) @descriptor.term @kind.property)
(enum_member_declaration name: (_) @descriptor.term @kind.enummember)
(delegate_declaration name: (identifier) @descriptor.method @kind.delegate)
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@
; (import_statement name: (_) @descriptor.term)
; (import_from_statement name: (_) @descriptor.term)

(class_definition name: (_) @descriptor.type body: (_) @scope)
(class_definition name: (_) @descriptor.type @kind.class body: (_) @scope)
(class_definition
body: (block
[(function_definition
name: (_) @descriptor.method @kind.field
name: (_) @descriptor.method @kind.method
body: (_) @local)
(decorated_definition
definition: (function_definition
name: (_) @descriptor.method @kind.field
name: (_) @descriptor.method @kind.method
body: (_) @local))]))


(module (function_definition name: (_) @descriptor.method body: (_) @local))
(module (decorated_definition (function_definition name: (_) @descriptor.method body: (_) @local)))
(module (function_definition name: (_) @descriptor.method @kind.function body: (_) @local))
(module (decorated_definition (function_definition name: (_) @descriptor.method @kind.function body: (_) @local)))

;; foo = 1
(expression_statement (assignment left: (identifier) @descriptor.term))
(expression_statement (assignment left: (identifier) @descriptor.term @kind.variable))

;; foo, bar, baz = 1, 2, 3
(expression_statement (assignment left: (pattern_list (identifier) @descriptor.term)))
(expression_statement (assignment left: (pattern_list (identifier) @descriptor.term @kind.variable)))
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
(assignment left: [(identifier) (constant)] @descriptor.term)
(class name: (_) @descriptor.type) @scope
(method name: (_) @descriptor.method) @local
(module name: (_) @descriptor.namespace @kind.module) @scope

(singleton_method name: (_) @descriptor.method) @local
(assignment left: (identifier) @descriptor.term @kind.variable)
(assignment left: (constant) @descriptor.term @kind.constant)
(class name: (_) @descriptor.type @kind.class) @scope
(method name: (_) @descriptor.method @kind.method) @local

(singleton_method name: (_) @descriptor.method @kind.singletonmethod) @local
[(do_block) (block) (unless) (case) (begin) (if) (while) (for)] @local

;; attr_accessor :bar -> bar, bar=
((call
method: (identifier) @_attr_accessor
arguments: (argument_list (simple_symbol) @descriptor.method))
arguments: (argument_list (simple_symbol) @descriptor.method @kind.accessor))
(#eq? @_attr_accessor "attr_accessor")
(#transform! ":(.*)" "$1")
(#transform! ":(.*)" "$1="))

((call
method: (identifier) @_attr_reader
arguments: (argument_list (simple_symbol) @descriptor.method))
arguments: (argument_list (simple_symbol) @descriptor.method @kind.getter))
(#eq? @_attr_reader "attr_reader")
(#transform! ":(.*)" "$1"))

((call
method: (identifier) @_attr_writer
arguments: (argument_list (simple_symbol) @descriptor.method))
arguments: (argument_list (simple_symbol) @descriptor.method @kind.setter))
(#eq? @_attr_writer "attr_writer")
(#transform! ":(.*)" "$1="))

Expand All @@ -30,7 +33,7 @@
method: (identifier) @_alias_method
arguments: (argument_list
.
(simple_symbol) @descriptor.method))
(simple_symbol) @descriptor.method @kind.methodalias))

(#eq? @_alias_method "alias_method")
(#transform! ":(.*)" "$1"))
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ mod test {

// But most tests should go here and just generate scip snapshots
generate_tags_and_snapshot!(Scip, test_scip_zig, "globals.zig");
generate_tags_and_snapshot!(Scip, test_scip_python, "globals.py");
generate_tags_and_snapshot!(All, test_tags_python, test_scip_python, "globals.py");
generate_tags_and_snapshot!(Scip, test_scip_python_comp, "python-repo-comp.py");
generate_tags_and_snapshot!(All, test_tags_ruby, test_scip_ruby, "ruby-globals.rb");
generate_tags_and_snapshot!(Scip, test_scip_java, "globals.java");
generate_tags_and_snapshot!(Scip, test_scip_typescript, "globals.ts");
generate_tags_and_snapshot!(Scip, test_scip_csharp, "globals.cs");
generate_tags_and_snapshot!(All, test_tags_csharp, test_scip_csharp, "globals.cs");
generate_tags_and_snapshot!(Scip, test_scip_scala, "globals.scala");
generate_tags_and_snapshot!(All, test_tags_kotlin, test_scip_kotlin, "globals.kt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ source: crates/scip-syntax/src/lib.rs
expression: dumped
---
using System.Collections.Generic;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-ctags `System.Collections.Generic`#

public void SurprisinglyValid(string firstParam) { }
// ^^^^^^^^^^^^^^^^^ definition scip-ctags SurprisinglyValid().
// ^^^^^^^^^^^^^^^^^ definition(Function) scip-ctags SurprisinglyValid().

namespace Longer.Namespace
// ^^^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/
// ^^^^^^^^^^^^^^^^ definition(Namespace) scip-ctags `Longer.Namespace`/
{
public class Class
// ^^^^^ definition scip-ctags `Longer.Namespace`/Class#
// ^^^^^ definition(Class) scip-ctags `Longer.Namespace`/Class#
{
public int ExplicitGetterSetter
// ^^^^^^^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ExplicitGetterSetter.
// ^^^^^^^^^^^^^^^^^^^^ definition(Property) scip-ctags `Longer.Namespace`/Class#ExplicitGetterSetter.
{
get
{
Expand All @@ -27,104 +26,104 @@ expression: dumped
}
}
private int _val;
// ^^^^ definition scip-ctags `Longer.Namespace`/Class#_val.
// ^^^^ definition(Field) scip-ctags `Longer.Namespace`/Class#_val.

protected virtual int ImplicitGetterSetter
// ^^^^^^^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ImplicitGetterSetter.
// ^^^^^^^^^^^^^^^^^^^^ definition(Property) scip-ctags `Longer.Namespace`/Class#ImplicitGetterSetter.
{
get;
set;
}

internal int ImplicitGetterPrivateSetter
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ImplicitGetterPrivateSetter.
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition(Property) scip-ctags `Longer.Namespace`/Class#ImplicitGetterPrivateSetter.
{
get;
private set;
}

public struct Coords
// ^^^^^^ definition scip-ctags `Longer.Namespace`/Class#Coords#
// ^^^^^^ definition(Struct) scip-ctags `Longer.Namespace`/Class#Coords#
{
public Coords(double x, double y)
// ^^^^^^ definition scip-ctags `Longer.Namespace`/Class#Coords#Coords().
// ^^^^^^ definition(Constructor) scip-ctags `Longer.Namespace`/Class#Coords#Coords().
{
X = x;
Y = y;
}

public double X { get; }
// ^ definition scip-ctags `Longer.Namespace`/Class#Coords#X.
// ^ definition(Property) scip-ctags `Longer.Namespace`/Class#Coords#X.
public double Y { get; }
// ^ definition scip-ctags `Longer.Namespace`/Class#Coords#Y.
// ^ definition(Property) scip-ctags `Longer.Namespace`/Class#Coords#Y.

public override string ToString() => $"({X}, {Y})";
// ^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#Coords#ToString().
// ^^^^^^^^ definition(Method) scip-ctags `Longer.Namespace`/Class#Coords#ToString().
}

delegate int MyDelegate();
// ^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#MyDelegate().
// ^^^^^^^^^^ definition(Delegate) scip-ctags `Longer.Namespace`/Class#MyDelegate().

public event ChangedEventHandler Changed;
// ^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#Changed.
// ^^^^^^^ definition(Event) scip-ctags `Longer.Namespace`/Class#Changed.

int _speed;
// ^^^^^^ definition scip-ctags `Longer.Namespace`/Class#_speed.
// ^^^^^^ definition(Field) scip-ctags `Longer.Namespace`/Class#_speed.
public string PublicImplicitGetterSetter { get; set; }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#PublicImplicitGetterSetter.
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition(Property) scip-ctags `Longer.Namespace`/Class#PublicImplicitGetterSetter.

public string LambdaFunction => PublicImplicitGetterSetter + " " + _speed + " speed";
// ^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#LambdaFunction.
// ^^^^^^^^^^^^^^ definition(Property) scip-ctags `Longer.Namespace`/Class#LambdaFunction.
jtibshirani marked this conversation as resolved.
Show resolved Hide resolved

public enum Swag
// ^^^^ definition scip-ctags `Longer.Namespace`/Class#Swag#
// ^^^^ definition(Enum) scip-ctags `Longer.Namespace`/Class#Swag#
{
Shirt,
// ^^^^^ definition scip-ctags `Longer.Namespace`/Class#Swag#Shirt.
// ^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#Swag#Shirt.
Sweater,
// ^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#Swag#Sweater.
// ^^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#Swag#Sweater.
Socks = 42,
// ^^^^^ definition scip-ctags `Longer.Namespace`/Class#Swag#Socks.
// ^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#Swag#Socks.
Pants
// ^^^^^ definition scip-ctags `Longer.Namespace`/Class#Swag#Pants.
// ^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#Swag#Pants.
}

public Swag SourcegraphSwag;
// ^^^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#SourcegraphSwag.
// ^^^^^^^^^^^^^^^ definition(Field) scip-ctags `Longer.Namespace`/Class#SourcegraphSwag.

[Flags]
public enum ZigFeatureSet
// ^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#
// ^^^^^^^^^^^^^ definition(Enum) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#
{
None = 0,
// ^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#None.
// ^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#None.
Errors = 1,
// ^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#Errors.
// ^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#Errors.
Comptime = 2,
// ^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#Comptime.
// ^^^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#Comptime.
BuildSystem = 4,
// ^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#BuildSystem.
// ^^^^^^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#BuildSystem.
CoolCommunity = 8,
// ^^^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#CoolCommunity.
// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#CoolCommunity.
FullPackage = Errors | Comptime | BuildSystem | CoolCommunity
// ^^^^^^^^^^^ definition scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#FullPackage.
// ^^^^^^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#FullPackage.
}

public static void Syntax() {}
// ^^^^^^ definition scip-ctags `Longer.Namespace`/Class#Syntax().
// ^^^^^^ definition(Method) scip-ctags `Longer.Namespace`/Class#Syntax().
}
}

namespace OneClass
// ^^^^^^^^ definition scip-ctags OneClass/
// ^^^^^^^^ definition(Namespace) scip-ctags OneClass/
{
public class TheClass
// ^^^^^^^^ definition scip-ctags OneClass/TheClass#
// ^^^^^^^^ definition(Class) scip-ctags OneClass/TheClass#
{
public Clickable ClickAction { get; set; }
// ^^^^^^^^^^^ definition scip-ctags OneClass/TheClass#ClickAction.
// ^^^^^^^^^^^ definition(Property) scip-ctags OneClass/TheClass#ClickAction.
public string Text { get; set; }
// ^^^^ definition scip-ctags OneClass/TheClass#Text.
// ^^^^ definition(Property) scip-ctags OneClass/TheClass#Text.
}
}

Loading
Loading