Skip to content

Commit d44ea99

Browse files
sagi1623olafurpg
authored andcommitted
Make Parameters and TypeParameters local (#38)
This PR is a follow up to the discussion we had [here](#37 (comment)). I also have a bunch of questions that popped up while I was creating this PR. I hope you can help me answering them. - Should type parameters be local? - Type parameters are not local in java, see [test case](https://github.com/sourcegraph/scip-java/blob/5028089e21c0484fa4c26e38179e82e8dd7dcad8/tests/snapshots/src/main/generated/com/airbnb/epoxy/BaseEpoxyTouchCallback.java#L8). - They are not local for typescript either. ([test case](https://github.com/sourcegraph/scip-typescript/blob/05e74c4b750990cf7868338500becce33a7997a0/snapshots/output/syntax/src/type-parameter.ts#L1)) - In clang indexer the type parameters are local ([test case](https://github.com/sourcegraph/scip-clang/blob/a3f9908d6b79fc5e7b1fb5462653ac1e171d512d/test/index/types/bad_tagdecl.snapshot.cc#L13)) - In go they are local too ([test case](https://github.com/sourcegraph/scip-go/blob/263821315ff57f8fd38c26d946cc302ed5a89ac7/internal/testdata/snapshots/output/inlinestruct/inlinestruct_genericindex.go#L4)) - For python I cannot see any tests with TypeVar - Should parameters be local? - In java they are ([test case](https://github.com/sourcegraph/scip-java/blob/5028089e21c0484fa4c26e38179e82e8dd7dcad8/tests/snapshots/src/main/generated/com/airbnb/epoxy/BaseEpoxyAdapter.java#L186)) - For Clang they are not ([test case](https://github.com/sourcegraph/scip-clang/blob/a3f9908d6b79fc5e7b1fb5462653ac1e171d512d/test/index/functions/methods.snapshot.cc#L114)) - For go they are not ([test case](https://github.com/sourcegraph/scip-go/blob/263821315ff57f8fd38c26d946cc302ed5a89ac7/internal/testdata/snapshots/output/inlinestruct/inlinestruct_genericindex.go#L28)) - For typescript they are not ([test case](https://github.com/sourcegraph/scip-typescript/blob/05e74c4b750990cf7868338500becce33a7997a0/snapshots/output/syntax/src/type-parameter.ts#L1)) - For python they are not ([test case](https://github.com/sourcegraph/scip-python/blob/8a21e88ad5da866f6c345af08d95669910968ef6/packages/pyright-scip/snapshots/output/single_function/src/single_function.py#L26)) Also if making a symbol local helps with search because it does not go outside of the document to look for it, would it make sense to make all types/members local that are not visible outside of the document. Examples for C#: - private nested types - private members (fields, properties, methods, etc.) - file scoped types (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/file) In general this could be applied to all languages that have the concept of access modifiers (java, c++, etc.). My only concern here is, if for example methods will be indexed as local, will they still show up correctly in the UI as methods or will they look like local variables? I have one last question that is not related to global vs local symbols. While I was playing around with the C# implementation I realized that the support for [partial classes and methods](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods) is not correct. For example both parts of a partial class declaration will create the same symbol definition, if I add a UT test case it will fail, however if users run the indexer it will not fail but generate two symbol definitions. Do you know how this will affect the products consuming the indexes?
1 parent 1095448 commit d44ea99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1129
-1127
lines changed

ScipDotnet/ScipDocumentIndexer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,12 @@ private static bool IsLocalSymbol(ISymbol sym)
368368
{
369369
return sym.Kind == SymbolKind.Local ||
370370
sym.Kind == SymbolKind.RangeVariable ||
371+
sym.Kind == SymbolKind.Parameter ||
372+
sym.Kind == SymbolKind.TypeParameter ||
373+
sym is IMethodSymbol { MethodKind: MethodKind.LocalFunction } ||
371374
// Anonymous classes/methods have empty names and can not be accessed outside their file.
372375
// The "global namespace" (parent of all namespaces) also has an empty name and should not
373376
// be treated as a local variable.
374-
sym is IMethodSymbol { MethodKind: MethodKind.LocalFunction } ||
375377
(sym.Name.Equals("") && sym.Kind != SymbolKind.Namespace);
376378
}
377379
}

snapshots/output-net6.0/syntax/Main/Classes.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Classes
2121
public Classes(int name)
2222
// ^^^^^^^ definition scip-dotnet nuget . . Main/Classes#`.ctor`().
2323
// documentation ```cs\npublic Classes.Classes(int name)\n```
24-
// ^^^^ definition scip-dotnet nuget . . Main/Classes#`.ctor`().(name)
24+
// ^^^^ definition local 0
2525
// documentation ```cs\nint name\n```
2626
{
2727
Name = "name";
@@ -31,10 +31,10 @@ public Classes(int name)
3131
public Classes(string name) => Name = name;
3232
// ^^^^^^^ definition scip-dotnet nuget . . Main/Classes#`.ctor`(+1).
3333
// documentation ```cs\npublic Classes.Classes(string name)\n```
34-
// ^^^^ definition scip-dotnet nuget . . Main/Classes#`.ctor`(+1).(name)
34+
// ^^^^ definition local 1
3535
// documentation ```cs\nstring name\n```
3636
// ^^^^ reference scip-dotnet nuget . . Main/Classes#Name.
37-
// ^^^^ reference scip-dotnet nuget . . Main/Classes#`.ctor`(+1).(name)
37+
// ^^^^ reference local 1
3838

3939
~Classes()
4040
// ^^^^^^^ definition scip-dotnet nuget . . Main/Classes#Finalize().
@@ -60,117 +60,117 @@ public partial class PartialClass
6060
class TypeParameterClass<T>
6161
// ^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#TypeParameterClass#
6262
// documentation ```cs\nclass TypeParameterClass<T>\n```
63-
// ^ definition scip-dotnet nuget . . Main/Classes#TypeParameterClass#[T]
63+
// ^ definition local 2
6464
// documentation ```cs\nT\n```
6565
{
6666
}
6767

6868
internal class InternalMultipleTypeParametersClass<T1, T2>
6969
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#InternalMultipleTypeParametersClass#
7070
// documentation ```cs\nclass InternalMultipleTypeParametersClass<T1, T2>\n```
71-
// ^^ definition scip-dotnet nuget . . Main/Classes#InternalMultipleTypeParametersClass#[T1]
71+
// ^^ definition local 3
7272
// documentation ```cs\nT1\n```
73-
// ^^ definition scip-dotnet nuget . . Main/Classes#InternalMultipleTypeParametersClass#[T2]
73+
// ^^ definition local 4
7474
// documentation ```cs\nT2\n```
7575
{
7676
}
7777

7878
interface ICovariantContravariant<in T1, out T2>
7979
// ^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#ICovariantContravariant#
8080
// documentation ```cs\ninterface ICovariantContravariant<in T1, out T2>\n```
81-
// ^^ definition scip-dotnet nuget . . Main/Classes#ICovariantContravariant#[T1]
81+
// ^^ definition local 5
8282
// documentation ```cs\nin T1\n```
83-
// ^^ definition scip-dotnet nuget . . Main/Classes#ICovariantContravariant#[T2]
83+
// ^^ definition local 6
8484
// documentation ```cs\nout T2\n```
8585
{
8686
public void Method1(T1 t1)
8787
// ^^^^^^^ definition scip-dotnet nuget . . Main/Classes#ICovariantContravariant#Method1().
8888
// documentation ```cs\nvoid ICovariantContravariant<in T1, out T2>.Method1(T1 t1)\n```
89-
// ^^ reference scip-dotnet nuget . . Main/Classes#ICovariantContravariant#[T1]
90-
// ^^ definition scip-dotnet nuget . . Main/Classes#ICovariantContravariant#Method1().(t1)
89+
// ^^ reference local 5
90+
// ^^ definition local 7
9191
// documentation ```cs\nT1 t1\n```
9292
{
9393
Console.WriteLine(t1);
94-
// ^^ reference scip-dotnet nuget . . Main/Classes#ICovariantContravariant#Method1().(t1)
94+
// ^^ reference local 7
9595
}
9696

9797
public T2? Method2()
98-
// ^^ reference scip-dotnet nuget . . Main/Classes#ICovariantContravariant#[T2]
98+
// ^^ reference local 6
9999
// ^^^^^^^ definition scip-dotnet nuget . . Main/Classes#ICovariantContravariant#Method2().
100100
// documentation ```cs\nT2? ICovariantContravariant<in T1, out T2>.Method2()\n```
101101
{
102102
return default(T2);
103-
// ^^ reference scip-dotnet nuget . . Main/Classes#ICovariantContravariant#[T2]
103+
// ^^ reference local 6
104104
}
105105
}
106106

107107
public class StructConstraintClass<T> where T : struct
108108
// ^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#StructConstraintClass#
109109
// documentation ```cs\nclass StructConstraintClass<T> where T : struct\n```
110-
// ^ definition scip-dotnet nuget . . Main/Classes#StructConstraintClass#[T]
110+
// ^ definition local 8
111111
// documentation ```cs\nT\n```
112-
// ^ reference scip-dotnet nuget . . Main/Classes#StructConstraintClass#[T]
112+
// ^ reference local 8
113113
{
114114
}
115115

116116
public class UnmanagedConstraintClass<T> where T : unmanaged
117117
// ^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#UnmanagedConstraintClass#
118118
// documentation ```cs\nclass UnmanagedConstraintClass<T> where T : unmanaged\n```
119-
// ^ definition scip-dotnet nuget . . Main/Classes#UnmanagedConstraintClass#[T]
119+
// ^ definition local 9
120120
// documentation ```cs\nT\n```
121-
// ^ reference scip-dotnet nuget . . Main/Classes#UnmanagedConstraintClass#[T]
121+
// ^ reference local 9
122122
{
123123
}
124124

125125
public class ClassConstraintClass<T> where T : class
126126
// ^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#ClassConstraintClass#
127127
// documentation ```cs\nclass ClassConstraintClass<T> where T : class\n```
128-
// ^ definition scip-dotnet nuget . . Main/Classes#ClassConstraintClass#[T]
128+
// ^ definition local 10
129129
// documentation ```cs\nT\n```
130-
// ^ reference scip-dotnet nuget . . Main/Classes#ClassConstraintClass#[T]
130+
// ^ reference local 10
131131
{
132132
}
133133

134134
public class NonNullableConstraintClass<T> where T : notnull
135135
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#NonNullableConstraintClass#
136136
// documentation ```cs\nclass NonNullableConstraintClass<T> where T : notnull\n```
137-
// ^ definition scip-dotnet nuget . . Main/Classes#NonNullableConstraintClass#[T]
137+
// ^ definition local 11
138138
// documentation ```cs\nT\n```
139-
// ^ reference scip-dotnet nuget . . Main/Classes#NonNullableConstraintClass#[T]
139+
// ^ reference local 11
140140
{
141141
}
142142

143143
public class NewConstraintClass<T> where T : new()
144144
// ^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#NewConstraintClass#
145145
// documentation ```cs\nclass NewConstraintClass<T> where T : new()\n```
146-
// ^ definition scip-dotnet nuget . . Main/Classes#NewConstraintClass#[T]
146+
// ^ definition local 12
147147
// documentation ```cs\nT\n```
148-
// ^ reference scip-dotnet nuget . . Main/Classes#NewConstraintClass#[T]
148+
// ^ reference local 12
149149
{
150150
}
151151

152152
public class TypeParameterConstraintClass<T> where T : SomeInterface
153153
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#TypeParameterConstraintClass#
154154
// documentation ```cs\nclass TypeParameterConstraintClass<T> where T : SomeInterface\n```
155-
// ^ definition scip-dotnet nuget . . Main/Classes#TypeParameterConstraintClass#[T]
155+
// ^ definition local 13
156156
// documentation ```cs\nT\n```
157-
// ^ reference scip-dotnet nuget . . Main/Classes#TypeParameterConstraintClass#[T]
157+
// ^ reference local 13
158158
// ^^^^^^^^^^^^^ reference scip-dotnet nuget . . Main/SomeInterface#
159159
{
160160
}
161161

162162
private class MultipleTypeParameterConstraintsClass<T1, T2> where T1 : SomeInterface, SomeInterface2, new()
163163
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/Classes#MultipleTypeParameterConstraintsClass#
164164
// documentation ```cs\nclass MultipleTypeParameterConstraintsClass<T1, T2> where T1 : SomeInterface, SomeInterface2, new() where T2 : SomeInterface2\n```
165-
// ^^ definition scip-dotnet nuget . . Main/Classes#MultipleTypeParameterConstraintsClass#[T1]
165+
// ^^ definition local 14
166166
// documentation ```cs\nT1\n```
167-
// ^^ definition scip-dotnet nuget . . Main/Classes#MultipleTypeParameterConstraintsClass#[T2]
167+
// ^^ definition local 15
168168
// documentation ```cs\nT2\n```
169-
// ^^ reference scip-dotnet nuget . . Main/Classes#MultipleTypeParameterConstraintsClass#[T1]
169+
// ^^ reference local 14
170170
// ^^^^^^^^^^^^^ reference scip-dotnet nuget . . Main/SomeInterface#
171171
// ^^^^^^^^^^^^^^ reference scip-dotnet nuget . . Main/SomeInterface2#
172172
where T2 : SomeInterface2
173-
// ^^ reference scip-dotnet nuget . . Main/Classes#MultipleTypeParameterConstraintsClass#[T2]
173+
// ^^ reference local 15
174174
// ^^^^^^^^^^^^^^ reference scip-dotnet nuget . . Main/SomeInterface2#
175175
{
176176
}
@@ -184,14 +184,14 @@ class IndexClass
184184
// documentation ```cs\nprivate bool IndexClass.a\n```
185185

186186
public bool this[int index]
187-
// ^^^^^ definition scip-dotnet nuget . . Main/Classes#IndexClass#`this[]`.(index)
187+
// ^^^^^ definition local 16
188188
// documentation ```cs\nint index\n```
189189
{
190190
get { return a; }
191191
// ^ reference scip-dotnet nuget . . Main/Classes#IndexClass#a.
192192
set { a = value; }
193193
// ^ reference scip-dotnet nuget . . Main/Classes#IndexClass#a.
194-
// ^^^^^ reference scip-dotnet nuget . . Main/Classes#IndexClass#set_Item().(value)
194+
// ^^^^^ reference local 17
195195
}
196196
}
197197

0 commit comments

Comments
 (0)