@@ -23,11 +23,12 @@ namespace SourceKit {
23
23
namespace CodeCompletion {
24
24
25
25
using swift::ide::CodeCompletionDeclKind;
26
+ using swift::ide::CodeCompletionFlair;
26
27
using swift::ide::CodeCompletionKeywordKind;
27
28
using swift::ide::CodeCompletionLiteralKind;
28
- using swift::ide::SemanticContextKind;
29
- using swift::ide::CodeCompletionFlair;
29
+ using swift::ide::CodeCompletionOperatorKind;
30
30
using swift::ide::CodeCompletionString;
31
+ using swift::ide::SemanticContextKind;
31
32
using SwiftResult = swift::ide::CodeCompletionResult;
32
33
using swift::ide::CompletionKind;
33
34
@@ -75,7 +76,8 @@ struct NameStyle {
75
76
// /
76
77
// / Extends a \c swift::ide::CodeCompletionResult with extra fields that are
77
78
// / filled in by SourceKit. Generally stored in an \c CompletionSink.
78
- class Completion : public SwiftResult {
79
+ class Completion {
80
+ const SwiftResult &base;
79
81
void *opaqueCustomKind = nullptr ;
80
82
Optional<uint8_t > moduleImportDepth;
81
83
PopularityFactor popularityFactor;
@@ -89,9 +91,12 @@ class Completion : public SwiftResult {
89
91
90
92
// / Wraps \p base with an \c Completion. The \p name and \p description
91
93
// / should outlive the result, generally by being stored in the same
92
- // / \c CompletionSink.
93
- Completion (SwiftResult base, StringRef name, StringRef description)
94
- : SwiftResult(base), name(name), description(description) {}
94
+ // / \c CompletionSink or in a sink that was adopted by the sink that this
95
+ // / \c Compleiton is being stored in.
96
+ Completion (const SwiftResult &base, StringRef name, StringRef description)
97
+ : base(base), name(name), description(description) {}
98
+
99
+ const SwiftResult &getSwiftResult () const { return base; }
95
100
96
101
bool hasCustomKind () const { return opaqueCustomKind; }
97
102
void *getCustomKind () const { return opaqueCustomKind; }
@@ -102,6 +107,63 @@ class Completion : public SwiftResult {
102
107
// / A popularity factory in the range [-1, 1]. The higher the value, the more
103
108
// / 'popular' this result is. 0 indicates unknown.
104
109
PopularityFactor getPopularityFactor () const { return popularityFactor; }
110
+
111
+ // MARK: Methods that forward to the SwiftResult
112
+
113
+ SwiftResult::ResultKind getKind () const { return getSwiftResult ().getKind (); }
114
+
115
+ CodeCompletionDeclKind getAssociatedDeclKind () const {
116
+ return getSwiftResult ().getAssociatedDeclKind ();
117
+ }
118
+
119
+ CodeCompletionLiteralKind getLiteralKind () const {
120
+ return getSwiftResult ().getLiteralKind ();
121
+ }
122
+
123
+ CodeCompletionKeywordKind getKeywordKind () const {
124
+ return getSwiftResult ().getKeywordKind ();
125
+ }
126
+
127
+ bool isOperator () const { return getSwiftResult ().isOperator (); }
128
+
129
+ CodeCompletionOperatorKind getOperatorKind () const {
130
+ return getSwiftResult ().getOperatorKind ();
131
+ }
132
+
133
+ bool isSystem () const { return getSwiftResult ().isSystem (); }
134
+
135
+ SwiftResult::ExpectedTypeRelation getExpectedTypeRelation () const {
136
+ return getSwiftResult ().getExpectedTypeRelation ();
137
+ }
138
+
139
+ SemanticContextKind getSemanticContext () const {
140
+ return getSwiftResult ().getSemanticContext ();
141
+ }
142
+
143
+ CodeCompletionFlair getFlair () const { return getSwiftResult ().getFlair (); }
144
+
145
+ bool isNotRecommended () const { return getSwiftResult ().isNotRecommended (); }
146
+
147
+ unsigned getNumBytesToErase () const {
148
+ return getSwiftResult ().getNumBytesToErase ();
149
+ }
150
+
151
+ CodeCompletionString *getCompletionString () const {
152
+ return getSwiftResult ().getCompletionString ();
153
+ }
154
+
155
+ StringRef getModuleName () const { return getSwiftResult ().getModuleName (); }
156
+
157
+ StringRef getBriefDocComment () const {
158
+ return getSwiftResult ().getBriefDocComment ();
159
+ }
160
+
161
+ ArrayRef<StringRef> getAssociatedUSRs () const {
162
+ return getSwiftResult ().getAssociatedUSRs ();
163
+ }
164
+
165
+ // / Allow "upcasting" the completion result to a SwiftResult.
166
+ operator const SwiftResult &() const { return getSwiftResult (); }
105
167
};
106
168
107
169
// / Storage sink for \c Completion objects.
@@ -123,9 +185,9 @@ struct CompletionSink {
123
185
124
186
class CompletionBuilder {
125
187
CompletionSink &sink;
126
- SwiftResult ¤t ;
188
+ const SwiftResult &base ;
127
189
bool modified = false ;
128
- Completion ::ExpectedTypeRelation typeRelation;
190
+ SwiftResult ::ExpectedTypeRelation typeRelation;
129
191
SemanticContextKind semanticContext;
130
192
CodeCompletionFlair flair;
131
193
CodeCompletionString *completionString;
@@ -135,7 +197,7 @@ class CompletionBuilder {
135
197
PopularityFactor popularityFactor;
136
198
137
199
public:
138
- CompletionBuilder (CompletionSink &sink, SwiftResult &base);
200
+ CompletionBuilder (CompletionSink &sink, const SwiftResult &base);
139
201
140
202
void setCustomKind (void *opaqueCustomKind) { customKind = opaqueCustomKind; }
141
203
@@ -144,7 +206,7 @@ class CompletionBuilder {
144
206
moduleImportDepth = value;
145
207
}
146
208
147
- void setExpectedTypeRelation (Completion ::ExpectedTypeRelation Relation) {
209
+ void setExpectedTypeRelation (SwiftResult ::ExpectedTypeRelation Relation) {
148
210
modified = true ;
149
211
typeRelation = Relation;
150
212
}
@@ -233,8 +295,8 @@ struct FilterRules {
233
295
llvm::StringMap<bool > hideByFilterName;
234
296
llvm::StringMap<bool > hideByDescription;
235
297
236
- bool hideCompletion (Completion * completion) const ;
237
- bool hideCompletion (SwiftResult * completion, StringRef name,
298
+ bool hideCompletion (const Completion & completion) const ;
299
+ bool hideCompletion (const SwiftResult & completion, StringRef name,
238
300
StringRef description, void *customKind = nullptr ) const ;
239
301
bool hideFilterName (StringRef name) const ;
240
302
};
0 commit comments