Skip to content

Commit cf1be5e

Browse files
authored
Merge pull request #20427 from rockbruno/sourcekit-operators
2 parents 612c5e1 + 6f1f1bd commit cf1be5e

File tree

3 files changed

+190
-3
lines changed

3 files changed

+190
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %sourcekitd-test -req=index %s -- -Xfrontend -serialize-diagnostics-path -Xfrontend %t.dia %s | %sed_clean > %t.response
2+
// RUN: diff -u %s.response %t.response
3+
4+
class ClassA {
5+
init(){}
6+
}
7+
8+
func +(lhs: ClassA, rhs: ClassA) -> ClassA {
9+
return lhs
10+
}
11+
12+
struct StructB {
13+
func method() {
14+
let a = ClassA()
15+
let b = a + a
16+
let c = StructB()
17+
let d = c - c
18+
}
19+
20+
public static func -(lhs: StructB, rhs: StructB) -> StructB {
21+
return lhs
22+
}
23+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
key.hash: <hash>,
3+
key.dependencies: [
4+
{
5+
key.kind: source.lang.swift.import.module.swift,
6+
key.name: "Swift",
7+
key.filepath: Swift.swiftmodule,
8+
key.hash: <hash>,
9+
key.is_system: 1
10+
}
11+
],
12+
key.entities: [
13+
{
14+
key.kind: source.lang.swift.decl.class,
15+
key.name: "ClassA",
16+
key.usr: "s:15index_operators6ClassAC",
17+
key.line: 4,
18+
key.column: 7,
19+
key.entities: [
20+
{
21+
key.kind: source.lang.swift.decl.function.constructor,
22+
key.name: "init()",
23+
key.usr: "s:15index_operators6ClassACACycfc",
24+
key.line: 5,
25+
key.column: 5
26+
}
27+
]
28+
},
29+
{
30+
key.kind: source.lang.swift.decl.function.operator.infix,
31+
key.name: "+(_:_:)",
32+
key.usr: "s:15index_operators1poiyAA6ClassACAD_ADtF",
33+
key.line: 8,
34+
key.column: 6,
35+
key.entities: [
36+
{
37+
key.kind: source.lang.swift.ref.class,
38+
key.name: "ClassA",
39+
key.usr: "s:15index_operators6ClassAC",
40+
key.line: 8,
41+
key.column: 13
42+
},
43+
{
44+
key.kind: source.lang.swift.ref.class,
45+
key.name: "ClassA",
46+
key.usr: "s:15index_operators6ClassAC",
47+
key.line: 8,
48+
key.column: 26
49+
},
50+
{
51+
key.kind: source.lang.swift.ref.class,
52+
key.name: "ClassA",
53+
key.usr: "s:15index_operators6ClassAC",
54+
key.line: 8,
55+
key.column: 37
56+
}
57+
]
58+
},
59+
{
60+
key.kind: source.lang.swift.decl.struct,
61+
key.name: "StructB",
62+
key.usr: "s:15index_operators7StructBV",
63+
key.line: 12,
64+
key.column: 8,
65+
key.entities: [
66+
{
67+
key.kind: source.lang.swift.decl.function.method.instance,
68+
key.name: "method()",
69+
key.usr: "s:15index_operators7StructBV6methodyyF",
70+
key.line: 13,
71+
key.column: 10,
72+
key.entities: [
73+
{
74+
key.kind: source.lang.swift.ref.class,
75+
key.name: "ClassA",
76+
key.usr: "s:15index_operators6ClassAC",
77+
key.line: 14,
78+
key.column: 17
79+
},
80+
{
81+
key.kind: source.lang.swift.ref.function.constructor,
82+
key.name: "init()",
83+
key.usr: "s:15index_operators6ClassACACycfc",
84+
key.line: 14,
85+
key.column: 17
86+
},
87+
{
88+
key.kind: source.lang.swift.ref.function.operator.infix,
89+
key.name: "+(_:_:)",
90+
key.usr: "s:15index_operators1poiyAA6ClassACAD_ADtF",
91+
key.line: 15,
92+
key.column: 19
93+
},
94+
{
95+
key.kind: source.lang.swift.ref.struct,
96+
key.name: "StructB",
97+
key.usr: "s:15index_operators7StructBV",
98+
key.line: 16,
99+
key.column: 17
100+
},
101+
{
102+
key.kind: source.lang.swift.ref.function.constructor,
103+
key.name: "init()",
104+
key.usr: "s:15index_operators7StructBVACycfc",
105+
key.line: 16,
106+
key.column: 17
107+
},
108+
{
109+
key.kind: source.lang.swift.ref.function.operator.infix,
110+
key.name: "-(_:_:)",
111+
key.usr: "s:15index_operators7StructBV1soiyA2C_ACtFZ",
112+
key.line: 17,
113+
key.column: 19
114+
}
115+
]
116+
},
117+
{
118+
key.kind: source.lang.swift.decl.function.operator.infix,
119+
key.name: "-(_:_:)",
120+
key.usr: "s:15index_operators7StructBV1soiyA2C_ACtFZ",
121+
key.line: 20,
122+
key.column: 24,
123+
key.entities: [
124+
{
125+
key.kind: source.lang.swift.ref.struct,
126+
key.name: "StructB",
127+
key.usr: "s:15index_operators7StructBV",
128+
key.line: 20,
129+
key.column: 31
130+
},
131+
{
132+
key.kind: source.lang.swift.ref.struct,
133+
key.name: "StructB",
134+
key.usr: "s:15index_operators7StructBV",
135+
key.line: 20,
136+
key.column: 45
137+
},
138+
{
139+
key.kind: source.lang.swift.ref.struct,
140+
key.name: "StructB",
141+
key.usr: "s:15index_operators7StructBV",
142+
key.line: 20,
143+
key.column: 57
144+
}
145+
],
146+
key.attributes: [
147+
{
148+
key.attribute: source.decl.attribute.public
149+
}
150+
]
151+
},
152+
{
153+
key.kind: source.lang.swift.decl.function.constructor,
154+
key.usr: "s:15index_operators7StructBVACycfc",
155+
key.line: 12,
156+
key.column: 8
157+
}
158+
]
159+
}
160+
]
161+
}

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,21 +545,24 @@ UIdent SwiftLangSupport::getUIDForSymbol(SymbolInfo sym, bool isRef) {
545545
return UID_FOR(TypeAlias);
546546

547547
case SymbolKind::Function:
548+
case SymbolKind::StaticMethod:
548549
if (sym.SubKind == SymbolSubKind::SwiftPrefixOperator)
549550
return UID_FOR(FunctionPrefixOperator);
550551
if (sym.SubKind == SymbolSubKind::SwiftPostfixOperator)
551552
return UID_FOR(FunctionPostfixOperator);
552553
if (sym.SubKind == SymbolSubKind::SwiftInfixOperator)
553554
return UID_FOR(FunctionInfixOperator);
554-
return UID_FOR(FunctionFree);
555+
if (sym.Kind == SymbolKind::StaticMethod) {
556+
return UID_FOR(MethodStatic);
557+
} else {
558+
return UID_FOR(FunctionFree);
559+
}
555560
case SymbolKind::Variable:
556561
return UID_FOR(VarGlobal);
557562
case SymbolKind::InstanceMethod:
558563
return UID_FOR(MethodInstance);
559564
case SymbolKind::ClassMethod:
560565
return UID_FOR(MethodClass);
561-
case SymbolKind::StaticMethod:
562-
return UID_FOR(MethodStatic);
563566
case SymbolKind::InstanceProperty:
564567
if (sym.SubKind == SymbolSubKind::SwiftSubscript)
565568
return UID_FOR(Subscript);

0 commit comments

Comments
 (0)