Skip to content

Commit

Permalink
scip-ctags: Fix line number mismatch due to scopes (#62345)
Browse files Browse the repository at this point in the history
Updated the logic in scip-ctags to correctly identify line for class type symbols
  • Loading branch information
mmanela committed May 2, 2024
1 parent 7a30830 commit 4d1c1bd
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
; (import_statement name: (_) @descriptor.term)
; (import_from_statement name: (_) @descriptor.term)

(class_definition name: (_) @descriptor.type @kind.class body: (_) @scope)
(class_definition name: (_) @descriptor.type @kind.class body: (_) ) @scope
(class_definition
body: (block
[(function_definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a> Reply<'a> {
name,
path,
language,
line: scope.scope_range.start_line as usize + 1,
line: scope.ident_range.start_line as usize + 1,
kind: descriptors_to_kind(&scope.descriptors, &scope.kind),
scope: tag_scope,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ mod test {
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!(
All,
test_tags_typescript,
test_scip_typescript,
"globals.ts"
);
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 @@ -45,7 +45,7 @@ expression: dumped
public struct Coords
// ^^^^^^ definition(Struct) scip-ctags `Longer.Namespace`/Class#Coords#
{
public Coords(double x, double y)
public Coords(double x, [Flags] double y)
// ^^^^^^ definition(Constructor) scip-ctags `Longer.Namespace`/Class#Coords#Coords().
{
X = x;
Expand All @@ -54,6 +54,9 @@ expression: dumped

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


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

Expand Down Expand Up @@ -109,21 +112,25 @@ expression: dumped
// ^^^^^^^^^^^ definition(EnumMember) scip-ctags `Longer.Namespace`/Class#ZigFeatureSet#FullPackage.
}

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

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


public string Text { get; set; }
// ^^^^ definition(Property) scip-ctags OneClass/TheClass#Text.
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ expression: dumped
foo = 1; bar = foo
//^^^ definition(Variable) scip-ctags foo.
// ^^^ definition(Variable) scip-ctags bar.

Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
---
source: crates/syntax-analysis/src/lib.rs
expression: "String::from_utf8_lossy(buf_writer.buffer())"
expression: "String::from_utf8_lossy(&output)"
---
{"_type":"tag","name":"Longer.Namespace","path":"globals.cs","language":"c_sharp","line":5,"kind":"namespace","scope":null}
{"_type":"tag","name":"Class","path":"globals.cs","language":"c_sharp","line":7,"kind":"class","scope":"Longer.Namespace"}
{"_type":"tag","name":"Coords","path":"globals.cs","language":"c_sharp","line":34,"kind":"struct","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"ToString","path":"globals.cs","language":"c_sharp","line":45,"kind":"method","scope":"Longer.Namespace.Class.Coords"}
{"_type":"tag","name":"Y","path":"globals.cs","language":"c_sharp","line":43,"kind":"property","scope":"Longer.Namespace.Class.Coords"}
{"_type":"tag","name":"ToString","path":"globals.cs","language":"c_sharp","line":48,"kind":"method","scope":"Longer.Namespace.Class.Coords"}
{"_type":"tag","name":"Y","path":"globals.cs","language":"c_sharp","line":46,"kind":"property","scope":"Longer.Namespace.Class.Coords"}
{"_type":"tag","name":"X","path":"globals.cs","language":"c_sharp","line":42,"kind":"property","scope":"Longer.Namespace.Class.Coords"}
{"_type":"tag","name":"Coords","path":"globals.cs","language":"c_sharp","line":36,"kind":"constructor","scope":"Longer.Namespace.Class.Coords"}
{"_type":"tag","name":"Swag","path":"globals.cs","language":"c_sharp","line":57,"kind":"enum","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"Pants","path":"globals.cs","language":"c_sharp","line":62,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"Socks","path":"globals.cs","language":"c_sharp","line":61,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"Sweater","path":"globals.cs","language":"c_sharp","line":60,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"Shirt","path":"globals.cs","language":"c_sharp","line":59,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"ZigFeatureSet","path":"globals.cs","language":"c_sharp","line":67,"kind":"enum","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"FullPackage","path":"globals.cs","language":"c_sharp","line":75,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"CoolCommunity","path":"globals.cs","language":"c_sharp","line":74,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"BuildSystem","path":"globals.cs","language":"c_sharp","line":73,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"Comptime","path":"globals.cs","language":"c_sharp","line":72,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"Errors","path":"globals.cs","language":"c_sharp","line":71,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"None","path":"globals.cs","language":"c_sharp","line":70,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"Syntax","path":"globals.cs","language":"c_sharp","line":78,"kind":"method","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"SourcegraphSwag","path":"globals.cs","language":"c_sharp","line":65,"kind":"field","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"LambdaFunction","path":"globals.cs","language":"c_sharp","line":55,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"PublicImplicitGetterSetter","path":"globals.cs","language":"c_sharp","line":53,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"_speed","path":"globals.cs","language":"c_sharp","line":52,"kind":"field","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"Changed","path":"globals.cs","language":"c_sharp","line":50,"kind":"event","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"MyDelegate","path":"globals.cs","language":"c_sharp","line":48,"kind":"delegate","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"Swag","path":"globals.cs","language":"c_sharp","line":60,"kind":"enum","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"Pants","path":"globals.cs","language":"c_sharp","line":65,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"Socks","path":"globals.cs","language":"c_sharp","line":64,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"Sweater","path":"globals.cs","language":"c_sharp","line":63,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"Shirt","path":"globals.cs","language":"c_sharp","line":62,"kind":"enumMember","scope":"Longer.Namespace.Class.Swag"}
{"_type":"tag","name":"ZigFeatureSet","path":"globals.cs","language":"c_sharp","line":71,"kind":"enum","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"FullPackage","path":"globals.cs","language":"c_sharp","line":78,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"CoolCommunity","path":"globals.cs","language":"c_sharp","line":77,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"BuildSystem","path":"globals.cs","language":"c_sharp","line":76,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"Comptime","path":"globals.cs","language":"c_sharp","line":75,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"Errors","path":"globals.cs","language":"c_sharp","line":74,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"None","path":"globals.cs","language":"c_sharp","line":73,"kind":"enumMember","scope":"Longer.Namespace.Class.ZigFeatureSet"}
{"_type":"tag","name":"Syntax","path":"globals.cs","language":"c_sharp","line":82,"kind":"method","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"SourcegraphSwag","path":"globals.cs","language":"c_sharp","line":68,"kind":"field","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"LambdaFunction","path":"globals.cs","language":"c_sharp","line":58,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"PublicImplicitGetterSetter","path":"globals.cs","language":"c_sharp","line":56,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"_speed","path":"globals.cs","language":"c_sharp","line":55,"kind":"field","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"Changed","path":"globals.cs","language":"c_sharp","line":53,"kind":"event","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"MyDelegate","path":"globals.cs","language":"c_sharp","line":51,"kind":"delegate","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"ImplicitGetterPrivateSetter","path":"globals.cs","language":"c_sharp","line":28,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"ImplicitGetterSetter","path":"globals.cs","language":"c_sharp","line":22,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"_val","path":"globals.cs","language":"c_sharp","line":20,"kind":"field","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"ExplicitGetterSetter","path":"globals.cs","language":"c_sharp","line":9,"kind":"property","scope":"Longer.Namespace.Class"}
{"_type":"tag","name":"OneClass","path":"globals.cs","language":"c_sharp","line":82,"kind":"namespace","scope":null}
{"_type":"tag","name":"TheClass","path":"globals.cs","language":"c_sharp","line":84,"kind":"class","scope":"OneClass"}
{"_type":"tag","name":"Text","path":"globals.cs","language":"c_sharp","line":87,"kind":"property","scope":"OneClass.TheClass"}
{"_type":"tag","name":"ClickAction","path":"globals.cs","language":"c_sharp","line":86,"kind":"property","scope":"OneClass.TheClass"}
{"_type":"tag","name":"OneClass","path":"globals.cs","language":"c_sharp","line":86,"kind":"namespace","scope":null}
{"_type":"tag","name":"TheClass","path":"globals.cs","language":"c_sharp","line":89,"kind":"class","scope":"OneClass"}
{"_type":"tag","name":"Text","path":"globals.cs","language":"c_sharp","line":95,"kind":"property","scope":"OneClass.TheClass"}
{"_type":"tag","name":"ClickAction","path":"globals.cs","language":"c_sharp","line":92,"kind":"property","scope":"OneClass.TheClass"}
{"_type":"tag","name":"SurprisinglyValid","path":"globals.cs","language":"c_sharp","line":3,"kind":"function","scope":null}

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
source: crates/syntax-analysis/src/lib.rs
expression: "String::from_utf8_lossy(buf_writer.buffer())"
expression: "String::from_utf8_lossy(&output)"
---
{"_type":"tag","name":"Bruh","path":"globals.py","language":"python","line":6,"kind":"class","scope":null}
{"_type":"tag","name":"Bruh","path":"globals.py","language":"python","line":5,"kind":"class","scope":null}
{"_type":"tag","name":"dab","path":"globals.py","language":"python","line":11,"kind":"method","scope":"Bruh"}
{"_type":"tag","name":"__init__","path":"globals.py","language":"python","line":8,"kind":"method","scope":"Bruh"}
{"_type":"tag","name":"a","path":"globals.py","language":"python","line":6,"kind":"variable","scope":"Bruh"}
{"_type":"tag","name":"SomeAsyncStuffs","path":"globals.py","language":"python","line":37,"kind":"class","scope":null}
{"_type":"tag","name":"SomeAsyncStuffs","path":"globals.py","language":"python","line":36,"kind":"class","scope":null}
{"_type":"tag","name":"__anext__","path":"globals.py","language":"python","line":43,"kind":"method","scope":"SomeAsyncStuffs"}
{"_type":"tag","name":"__aiter__","path":"globals.py","language":"python","line":40,"kind":"method","scope":"SomeAsyncStuffs"}
{"_type":"tag","name":"__init__","path":"globals.py","language":"python","line":37,"kind":"method","scope":"SomeAsyncStuffs"}
{"_type":"tag","name":"ClassWithDecorators","path":"globals.py","language":"python","line":61,"kind":"class","scope":null}
{"_type":"tag","name":"ClassWithDecorators","path":"globals.py","language":"python","line":60,"kind":"class","scope":null}
{"_type":"tag","name":"prints_something","path":"globals.py","language":"python","line":73,"kind":"method","scope":"ClassWithDecorators"}
{"_type":"tag","name":"class_method","path":"globals.py","language":"python","line":66,"kind":"method","scope":"ClassWithDecorators"}
{"_type":"tag","name":"static_method","path":"globals.py","language":"python","line":62,"kind":"method","scope":"ClassWithDecorators"}
Expand All @@ -26,4 +26,3 @@ expression: "String::from_utf8_lossy(buf_writer.buffer())"
{"_type":"tag","name":"my_function","path":"globals.py","language":"python","line":32,"kind":"function","scope":null}
{"_type":"tag","name":"should_show_ifs","path":"globals.py","language":"python","line":19,"kind":"variable","scope":null}
{"_type":"tag","name":"bruh","path":"globals.py","language":"python","line":3,"kind":"variable","scope":null}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/syntax-analysis/src/lib.rs
expression: "String::from_utf8_lossy(&output)"
---
{"_type":"tag","name":"MyClass","path":"globals.ts","language":"typescript","line":1,"kind":"class","scope":null}
{"_type":"tag","name":"also_private_method","path":"globals.ts","language":"typescript","line":8,"kind":"method","scope":"MyClass"}
{"_type":"tag","name":"#private_method","path":"globals.ts","language":"typescript","line":7,"kind":"method","scope":"MyClass"}
{"_type":"tag","name":"public_method","path":"globals.ts","language":"typescript","line":6,"kind":"method","scope":"MyClass"}
{"_type":"tag","name":"also_private_field","path":"globals.ts","language":"typescript","line":4,"kind":"property","scope":"MyClass"}
{"_type":"tag","name":"#private_field","path":"globals.ts","language":"typescript","line":3,"kind":"property","scope":"MyClass"}
{"_type":"tag","name":"public_field","path":"globals.ts","language":"typescript","line":2,"kind":"property","scope":"MyClass"}
{"_type":"tag","name":"MyInterface","path":"globals.ts","language":"typescript","line":11,"kind":"interface","scope":null}
{"_type":"tag","name":"sayBruh","path":"globals.ts","language":"typescript","line":13,"kind":"method","scope":"MyInterface"}
{"_type":"tag","name":"bruh","path":"globals.ts","language":"typescript","line":12,"kind":"property","scope":"MyInterface"}
{"_type":"tag","name":"MyEnum","path":"globals.ts","language":"typescript","line":16,"kind":"enum","scope":null}
{"_type":"tag","name":"go","path":"globals.ts","language":"typescript","line":19,"kind":"property","scope":"MyEnum"}
{"_type":"tag","name":"rust","path":"globals.ts","language":"typescript","line":18,"kind":"property","scope":"MyEnum"}
{"_type":"tag","name":"zig","path":"globals.ts","language":"typescript","line":17,"kind":"property","scope":"MyEnum"}
{"_type":"tag","name":"global1","path":"globals.ts","language":"typescript","line":22,"kind":"variable","scope":null}
{"_type":"tag","name":"global2","path":"globals.ts","language":"typescript","line":23,"kind":"variable","scope":null}
{"_type":"tag","name":"myObject","path":"globals.ts","language":"typescript","line":35,"kind":"variable","scope":null}
{"_type":"tag","name":"myArrow","path":"globals.ts","language":"typescript","line":39,"kind":"function","scope":"myObject"}
{"_type":"tag","name":"myMethod","path":"globals.ts","language":"typescript","line":38,"kind":"function","scope":"myObject"}
{"_type":"tag","name":"myProperty","path":"globals.ts","language":"typescript","line":36,"kind":"property","scope":"myObject"}
{"_type":"tag","name":"func","path":"globals.ts","language":"typescript","line":25,"kind":"function","scope":null}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ internal int ImplicitGetterPrivateSetter

public struct Coords
{
public Coords(double x, double y)
public Coords(double x, [Flags] double y)
{
X = x;
Y = y;
}

public double X { get; }


[Flags]
public double Y { get; }

public override string ToString() => $"({X}, {Y})";
Expand Down Expand Up @@ -75,15 +78,20 @@ public enum ZigFeatureSet
FullPackage = Errors | Comptime | BuildSystem | CoolCommunity
}

public static void Syntax() {}
[Flags]
public static void Syntax() { }
}
}

namespace OneClass
{
[Flags]
public class TheClass
{
[Flags]
public Clickable ClickAction { get; set; }


public string Text { get; set; }
}
}

0 comments on commit 4d1c1bd

Please sign in to comment.