Skip to content

Commit 78b6759

Browse files
authored
Merge pull request #30059 from owenv/sourcekit-edu-notes
[Diagnostics][SourceKit] Expose educational notes through SourceKit diagnostics request
2 parents 0031873 + f11df3e commit 78b6759

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extension (Int, Int) {}
2+
3+
// RUN: %sourcekitd-test -req=sema %s -- -Xfrontend -enable-descriptive-diagnostics -Xfrontend -diagnostic-documentation-path -Xfrontend /educational/notes/path/prefix %s | %FileCheck %s -check-prefix=DESCRIPTIVE
4+
5+
// DESCRIPTIVE: key.description: "non-nominal type
6+
// DESCRIPTIVE: key.educational_note_paths: [
7+
// DESCRIPTIVE-NEXT: "/educational/notes/path/prefix/nominal-types.md"
8+
// DESCRIPTIVE-NEXT: ]
9+
10+
// RUN: %sourcekitd-test -req=sema %s -- %s | %FileCheck %s -check-prefix=DESCRIPTIVE-DISABLED
11+
12+
// DESCRIPTIVE-DISABLED: key.description: "non-nominal type
13+
// DESCRIPTIVE-DISABLED-NOT: key.educational_note_paths

tools/SourceKit/docs/Protocol.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ of diagnostic entries. A diagnostic entry has this format:
418418
[opts] <key.fixits>: (array) [fixit+] // one or more entries for fixits
419419
[opts] <key.ranges>: (array) [range+] // one or more entries for ranges
420420
[opts] <key.diagnostics>: (array) [diagnostic+] // one or more sub-diagnostic entries
421+
[opts] <key.educational_note_paths>: (array) [string+] // one or more absolute paths of educational notes, formatted as Markdown
421422
}
422423
```
423424

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct DiagnosticEntryInfoBase {
203203
std::string Filename;
204204
SmallVector<std::pair<unsigned, unsigned>, 2> Ranges;
205205
SmallVector<Fixit, 2> Fixits;
206+
SmallVector<std::string, 1> EducationalNotePaths;
206207
};
207208

208209
struct DiagnosticEntryInfo : DiagnosticEntryInfoBase {

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ void EditorDiagConsumer::handleDiagnostic(SourceManager &SM,
110110
}
111111
SKInfo.Description = Text.str();
112112

113+
for (auto notePath : Info.EducationalNotePaths)
114+
SKInfo.EducationalNotePaths.push_back(notePath);
115+
113116
Optional<unsigned> BufferIDOpt;
114117
if (Info.Loc.isValid()) {
115118
BufferIDOpt = SM.findBufferContainingLoc(Info.Loc);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,6 +2686,9 @@ static void fillDictionaryForDiagnosticInfoBase(
26862686
if (!Info.Filename.empty())
26872687
Elem.set(KeyFilePath, Info.Filename);
26882688

2689+
if (!Info.EducationalNotePaths.empty())
2690+
Elem.set(KeyEducationalNotePaths, Info.EducationalNotePaths);
2691+
26892692
if (!Info.Ranges.empty()) {
26902693
auto RangesArr = Elem.setArray(KeyRanges);
26912694
for (auto R : Info.Ranges) {

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(self, internal_name, external_name):
9696
KEY('Ranges', 'key.ranges'),
9797
KEY('Fixits', 'key.fixits'),
9898
KEY('Diagnostics', 'key.diagnostics'),
99+
KEY('EducationalNotePaths', 'key.educational_note_paths'),
99100
KEY('FormatOptions', 'key.editor.format.options'),
100101
KEY('CodeCompleteOptions', 'key.codecomplete.options'),
101102
KEY('FilterRules', 'key.codecomplete.filterrules'),

0 commit comments

Comments
 (0)