Skip to content

Commit 71a34ff

Browse files
committed
Represent diagnostic categories as UIDs in SourceKit (WIP)
1 parent 754d199 commit 71a34ff

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

tools/SourceKit/docs/Protocol.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,19 @@ 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.
323-
[opt] <key.category>: (string) // The category of the diagnostic, e.g. 'deprecation', 'no-usage', ...
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.categories>: (array) [UID*] // The categories of the diagnostic. Can be:
324+
// - source.diagnostic.category.deprecation
325+
// - source.diagnostic.category.no_usage
324326
}
325327
```
326328

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ enum class DiagnosticSeverityKind {
193193
Error
194194
};
195195

196+
enum class DiagnosticCategory {
197+
Deprecation,
198+
NoUsage
199+
};
200+
196201
struct DiagnosticEntryInfoBase {
197202
struct Fixit {
198203
unsigned Offset;
@@ -201,12 +206,12 @@ struct DiagnosticEntryInfoBase {
201206
};
202207

203208
std::string ID;
204-
std::string Category;
205209
std::string Description;
206210
unsigned Offset = 0;
207211
unsigned Line = 0;
208212
unsigned Column = 0;
209213
std::string Filename;
214+
SmallVector<DiagnosticCategory, 1> Categories;
210215
SmallVector<std::pair<unsigned, unsigned>, 2> Ranges;
211216
SmallVector<Fixit, 2> Fixits;
212217
SmallVector<std::string, 1> EducationalNotePaths;

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

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

103103
SKInfo.ID = DiagnosticEngine::diagnosticIDStringFor(Info.ID).str();
104-
SKInfo.Category = Info.Category.str();
104+
105+
if (Info.Category == "deprecation") {
106+
SKInfo.Categories.push_back(DiagnosticCategory::Deprecation);
107+
} else if (Info.Category == "no-usage") {
108+
SKInfo.Categories.push_back(DiagnosticCategory::NoUsage);
109+
}
105110

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

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,8 +2827,20 @@ 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);
2830+
if (!Info.Categories.empty()) {
2831+
SmallVector<sourcekitd_uid_t, 1> CategoryUIDs;
2832+
for (auto C : Info.Categories) {
2833+
switch (C) {
2834+
case DiagnosticCategory::Deprecation:
2835+
CategoryUIDs.push_back(UIDKindDiagDeprecation);
2836+
break;
2837+
case DiagnosticCategory::NoUsage:
2838+
CategoryUIDs.push_back(UIDKindDiagNoUsage);
2839+
break;
2840+
}
2841+
}
2842+
Elem.set(KeyCategories, CategoryUIDs);
2843+
}
28322844

28332845
Elem.set(KeyDescription, Info.Description);
28342846
if (Info.Line != 0) {

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def __init__(self, internal_name, external_name):
155155
KEY('ArgIndex', 'key.argindex'),
156156
KEY('Text', 'key.text'),
157157
KEY('Category', 'key.category'),
158+
KEY('Categories', 'key.categories'),
158159
KEY('IsFunctionLike', 'key.is_function_like'),
159160
KEY('IsNonProtocolType', 'key.is_non_protocol_type'),
160161
KEY('RefactorActions', 'key.refactor_actions'),
@@ -417,6 +418,8 @@ def __init__(self, internal_name, external_name):
417418
KIND('DiagNote', 'source.diagnostic.severity.note'),
418419
KIND('DiagWarning', 'source.diagnostic.severity.warning'),
419420
KIND('DiagError', 'source.diagnostic.severity.error'),
421+
KIND('DiagDeprecation', 'source.diagnostic.category.deprecation'),
422+
KIND('DiagNoUsage', 'source.diagnostic.category.no_usage'),
420423
KIND('CodeCompletionEverything', 'source.codecompletion.everything'),
421424
KIND('CodeCompletionModule', 'source.codecompletion.module'),
422425
KIND('CodeCompletionKeyword', 'source.codecompletion.keyword'),

0 commit comments

Comments
 (0)