Skip to content

Commit 34600eb

Browse files
authored
Add support for queries in both C# and VbNet (#36)
1 parent 21422e1 commit 34600eb

File tree

9 files changed

+537
-125
lines changed

9 files changed

+537
-125
lines changed

ScipDotnet/ScipCSharpSyntaxWalker.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,34 @@ public override void VisitTypeParameter(TypeParameterSyntax node)
129129
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
130130
base.VisitTypeParameter(node);
131131
}
132+
133+
public override void VisitFromClause(FromClauseSyntax node)
134+
{
135+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
136+
base.VisitFromClause(node);
137+
}
138+
139+
public override void VisitJoinClause(JoinClauseSyntax node)
140+
{
141+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
142+
base.VisitJoinClause(node);
143+
}
144+
145+
public override void VisitJoinIntoClause(JoinIntoClauseSyntax node)
146+
{
147+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
148+
base.VisitJoinIntoClause(node);
149+
}
150+
151+
public override void VisitLetClause(LetClauseSyntax node)
152+
{
153+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
154+
base.VisitLetClause(node);
155+
}
156+
157+
public override void VisitQueryContinuation(QueryContinuationSyntax node)
158+
{
159+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
160+
base.VisitQueryContinuation(node);
161+
}
132162
}

ScipDotnet/ScipDocumentIndexer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ private static IEnumerable<int> LocationToRange(Location location)
367367
private static bool IsLocalSymbol(ISymbol sym)
368368
{
369369
return sym.Kind == SymbolKind.Local ||
370+
sym.Kind == SymbolKind.RangeVariable ||
370371
// Anonymous classes/methods have empty names and can not be accessed outside their file.
371372
// The "global namespace" (parent of all namespaces) also has an empty name and should not
372373
// be treated as a local variable.

ScipDotnet/ScipVisualBasicSyntaxWalker.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,28 @@ public override void VisitTypeParameter(TypeParameterSyntax node)
117117
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
118118
base.VisitTypeParameter(node);
119119
}
120+
121+
public override void VisitExpressionRangeVariable(ExpressionRangeVariableSyntax node)
122+
{
123+
if (node.NameEquals != null)
124+
{
125+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node.NameEquals.Identifier), node.NameEquals.Identifier.GetLocation(), true);
126+
}
127+
base.VisitExpressionRangeVariable(node);
128+
}
129+
130+
public override void VisitAggregationRangeVariable(AggregationRangeVariableSyntax node)
131+
{
132+
if (node.NameEquals != null)
133+
{
134+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node.NameEquals.Identifier), node.NameEquals.Identifier.GetLocation(), true);
135+
}
136+
base.VisitAggregationRangeVariable(node);
137+
}
138+
139+
public override void VisitCollectionRangeVariable(CollectionRangeVariableSyntax node)
140+
{
141+
_scipDocumentIndexer.VisitOccurrence(_semanticModel.GetDeclaredSymbol(node), node.Identifier.GetLocation(), true);
142+
base.VisitCollectionRangeVariable(node);
143+
}
120144
}

snapshots/input/syntax/Main/QuerySyntax.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,29 @@ from b in sourceB
5050
where a.Method() == b.Method()
5151
select new { A = a.Method(), B = b.Method() };
5252
}
53+
54+
void JoinInto(List<Student> students1, List<Student> students2)
55+
{
56+
var innerGroupJoinQuery =
57+
from student1 in students1
58+
join student2 in students2 on student1.ID equals student2.ID into studentGroup
59+
select new { Student = student1.First, Students = studentGroup };
60+
}
61+
62+
void Continuation(List<Student> students)
63+
{
64+
var sortedGroups =
65+
from student in students
66+
orderby student.Last, student.First
67+
group student by student.Last[0] into newGroup
68+
orderby newGroup.Key
69+
select newGroup;
70+
}
71+
72+
private class Student
73+
{
74+
public string First { get; set; }
75+
public string Last { get; set; }
76+
public int ID { get; set; }
77+
}
5378
}

snapshots/input/syntax/VBMain/QuerySyntax.vb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,18 @@ Namespace VBMain
3232
End Sub
3333

