@@ -1091,7 +1091,7 @@ doConformingMethodList(const CompilerInvocation &InitInvok,
10911091static void printCodeCompletionResultsImpl (
10921092 ArrayRef<CodeCompletionResult *> Results, llvm::raw_ostream &OS,
10931093 bool IncludeKeywords, bool IncludeComments, bool IncludeSourceText,
1094- bool PrintAnnotatedDescription, const ASTContext & Ctx) {
1094+ bool PrintAnnotatedDescription, const ASTContext * Ctx) {
10951095 unsigned NumResults = 0 ;
10961096 for (auto Result : Results) {
10971097 if (!IncludeKeywords &&
@@ -1134,30 +1134,33 @@ static void printCodeCompletionResultsImpl(
11341134 OS << " ; comment=" << comment;
11351135 }
11361136
1137- SmallString<256 > Scratch;
1138- auto DiagSeverityAndMessage =
1139- Result->getDiagnosticSeverityAndMessage (Scratch, Ctx);
1140- if (DiagSeverityAndMessage.first !=
1141- CodeCompletionDiagnosticSeverity::None) {
1142- OS << " ; diagnostics=" << comment;
1143- switch (DiagSeverityAndMessage.first ) {
1144- case CodeCompletionDiagnosticSeverity::Error:
1145- OS << " error" ;
1146- break ;
1147- case CodeCompletionDiagnosticSeverity::Warning:
1148- OS << " warning" ;
1149- break ;
1150- case CodeCompletionDiagnosticSeverity::Remark:
1151- OS << " remark" ;
1152- break ;
1153- case CodeCompletionDiagnosticSeverity::Note:
1154- OS << " note" ;
1155- break ;
1156- case CodeCompletionDiagnosticSeverity::None:
1157- llvm_unreachable (" none" );
1158- }
1137+ if (Ctx) {
1138+ // Only print diagnostics if we have an ASTContext
11591139 SmallString<256 > Scratch;
1160- OS << " :" << DiagSeverityAndMessage.second ;
1140+ auto DiagSeverityAndMessage =
1141+ Result->getDiagnosticSeverityAndMessage (Scratch, *Ctx);
1142+ if (DiagSeverityAndMessage.first !=
1143+ CodeCompletionDiagnosticSeverity::None) {
1144+ OS << " ; diagnostics=" << comment;
1145+ switch (DiagSeverityAndMessage.first ) {
1146+ case CodeCompletionDiagnosticSeverity::Error:
1147+ OS << " error" ;
1148+ break ;
1149+ case CodeCompletionDiagnosticSeverity::Warning:
1150+ OS << " warning" ;
1151+ break ;
1152+ case CodeCompletionDiagnosticSeverity::Remark:
1153+ OS << " remark" ;
1154+ break ;
1155+ case CodeCompletionDiagnosticSeverity::Note:
1156+ OS << " note" ;
1157+ break ;
1158+ case CodeCompletionDiagnosticSeverity::None:
1159+ llvm_unreachable (" none" );
1160+ }
1161+ SmallString<256 > Scratch;
1162+ OS << " :" << DiagSeverityAndMessage.second ;
1163+ }
11611164 }
11621165
11631166 OS << " \n " ;
@@ -1188,7 +1191,7 @@ static int printCodeCompletionResults(
11881191 printCodeCompletionResultsImpl (
11891192 Result.ResultSink .Results , OS, IncludeKeywords, IncludeComments,
11901193 IncludeSourceText, PrintAnnotatedDescription,
1191- Result.Info .compilerInstance ->getASTContext ());
1194+ & Result.Info .compilerInstance ->getASTContext ());
11921195 printCodeCompletionLookedupTypeNames (
11931196 Result.Info .completionContext ->LookedupNominalTypeNames , OS);
11941197 return 0 ;
@@ -1570,7 +1573,7 @@ static int doBatchCodeCompletion(const CompilerInvocation &InitInvok,
15701573 Result->ResultSink .Results , OS, IncludeKeywords,
15711574 IncludeComments, IncludeSourceText,
15721575 CodeCompletionAnnotateResults,
1573- Result->Info .compilerInstance ->getASTContext ());
1576+ & Result->Info .compilerInstance ->getASTContext ());
15741577 printCodeCompletionLookedupTypeNames (
15751578 Result->Info .completionContext ->LookedupNominalTypeNames , OS);
15761579 break ;
@@ -4249,12 +4252,11 @@ int main(int argc, char *argv[]) {
42494252 ContextualNotRecommendedReason::None);
42504253 contextualResults.push_back (contextualResult);
42514254 }
4252- auto CompInstance = std::make_unique<CompilerInstance>();
42534255 printCodeCompletionResultsImpl (
42544256 contextualResults, llvm::outs (), options::CodeCompletionKeywords,
42554257 options::CodeCompletionComments, options::CodeCompletionSourceText,
42564258 options::CodeCompletionAnnotateResults,
4257- CompInstance-> getASTContext () );
4259+ /* Ctx= */ nullptr );
42584260 }
42594261
42604262 return 0 ;
0 commit comments