Skip to content

Commit 754d199

Browse files
committed
Expose diagnostic category via SourceKit
1 parent d9e2bcd commit 754d199

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,9 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
11311131
StringRef Category;
11321132
if (isAPIDigesterBreakageDiagnostic(diagnostic.getID()))
11331133
Category = "api-digester-breaking-change";
1134-
if (isDeprecationDiagnostic(diagnostic.getID()))
1134+
else if (isDeprecationDiagnostic(diagnostic.getID()))
11351135
Category = "deprecation";
1136-
if (isNoUsageDiagnostic(diagnostic.getID()))
1136+
else if (isNoUsageDiagnostic(diagnostic.getID()))
11371137
Category = "no-usage";
11381138

11391139
return DiagnosticInfo(

tools/SourceKit/docs/Protocol.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,17 @@ entity ::=
310310
```
311311
diagnostic ::=
312312
{
313-
<key.id>: (string) // The internal ID of the diagnostic.
314-
<key.line>: (int64) // The line upon which the diagnostic was emitted.
315-
<key.column>: (int64) // The column upon which the diagnostic was emitted.
316-
<key.filepath>: (string) // The absolute path to the file that was being parsed
317-
// when the diagnostic was emitted.
318-
<key.severity>: (UID) // The severity of the diagnostic. Can be one of:
319-
// - source.diagnostic.severity.note
320-
// - source.diagnostic.severity.warning
321-
// - source.diagnostic.severity.error
322-
<key.description>: (string) // A description of the diagnostic.
313+
<key.id>: (string) // The internal ID of the diagnostic.
314+
<key.line>: (int64) // The line upon which the diagnostic was emitted.
315+
<key.column>: (int64) // The column upon which the diagnostic was emitted.
316+
<key.filepath>: (string) // The absolute path to the file that was being parsed
317+
// when the diagnostic was emitted.
318+
<key.severity>: (UID) // The severity of the diagnostic. Can be one of:
319+
// - source.diagnostic.severity.note
320+
// - source.diagnostic.severity.warning
321+
// - source.diagnostic.severity.error
322+
<key.description>: (string) // A description of the diagnostic.
323+
[opt] <key.category>: (string) // The category of the diagnostic, e.g. 'deprecation', 'no-usage', ...
323324
}
324325
```
325326

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ struct DiagnosticEntryInfoBase {
201201
};
202202

203203
std::string ID;
204+
std::string Category;
204205
std::string Description;
205206
unsigned Offset = 0;
206207
unsigned Line = 0;

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void EditorDiagConsumer::handleDiagnostic(SourceManager &SM,
101101
DiagnosticEntryInfo SKInfo;
102102

103103
SKInfo.ID = DiagnosticEngine::diagnosticIDStringFor(Info.ID).str();
104+
SKInfo.Category = Info.Category.str();
104105

105106
// Actually substitute the diagnostic arguments into the diagnostic text.
106107
llvm::SmallString<256> Text;

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,9 @@ static void fillDictionaryForDiagnosticInfoBase(
28272827
if (!Info.ID.empty())
28282828
Elem.set(KeyID, Info.ID);
28292829

2830+
if (!Info.Category.empty())
2831+
Elem.set(KeyCategory, Info.Category);
2832+
28302833
Elem.set(KeyDescription, Info.Description);
28312834
if (Info.Line != 0) {
28322835
Elem.set(KeyLine, Info.Line);

0 commit comments

Comments
 (0)