3434
Private Sub MultipleFrom()
35-
Dim x = From a In sourceA From b In sourceB Where a.Method() = b.Method() Select New With {Key .A = a.Method(), Key .B = b.Method()}
35+
Dim x = From a In sourceA From b In sourceB Where a.Method() = b.Method() Select c = New With {Key .A = a.Method(), Key .B = b.Method()} Where c.A = String.Empty
3636
End Sub
37+
38+
Private Sub Into(Students As List(Of Student))
39+
Dim sortedGroups = From student In Students Order By student.Last, student.First Group student By student.Last Into newGroup = Group Order By newGroup
40+
End Sub
41+
42+
Private Class Student
43+
Public Property First As String
44+
Public Property Last As String
45+
Public Property ID As Integer
46+
End Class
47+
3748
End Class
3849
End Namespace

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

Lines changed: 125 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,92 +35,187 @@ void Select()
3535
var x = from a in sourceA select a.Method();
3636
// ^ definition local 0
3737
// documentation ```cs\n? x\n```
38+
// ^ definition local 1
39+
// documentation ```cs\n? a\n```
3840
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceA.
39-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Select().a.
41+
// ^ reference local 1
4042
}
4143

4244
void Projection()
4345
// ^^^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Projection().
4446
// documentation ```cs\nprivate void QuerySyntax.Projection()\n```
4547
{
4648
var x = from a in sourceA select new { Name = a.Method() };
47-
// ^ definition local 1
49+
// ^ definition local 2
4850
// documentation ```cs\n? x\n```
51+
// ^ definition local 3
52+
// documentation ```cs\n? a\n```
4953
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceA.
50-
// ^^^^ reference local 3
51-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Projection().a.
54+
// ^^^^ reference local 5
55+
// ^ reference local 3
5256
var b = from a in x select a.Name;
53-
// ^ definition local 4
57+
// ^ definition local 6
5458
// documentation ```cs\n? b\n```
55-
// ^ reference local 1
56-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Projection().a.
59+
// ^ definition local 7
60+
// documentation ```cs\n? a\n```
61+
// ^ reference local 2
62+
// ^ reference local 7
5763
}
5864

5965
void Where()
6066
// ^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Where().
6167
// documentation ```cs\nprivate void QuerySyntax.Where()\n```
6268
{
6369
var x = from a in sourceA where a.Method().StartsWith("a") select a;
64-
// ^ definition local 5
70+
// ^ definition local 8
6571
// documentation ```cs\n? x\n```
72+
// ^ definition local 9
73+
// documentation ```cs\n? a\n```
6674
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceA.
67-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Where().a.
68-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Where().a.
75+
// ^ reference local 9
76+
// ^ reference local 9
6977
}
7078

7179
void Let()
7280
// ^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Let().
7381
// documentation ```cs\nprivate void QuerySyntax.Let()\n```
7482
{
7583
var x = from a in sourceA
76-
// ^ definition local 6
84+
// ^ definition local 10
7785
// documentation ```cs\n? x\n```
86+
// ^ definition local 11
87+
// documentation ```cs\n? a\n```
7888
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceA.
7989
let z = new { A = a.Method(), B = a.Method() }
80-
// ^ reference local 8
81-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Let().a.
82-
// ^ reference local 9
83-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Let().a.
90+
// ^ definition local 12
91+
// documentation ```cs\n? z\n```
92+
// ^ reference local 14
93+
// ^ reference local 11
94+
// ^ reference local 15
95+
// ^ reference local 11
8496
select z;
85-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Let().z.
97+
// ^ reference local 12
8698
}
8799

88100
void Join()
89101
// ^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Join().
90102
// documentation ```cs\nprivate void QuerySyntax.Join()\n```
91103
{
92104
var x = from a in sourceA
93-
// ^ definition local 10
105+
// ^ definition local 16
94106
// documentation ```cs\n? x\n```
107+
// ^ definition local 17
108+
// documentation ```cs\n? a\n```
95109
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceA.
96110
join b in sourceB on a.Method() equals b.Method()
111+
// ^ definition local 18
112+
// documentation ```cs\n? b\n```
97113
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceB.
98-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Join().a.
99-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Join().b.
114+
// ^ reference local 17
115+
// ^ reference local 18
100116
select new { A = a.Method(), B = b.Method() };
101-
// ^ reference local 8
102-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Join().a.
103-
// ^ reference local 9
104-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#Join().b.
117+
// ^ reference local 14
118+
// ^ reference local 17
119+
// ^ reference local 15
120+
// ^ reference local 18
105121
}
106122

