@@ -323,6 +323,67 @@ void CodeCompletionString::dump() const {
323
323
}
324
324
}
325
325
326
+ ContextFreeCodeCompletionResult *
327
+ ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult (
328
+ llvm::BumpPtrAllocator &Allocator, CodeCompletionResultKind Kind,
329
+ CodeCompletionString *CompletionString,
330
+ CodeCompletionOperatorKind KnownOperatorKind, StringRef BriefDocComment,
331
+ CodeCompletionResultType ResultType,
332
+ ContextFreeNotRecommendedReason NotRecommended,
333
+ CodeCompletionDiagnosticSeverity DiagnosticSeverity,
334
+ StringRef DiagnosticMessage) {
335
+ return new (Allocator) ContextFreeCodeCompletionResult (
336
+ Kind, /* AssociatedKind=*/ 0 , KnownOperatorKind,
337
+ /* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " , BriefDocComment,
338
+ /* AssociatedUSRs=*/ {}, ResultType, NotRecommended, DiagnosticSeverity,
339
+ DiagnosticMessage);
340
+ }
341
+
342
+ ContextFreeCodeCompletionResult *
343
+ ContextFreeCodeCompletionResult::createKeywordResult (
344
+ llvm::BumpPtrAllocator &Allocator, CodeCompletionKeywordKind Kind,
345
+ CodeCompletionString *CompletionString, StringRef BriefDocComment,
346
+ CodeCompletionResultType ResultType) {
347
+ return new (Allocator) ContextFreeCodeCompletionResult (
348
+ CodeCompletionResultKind::Keyword, static_cast <uint8_t >(Kind),
349
+ CodeCompletionOperatorKind::None, /* IsSystem=*/ false , CompletionString,
350
+
351
+ /* ModuleName=*/ " " , BriefDocComment,
352
+ /* AssociatedUSRs=*/ {}, ResultType, ContextFreeNotRecommendedReason::None,
353
+ CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " );
354
+ }
355
+
356
+ ContextFreeCodeCompletionResult *
357
+ ContextFreeCodeCompletionResult::createLiteralResult (
358
+ llvm::BumpPtrAllocator &Allocator, CodeCompletionLiteralKind LiteralKind,
359
+ CodeCompletionString *CompletionString,
360
+ CodeCompletionResultType ResultType) {
361
+ return new (Allocator) ContextFreeCodeCompletionResult (
362
+ CodeCompletionResultKind::Literal, static_cast <uint8_t >(LiteralKind),
363
+ CodeCompletionOperatorKind::None,
364
+ /* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " ,
365
+ /* BriefDocComment=*/ " " ,
366
+ /* AssociatedUSRs=*/ {}, ResultType, ContextFreeNotRecommendedReason::None,
367
+ CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " );
368
+ }
369
+
370
+ ContextFreeCodeCompletionResult *
371
+ ContextFreeCodeCompletionResult::createDeclResult (
372
+ llvm::BumpPtrAllocator &Allocator, CodeCompletionString *CompletionString,
373
+ const Decl *AssociatedDecl, StringRef ModuleName, StringRef BriefDocComment,
374
+ ArrayRef<StringRef> AssociatedUSRs, CodeCompletionResultType ResultType,
375
+ ContextFreeNotRecommendedReason NotRecommended,
376
+ CodeCompletionDiagnosticSeverity DiagnosticSeverity,
377
+ StringRef DiagnosticMessage) {
378
+ assert (AssociatedDecl && " should have a decl" );
379
+ return new (Allocator) ContextFreeCodeCompletionResult (
380
+ CodeCompletionResultKind::Declaration,
381
+ static_cast <uint8_t >(getCodeCompletionDeclKind (AssociatedDecl)),
382
+ CodeCompletionOperatorKind::None, getDeclIsSystem (AssociatedDecl),
383
+ CompletionString, ModuleName, BriefDocComment, AssociatedUSRs, ResultType,
384
+ NotRecommended, DiagnosticSeverity, DiagnosticMessage);
385
+ }
386
+
326
387
CodeCompletionDeclKind
327
388
ContextFreeCodeCompletionResult::getCodeCompletionDeclKind (const Decl *D) {
328
389
switch (D->getKind ()) {
@@ -1276,8 +1337,8 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
1276
1337
}
1277
1338
}
1278
1339
1279
- ContextFreeResult = new (*Sink. Allocator ) ContextFreeCodeCompletionResult (
1280
- CCS, AssociatedDecl, ModuleName,
1340
+ ContextFreeResult = ContextFreeCodeCompletionResult::createDeclResult (
1341
+ *Sink. Allocator , CCS, AssociatedDecl, ModuleName,
1281
1342
copyString (*Sink.Allocator , BriefDocComment),
1282
1343
copyAssociatedUSRs (*Sink.Allocator , AssociatedDecl), ResultType,
1283
1344
ContextFreeNotRecReason, ContextFreeDiagnosticSeverity,
@@ -1286,22 +1347,23 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
1286
1347
}
1287
1348
1288
1349
case CodeCompletionResultKind::Keyword:
1289
- ContextFreeResult = new (*Sink. Allocator ) ContextFreeCodeCompletionResult (
1290
- KeywordKind, CCS, copyString ( *Sink.Allocator , BriefDocComment) ,
1291
- ResultType);
1350
+ ContextFreeResult = ContextFreeCodeCompletionResult::createKeywordResult (
1351
+ *Sink.Allocator , KeywordKind, CCS ,
1352
+ copyString (*Sink. Allocator , BriefDocComment), ResultType);
1292
1353
break ;
1293
1354
case CodeCompletionResultKind::BuiltinOperator:
1294
1355
case CodeCompletionResultKind::Pattern:
1295
- ContextFreeResult = new (*Sink.Allocator ) ContextFreeCodeCompletionResult (
1296
- Kind, CCS, CodeCompletionOperatorKind::None,
1297
- copyString (*Sink.Allocator , BriefDocComment), ResultType,
1298
- ContextFreeNotRecReason,
1299
- ContextFreeDiagnosticSeverity, ContextFreeDiagnosticMessage);
1356
+ ContextFreeResult =
1357
+ ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult (
1358
+ *Sink.Allocator , Kind, CCS, CodeCompletionOperatorKind::None,
1359
+ copyString (*Sink.Allocator , BriefDocComment), ResultType,
1360
+ ContextFreeNotRecReason, ContextFreeDiagnosticSeverity,
1361
+ ContextFreeDiagnosticMessage);
1300
1362
break ;
1301
1363
case CodeCompletionResultKind::Literal:
1302
1364
assert (LiteralKind.hasValue ());
1303
- ContextFreeResult = new (*Sink. Allocator )
1304
- ContextFreeCodeCompletionResult ( *LiteralKind, CCS, ResultType);
1365
+ ContextFreeResult = ContextFreeCodeCompletionResult::createLiteralResult (
1366
+ *Sink. Allocator , *LiteralKind, CCS, ResultType);
1305
1367
break ;
1306
1368
}
1307
1369
0 commit comments