Skip to content

Commit 8c4c186

Browse files
committed
[sourcekit] Include diagnostics from code-completion in notification
The only interesting change here is that I stopped filtering out non-note diagnostics from outside the "inputs". This matches better how code-completion gets inputs, and shouldn't hurt anything else since only the tracing code will look at diagnostics that aren't in specific buffers anyway. rdar://38438512
1 parent b78987a commit 8c4c186

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
_ = unknown
2+
// code-completion at 2:1

test/SourceKit/CompileNotifications/diagnostics.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@
3838
// CLANG_IMPORTER-NEXT: key.filepath: "<{{.*}}>"
3939
// CLANG_IMPORTER-NEXT: key.severity: source.diagnostic.severity.error,
4040
// CLANG_IMPORTER-NEXT: key.description: {{.*}}not found
41+
42+
// Note: we're missing the "compiler is in code completion mode" diagnostic,
43+
// which is probably just as well.
44+
// RUN: %sourcekitd-test -req=track-compiles == -req=complete -offset=0 %s -- %s | %FileCheck %s -check-prefix=NODIAGS
45+
// RUN: %sourcekitd-test -req=track-compiles == -req=complete -pos=2:1 %S/Inputs/sema-error.swift -- %S/Inputs/sema-error.swift | %FileCheck %s -check-prefix=SEMA

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CodeCompletionOrganizer.h"
1414
#include "SwiftASTManager.h"
1515
#include "SwiftLangSupport.h"
16+
#include "SwiftEditorDiagConsumer.h"
1617
#include "SourceKit/Support/Logging.h"
1718
#include "SourceKit/Support/UIdent.h"
1819

@@ -138,6 +139,12 @@ static bool swiftCodeCompleteImpl(SwiftLangSupport &Lang,
138139
PrintingDiagnosticConsumer PrintDiags;
139140
CI.addDiagnosticConsumer(&PrintDiags);
140141

142+
EditorDiagConsumer TraceDiags;
143+
trace::TracedOperation TracedOp(trace::OperationKind::CodeCompletion);
144+
if (TracedOp.enabled()) {
145+
CI.addDiagnosticConsumer(&TraceDiags);
146+
}
147+
141148
CompilerInvocation Invocation;
142149
bool Failed = Lang.getASTManager().initCompilerInvocation(
143150
Invocation, Args, CI.getDiags(), InputFile->getBufferIdentifier(), Error);
@@ -188,8 +195,6 @@ static bool swiftCodeCompleteImpl(SwiftLangSupport &Lang,
188195

189196
TracedInit.finish();
190197

191-
192-
trace::TracedOperation TracedOp(trace::OperationKind::CodeCompletion);
193198
if (TracedOp.enabled()) {
194199
trace::SwiftInvocation SwiftArgs;
195200
trace::initTraceInfo(SwiftArgs, InputFile->getBufferIdentifier(), Args);
@@ -215,6 +220,13 @@ static bool swiftCodeCompleteImpl(SwiftLangSupport &Lang,
215220
&CompletionContext);
216221
CI.performSema();
217222
SwiftConsumer.clearContext();
223+
224+
if (TracedOp.enabled()) {
225+
SmallVector<DiagnosticEntryInfo, 8> Diagnostics;
226+
TraceDiags.getAllDiagnostics(Diagnostics);
227+
TracedOp.finish(Diagnostics);
228+
}
229+
218230
return true;
219231
}
220232

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,10 @@ void EditorDiagConsumer::handleDiagnostic(
114114
if (!isInputBufferID(BufferID)) {
115115
if (Info.ID == diag::error_from_clang.ID ||
116116
Info.ID == diag::warning_from_clang.ID ||
117-
Info.ID == diag::note_from_clang.ID) {
117+
Info.ID == diag::note_from_clang.ID ||
118+
!IsNote) {
118119
// Handle it as other diagnostics.
119120
} else {
120-
if (!IsNote) {
121-
LOG_WARN_FUNC("got swift diagnostic not pointing at input file, "
122-
"buffer name: " << SM.getIdentifierForBuffer(BufferID));
123-
return;
124-
}
125-
126121
// FIXME: This is a note pointing to a synthesized declaration buffer for
127122
// a declaration coming from a module.
128123
// We should include the Decl* in the DiagnosticInfo and have a way for

0 commit comments

Comments
 (0)