107123
void MultipleFrom()
108124
// ^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#MultipleFrom().
109125
// documentation ```cs\nprivate void QuerySyntax.MultipleFrom()\n```
110126
{
111127
var x = from a in sourceA
112-
// ^ definition local 11
128+
// ^ definition local 19
113129
// documentation ```cs\n? x\n```
130+
// ^ definition local 20
131+
// documentation ```cs\n? a\n```
114132
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceA.
115133
from b in sourceB
134+
// ^ definition local 21
135+
// documentation ```cs\n? b\n```
116136
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#sourceB.
117137
where a.Method() == b.Method()
118-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#MultipleFrom().a.
119-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#MultipleFrom().b.
138+
// ^ reference local 20
139+
// ^ reference local 21
120140
select new { A = a.Method(), B = b.Method() };
121-
// ^ reference local 8
122-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#MultipleFrom().a.
123-
// ^ reference local 9
124-
// ^ reference scip-dotnet nuget . . Main/QuerySyntax#MultipleFrom().b.
141+
// ^ reference local 14
142+
// ^ reference local 20
143+
// ^ reference local 15
144+
// ^ reference local 21
145+
}
146+
147+
void JoinInto(List<Student> students1, List<Student> students2)
148+
// ^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#JoinInto().
149+
// documentation ```cs\nprivate void QuerySyntax.JoinInto(List<Student> students1, List<Student> students2)\n```
150+
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#Student#
151+
// ^^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#JoinInto().(students1)
152+
// documentation ```cs\nList<Student> students1\n```
153+
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#Student#
154+
// ^^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#JoinInto().(students2)
155+
// documentation ```cs\nList<Student> students2\n```
156+
{
157+
var innerGroupJoinQuery =
158+
// ^^^^^^^^^^^^^^^^^^^ definition local 22
159+
// documentation ```cs\n? innerGroupJoinQuery\n```
160+
from student1 in students1
161+
// ^^^^^^^^ definition local 23
162+
// documentation ```cs\n? student1\n```
163+
// ^^^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#JoinInto().(students1)
164+
join student2 in students2 on student1.ID equals student2.ID into studentGroup
165+
// ^^^^^^^^ definition local 24
166+
// documentation ```cs\n? student2\n```
167+
// ^^^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#JoinInto().(students2)
168+
// ^^^^^^^^ reference local 23
169+
// ^^^^^^^^ reference local 24
170+
// ^^^^^^^^^^^^ definition local 25
171+
// documentation ```cs\n? studentGroup\n```
172+
select new { Student = student1.First, Students = studentGroup };
173+
// ^^^^^^^ reference local 27
174+
// ^^^^^^^^ reference local 23
175+
// ^^^^^^^^ reference local 28
176+
// ^^^^^^^^^^^^ reference local 25
177+
}
178+
179+
void Continuation(List<Student> students)
180+
// ^^^^^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Continuation().
181+
// documentation ```cs\nprivate void QuerySyntax.Continuation(List<Student> students)\n```
182+
// ^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#Student#
183+
// ^^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Continuation().(students)
184+
// documentation ```cs\nList<Student> students\n```
185+
{
186+
var sortedGroups =
187+
// ^^^^^^^^^^^^ definition local 29
188+
// documentation ```cs\n? sortedGroups\n```
189+
from student in students
190+
// ^^^^^^^ definition local 30
191+
// documentation ```cs\n? student\n```
192+
// ^^^^^^^^ reference scip-dotnet nuget . . Main/QuerySyntax#Continuation().(students)
193+
orderby student.Last, student.First
194+
// ^^^^^^^ reference local 30
195+
// ^^^^^^^ reference local 30
196+
group student by student.Last[0] into newGroup
197+
// ^^^^^^^ reference local 30
198+
// ^^^^^^^ reference local 30
199+
// ^^^^^^^^ definition local 31
200+
// documentation ```cs\n? newGroup\n```
201+
orderby newGroup.Key
202+
// ^^^^^^^^ reference local 31
203+
select newGroup;
204+
// ^^^^^^^^ reference local 31
205+
}
206+
207+
private class Student
208+
// ^^^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Student#
209+
// documentation ```cs\nclass Student\n```
210+
{
211+
public string First { get; set; }
212+
// ^^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Student#First.
213+
// documentation ```cs\npublic string Student.First { get; set; }\n```
214+
public string Last { get; set; }
215+
// ^^^^ definition scip-dotnet nuget . . Main/QuerySyntax#Student#Last.
216+
// documentation ```cs\npublic string Student.Last { get; set; }\n```
217+
public int ID { get; set; }
218+
// ^^ definition scip-dotnet nuget . . Main/QuerySyntax#Student#ID.
219+
// documentation ```cs\npublic int Student.ID { get; set; }\n```
125220
}
126221
}

0 commit comments

Comments
 (0)