Skip to content

Commit 9bbe441

Browse files
committed
[SourceKit] Change return value of functions in EditorConsumer to void
We were always returning true from those functions in SKEditorConsumer and false in the test consumers. On the client side we would then ignore the return value. So it's clearer to have the functions not return anything.
1 parent 293e8bd commit 9bbe441

File tree

5 files changed

+86
-139
lines changed

5 files changed

+86
-139
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ class EditorConsumer {
222222
virtual void handleRequestError(const char *Description) = 0;
223223

224224
virtual bool syntaxMapEnabled() = 0;
225-
virtual bool handleSyntaxMap(unsigned Offset, unsigned Length,
225+
virtual void handleSyntaxMap(unsigned Offset, unsigned Length,
226226
UIdent Kind) = 0;
227227

228228
virtual bool documentStructureEnabled() = 0;
229229

230-
virtual bool handleSemanticAnnotation(unsigned Offset, unsigned Length,
230+
virtual void handleSemanticAnnotation(unsigned Offset, unsigned Length,
231231
UIdent Kind, bool isSystem) = 0;
232232

233-
virtual bool beginDocumentSubStructure(unsigned Offset, unsigned Length,
233+
virtual void beginDocumentSubStructure(unsigned Offset, unsigned Length,
234234
UIdent Kind, UIdent AccessLevel,
235235
UIdent SetterAccessLevel,
236236
unsigned NameOffset,
@@ -246,25 +246,24 @@ class EditorConsumer {
246246
ArrayRef<StringRef> InheritedTypes,
247247
ArrayRef<std::tuple<UIdent, unsigned, unsigned>> Attrs) = 0;
248248

249-
virtual bool endDocumentSubStructure() = 0;
249+
virtual void endDocumentSubStructure() = 0;
250250

251-
virtual bool handleDocumentSubStructureElement(UIdent Kind,
252-
unsigned Offset,
251+
virtual void handleDocumentSubStructureElement(UIdent Kind, unsigned Offset,
253252
unsigned Length) = 0;
254253

255-
virtual bool recordAffectedRange(unsigned Offset, unsigned Length) = 0;
254+
virtual void recordAffectedRange(unsigned Offset, unsigned Length) = 0;
256255

257-
virtual bool recordAffectedLineRange(unsigned Line, unsigned Length) = 0;
256+
virtual void recordAffectedLineRange(unsigned Line, unsigned Length) = 0;
258257

259-
virtual bool recordFormattedText(StringRef Text) = 0;
258+
virtual void recordFormattedText(StringRef Text) = 0;
260259

261-
virtual bool setDiagnosticStage(UIdent DiagStage) = 0;
262-
virtual bool handleDiagnostic(const DiagnosticEntryInfo &Info,
260+
virtual void setDiagnosticStage(UIdent DiagStage) = 0;
261+
virtual void handleDiagnostic(const DiagnosticEntryInfo &Info,
263262
UIdent DiagStage) = 0;
264263

265-
virtual bool handleSourceText(StringRef Text) = 0;
264+
virtual void handleSourceText(StringRef Text) = 0;
266265

267-
virtual bool
266+
virtual void
268267
handleSyntaxTree(const swift::syntax::SourceFileSyntax &SyntaxTree,
269268
std::unordered_set<unsigned> ReusedNodeIds) = 0;
270269
virtual bool syntaxTreeEnabled() {
@@ -273,8 +272,8 @@ class EditorConsumer {
273272
virtual SyntaxTreeTransferMode syntaxTreeTransferMode() = 0;
274273

275274
virtual bool syntaxReuseInfoEnabled() = 0;
276-
virtual bool handleSyntaxReuseRegions(
277-
std::vector<SourceFileRange> ReuseRegions) = 0;
275+
virtual void
276+
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) = 0;
278277

279278
virtual void finished() {}
280279
};

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,8 +1856,7 @@ void SwiftEditorDocument::readSemanticInfo(ImmutableTextSnapshotRef Snapshot,
18561856
UIdent Kind = SemaTok.getUIdentForKind();
18571857
bool IsSystem = SemaTok.getIsSystem();
18581858
if (Kind.isValid())
1859-
if (!Consumer.handleSemanticAnnotation(Offset, Length, Kind, IsSystem))
1860-
break;
1859+
Consumer.handleSemanticAnnotation(Offset, Length, Kind, IsSystem);
18611860
}
18621861

18631862
static UIdent SemaDiagStage("source.diagnostic.stage.swift.sema");

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

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,14 +2047,14 @@ class SKEditorConsumer : public EditorConsumer {
20472047

20482048
bool syntaxMapEnabled() override { return Opts.EnableSyntaxMap; }
20492049

2050-
bool handleSyntaxMap(unsigned Offset, unsigned Length, UIdent Kind) override;
2050+
void handleSyntaxMap(unsigned Offset, unsigned Length, UIdent Kind) override;
20512051

2052-
bool handleSemanticAnnotation(unsigned Offset, unsigned Length, UIdent Kind,
2052+
void handleSemanticAnnotation(unsigned Offset, unsigned Length, UIdent Kind,
20532053
bool isSystem) override;
20542054

20552055
bool documentStructureEnabled() override { return Opts.EnableStructure; }
20562056

2057-
bool beginDocumentSubStructure(unsigned Offset, unsigned Length, UIdent Kind,
2057+
void beginDocumentSubStructure(unsigned Offset, unsigned Length, UIdent Kind,
20582058
UIdent AccessLevel,
20592059
UIdent SetterAccessLevel,
20602060
unsigned NameOffset,
@@ -2070,30 +2070,29 @@ class SKEditorConsumer : public EditorConsumer {
20702070
ArrayRef<StringRef> InheritedTypes,
20712071
ArrayRef<std::tuple<UIdent, unsigned, unsigned>> Attrs) override;
20722072

2073-
bool endDocumentSubStructure() override;
2073+
void endDocumentSubStructure() override;
20742074

2075-
bool handleDocumentSubStructureElement(UIdent Kind,
2076-
unsigned Offset,
2075+
void handleDocumentSubStructureElement(UIdent Kind, unsigned Offset,
20772076
unsigned Length) override;
20782077

2079-
bool recordAffectedRange(unsigned Offset, unsigned Length) override;
2078+
void recordAffectedRange(unsigned Offset, unsigned Length) override;
20802079

2081-
bool recordAffectedLineRange(unsigned Line, unsigned Length) override;
2080+
void recordAffectedLineRange(unsigned Line, unsigned Length) override;
20822081

2083-
bool recordFormattedText(StringRef Text) override;
2082+
void recordFormattedText(StringRef Text) override;
20842083

2085-
bool setDiagnosticStage(UIdent DiagStage) override;
2086-
bool handleDiagnostic(const DiagnosticEntryInfo &Info,
2084+
void setDiagnosticStage(UIdent DiagStage) override;
2085+
void handleDiagnostic(const DiagnosticEntryInfo &Info,
20872086
UIdent DiagStage) override;
20882087

2089-
bool handleSourceText(StringRef Text) override;
2088+
void handleSourceText(StringRef Text) override;
20902089

2091-
bool handleSyntaxTree(const swift::syntax::SourceFileSyntax &SyntaxTree,
2090+
void handleSyntaxTree(const swift::syntax::SourceFileSyntax &SyntaxTree,
20922091
std::unordered_set<unsigned> ReusedNodeIds) override;
20932092

20942093
bool syntaxReuseInfoEnabled() override { return Opts.EnableSyntaxReuseInfo; }
2095-
bool handleSyntaxReuseRegions(
2096-
std::vector<SourceFileRange> ReuseRegions) override;
2094+
void
2095+
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) override;
20972096

20982097
SyntaxTreeTransferMode syntaxTreeTransferMode() override {
20992098
return Opts.SyntaxTransferMode;
@@ -2268,24 +2267,22 @@ void SKEditorConsumer::handleRequestError(const char *Description) {
22682267
}
22692268
}
22702269

2271-
bool SKEditorConsumer::handleSyntaxMap(unsigned Offset, unsigned Length,
2270+
void SKEditorConsumer::handleSyntaxMap(unsigned Offset, unsigned Length,
22722271
UIdent Kind) {
22732272
if (!Opts.EnableSyntaxMap)
2274-
return true;
2273+
return;
22752274

22762275
SyntaxMap.add(Kind, Offset, Length, /*IsSystem=*/false);
2277-
return true;
22782276
}
22792277

2280-
bool SKEditorConsumer::handleSemanticAnnotation(unsigned Offset,
2281-
unsigned Length,
2282-
UIdent Kind, bool isSystem) {
2278+
void SKEditorConsumer::handleSemanticAnnotation(unsigned Offset,
2279+
unsigned Length, UIdent Kind,
2280+
bool isSystem) {
22832281
assert(Kind.isValid());
22842282
SemanticAnnotations.add(Kind, Offset, Length, isSystem);
2285-
return true;
22862283
}
22872284

2288-
bool
2285+
void
22892286
SKEditorConsumer::beginDocumentSubStructure(unsigned Offset,
22902287
unsigned Length, UIdent Kind,
22912288
UIdent AccessLevel,
@@ -2308,41 +2305,32 @@ SKEditorConsumer::beginDocumentSubStructure(unsigned Offset,
23082305
NameLength, BodyOffset, BodyLength, DocOffset, DocLength, DisplayName,
23092306
TypeName, RuntimeName, SelectorName, InheritedTypes, Attrs);
23102307
}
2311-
return true;
23122308
}
23132309

2314-
bool SKEditorConsumer::endDocumentSubStructure() {
2310+
void SKEditorConsumer::endDocumentSubStructure() {
23152311
if (Opts.EnableStructure)
23162312
DocStructure.endSubStructure();
2317-
return true;
23182313
}
23192314

2320-
bool SKEditorConsumer::handleDocumentSubStructureElement(UIdent Kind,
2315+
void SKEditorConsumer::handleDocumentSubStructureElement(UIdent Kind,
23212316
unsigned Offset,
23222317
unsigned Length) {
23232318
if (Opts.EnableStructure)
23242319
DocStructure.addElement(Kind, Offset, Length);
2325-
return true;
23262320
}
23272321

2328-
bool SKEditorConsumer::recordAffectedRange(unsigned Offset, unsigned Length) {
2322+
void SKEditorConsumer::recordAffectedRange(unsigned Offset, unsigned Length) {
23292323
Dict.set(KeyOffset, Offset);
23302324
Dict.set(KeyLength, Length);
2331-
2332-
return true;
23332325
}
23342326

2335-
bool SKEditorConsumer::recordAffectedLineRange(unsigned Line, unsigned Length) {
2327+
void SKEditorConsumer::recordAffectedLineRange(unsigned Line, unsigned Length) {
23362328
Dict.set(KeyLine, Line);
23372329
Dict.set(KeyLength, Length);
2338-
2339-
return true;
23402330
}
23412331

2342-
bool SKEditorConsumer::recordFormattedText(StringRef Text) {
2332+
void SKEditorConsumer::recordFormattedText(StringRef Text) {
23432333
Dict.set(KeySourceText, Text);
2344-
2345-
return true;
23462334
}
23472335

23482336
static void fillDictionaryForDiagnosticInfoBase(
@@ -2409,15 +2397,14 @@ static void fillDictionaryForDiagnosticInfoBase(
24092397
}
24102398
}
24112399

2412-
bool SKEditorConsumer::setDiagnosticStage(UIdent DiagStage) {
2400+
void SKEditorConsumer::setDiagnosticStage(UIdent DiagStage) {
24132401
Dict.set(KeyDiagnosticStage, DiagStage);
2414-
return true;
24152402
}
24162403

2417-
bool SKEditorConsumer::handleDiagnostic(const DiagnosticEntryInfo &Info,
2404+
void SKEditorConsumer::handleDiagnostic(const DiagnosticEntryInfo &Info,
24182405
UIdent DiagStage) {
24192406
if (!Opts.EnableDiagnostics)
2420-
return true;
2407+
return;
24212408

24222409
ResponseBuilder::Array &Arr = Diags;
24232410
if (Arr.isNull())
@@ -2426,19 +2413,17 @@ bool SKEditorConsumer::handleDiagnostic(const DiagnosticEntryInfo &Info,
24262413
auto Elem = Arr.appendDictionary();
24272414
Elem.set(KeyDiagnosticStage, DiagStage);
24282415
fillDictionaryForDiagnosticInfo(Elem, Info);
2429-
return true;
24302416
}
24312417

2432-
bool SKEditorConsumer::handleSourceText(StringRef Text) {
2418+
void SKEditorConsumer::handleSourceText(StringRef Text) {
24332419
Dict.set(KeySourceText, Text);
2434-
return true;
24352420
}
24362421

2437-
bool SKEditorConsumer::handleSyntaxTree(
2422+
void SKEditorConsumer::handleSyntaxTree(
24382423
const swift::syntax::SourceFileSyntax &SyntaxTree,
24392424
std::unordered_set<unsigned> ReusedNodeIds) {
24402425
if (Opts.SyntaxTransferMode == SyntaxTreeTransferMode::Off)
2441-
return true;
2426+
return;
24422427

24432428
std::string SyntaxTreeString;
24442429
{
@@ -2450,10 +2435,9 @@ bool SKEditorConsumer::handleSyntaxTree(
24502435
SyntaxTreeOutput << *SyntaxTree.getRaw();
24512436
}
24522437
Dict.set(KeySerializedSyntaxTree, SyntaxTreeString);
2453-
return true;
24542438
}
24552439

2456-
bool SKEditorConsumer::handleSyntaxReuseRegions(
2440+
void SKEditorConsumer::handleSyntaxReuseRegions(
24572441
std::vector<SourceFileRange> ReuseRegions) {
24582442
if (Opts.EnableSyntaxReuseInfo) {
24592443
auto Array = Dict.setArray(KeySyntaxReuseRegions);
@@ -2464,7 +2448,6 @@ bool SKEditorConsumer::handleSyntaxReuseRegions(
24642448
SubDict.set(KeyLength, Region.End - Region.Start);
24652449
}
24662450
}
2467-
return true;
24682451
}
24692452

24702453
static sourcekitd_response_t

unittests/SourceKit/SwiftLang/CursorInfoTest.cpp

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,15 @@ class NullEditorConsumer : public EditorConsumer {
3838

3939
bool syntaxMapEnabled() override { return true; }
4040

41-
bool handleSyntaxMap(unsigned Offset, unsigned Length, UIdent Kind) override {
42-
return false;
41+
void handleSyntaxMap(unsigned Offset, unsigned Length, UIdent Kind) override {
4342
}
4443

45-
bool handleSemanticAnnotation(unsigned Offset, unsigned Length,
46-
UIdent Kind, bool isSystem) override {
47-
return false;
48-
}
49-
44+
void handleSemanticAnnotation(unsigned Offset, unsigned Length, UIdent Kind,
45+
bool isSystem) override {}
46+
5047
bool documentStructureEnabled() override { return false; }
5148

52-
bool beginDocumentSubStructure(unsigned Offset, unsigned Length,
49+
void beginDocumentSubStructure(unsigned Offset, unsigned Length,
5350
UIdent Kind, UIdent AccessLevel,
5451
UIdent SetterAccessLevel,
5552
unsigned NameOffset,
@@ -64,49 +61,36 @@ class NullEditorConsumer : public EditorConsumer {
6461
StringRef SelectorName,
6562
ArrayRef<StringRef> InheritedTypes,
6663
ArrayRef<std::tuple<UIdent, unsigned, unsigned>> Attrs) override {
67-
return false;
6864
}
6965

70-
bool endDocumentSubStructure() override { return false; }
66+
void endDocumentSubStructure() override {}
7167

72-
bool handleDocumentSubStructureElement(UIdent Kind,
73-
unsigned Offset,
74-
unsigned Length) override {
75-
return false;
76-
}
68+
void handleDocumentSubStructureElement(UIdent Kind, unsigned Offset,
69+
unsigned Length) override {}
7770

78-
bool recordAffectedRange(unsigned Offset, unsigned Length) override {
79-
return false;
80-
}
81-
82-
bool recordAffectedLineRange(unsigned Line, unsigned Length) override {
83-
return false;
84-
}
71+
void recordAffectedRange(unsigned Offset, unsigned Length) override {}
8572

86-
bool recordFormattedText(StringRef Text) override { return false; }
73+
void recordAffectedLineRange(unsigned Line, unsigned Length) override {}
8774

88-
bool setDiagnosticStage(UIdent DiagStage) override { return false; }
89-
bool handleDiagnostic(const DiagnosticEntryInfo &Info,
90-
UIdent DiagStage) override {
91-
return false;
92-
}
75+
void setDiagnosticStage(UIdent DiagStage) override {}
76+
void handleDiagnostic(const DiagnosticEntryInfo &Info,
77+
UIdent DiagStage) override {}
78+
void recordFormattedText(StringRef Text) override {}
9379

94-
bool handleSourceText(StringRef Text) override { return false; }
95-
bool handleSyntaxTree(const swift::syntax::SourceFileSyntax &SyntaxTree,
96-
std::unordered_set<unsigned> ReusedNodeIds) override {
97-
return false;
98-
}
80+
void handleSourceText(StringRef Text) override {}
81+
void handleSyntaxTree(const swift::syntax::SourceFileSyntax &SyntaxTree,
82+
std::unordered_set<unsigned> ReusedNodeIds) override {}
9983

10084
SyntaxTreeTransferMode syntaxTreeTransferMode() override {
10185
return SyntaxTreeTransferMode::Off;
10286
}
10387

10488
bool syntaxReuseInfoEnabled() override { return false; }
10589

106-
bool handleSyntaxReuseRegions(
107-
std::vector<SourceFileRange> ReuseRegions) override {
108-
return false;
90+
void
91+
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) override {
10992
}
93+
11094
public:
11195
bool needsSema = false;
11296
};

0 commit comments

Comments
 (0)