Skip to content

Commit 985dbee

Browse files
committed
Simplify the integrated REPL code completion a little
Parsing additional declarations from a separate buffer into an existing SourceFile is definitely a hack, but again, the integrated REPL is deprecated and does not deserve real attention.
1 parent de07fdf commit 985dbee

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/IDE/REPLCodeCompletion.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID,
193193
CodeCompletionCallbacksFactory *CompletionCallbacksFactory) {
194194
// Temporarily disable printing the diagnostics.
195195
ASTContext &Ctx = SF.getASTContext();
196-
auto DiagnosticConsumers = Ctx.Diags.takeConsumers();
196+
DiagnosticTransaction DelayedDiags(Ctx.Diags);
197197

198198
std::string AugmentedCode = EnteredCode.str();
199199
AugmentedCode += '\0';
@@ -206,30 +206,23 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID,
206206
// Parse, typecheck and temporarily insert the incomplete code into the AST.
207207
const unsigned OriginalDeclCount = SF.Decls.size();
208208

209-
unsigned CurElem = OriginalDeclCount;
210209
PersistentParserState PersistentState(Ctx);
211210
std::unique_ptr<DelayedParsingCallbacks> DelayedCB(
212211
new CodeCompleteDelayedCallbacks(Ctx.SourceMgr.getCodeCompletionLoc()));
213212
bool Done;
214213
do {
215214
parseIntoSourceFile(SF, *BufferID, &Done, nullptr, &PersistentState,
216215
DelayedCB.get());
217-
performTypeChecking(SF, PersistentState.getTopLevelContext(), None,
218-
CurElem);
219-
CurElem = SF.Decls.size();
220216
} while (!Done);
217+
performTypeChecking(SF, PersistentState.getTopLevelContext(), None,
218+
OriginalDeclCount);
221219

222220
performDelayedParsing(&SF, PersistentState, CompletionCallbacksFactory);
223221

224222
// Now we are done with code completion. Remove the declarations we
225223
// temporarily inserted.
226224
SF.Decls.resize(OriginalDeclCount);
227-
228-
// Add the diagnostic consumers back.
229-
for (auto DC : DiagnosticConsumers)
230-
Ctx.Diags.addConsumer(*DC);
231-
232-
Ctx.Diags.resetHadAnyError();
225+
DelayedDiags.abort();
233226
}
234227

235228
void REPLCompletions::populate(SourceFile &SF, StringRef EnteredCode) {

0 commit comments

Comments
 (0)