Skip to content

Commit c93a542

Browse files
committed
[NFC] preliminary formatting
1 parent ff73bb8 commit c93a542

File tree

8 files changed

+52
-36
lines changed

8 files changed

+52
-36
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,8 @@ class EditorConsumer {
391391
virtual void handleSemanticAnnotation(unsigned Offset, unsigned Length,
392392
UIdent Kind, bool isSystem) = 0;
393393

394-
virtual void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind, StringRef USR) = 0;
394+
virtual void handleDeclaration(unsigned Offset, unsigned Length,
395+
UIdent Kind, StringRef USR) = 0;
395396

396397
virtual void beginDocumentSubStructure(unsigned Offset, unsigned Length,
397398
UIdent Kind, UIdent AccessLevel,

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class SwiftInterfaceGenContext::Implementation {
6868
std::string Text;
6969
std::vector<TextReference> References;
7070
std::vector<TextDecl> Decls;
71-
/// Do not clear the map or erase elements, without keeping the Decls vector in sync
71+
/// Do not clear the map or erase elements,
72+
/// without keeping the Decls vector in sync
7273
llvm::StringMap<TextDecl> USRMap;
7374
};
7475

@@ -160,10 +161,14 @@ class AnnotatingPrinter : public StreamPrinter {
160161
StringRef USR = OS.str();
161162
DeclUSRs.emplace_back(VD, USR);
162163
auto iterator = Info.USRMap.insert_or_assign(USR, Entry).first;
163-
// Set the USR in the declarations to the key in the USRMap, because the lifetime of that matches/exceeds the lifetime of Decls
164-
// String keys in the StringMap are heap allocated and only get destroyed on explicit erase() or clear() calls, or on destructor calls
165-
// (the ProgrammersManual description itself also states that StringMap "only ever copies a string if a value is inserted").
166-
// Thus this never results in a dangling reference, as the USRMap is never cleared and no elements are erased in its lifetime.
164+
// Set the USR in the declarations to the key in the USRMap, because the
165+
// lifetime of that matches/exceeds the lifetime of Decls String keys in
166+
// the StringMap are heap allocated and only get destroyed on explicit
167+
// erase() or clear() calls, or on destructor calls (the Programmer's
168+
// Manual description itself also states that StringMap "only ever
169+
// copies a string if a value is inserted").
170+
// Thus this never results in a dangling reference, as the USRMap is
171+
// never cleared and no elements are erased in its lifetime.
167172
Info.Decls.back().USR = iterator->getKey();
168173
}
169174
}
@@ -273,16 +278,18 @@ static void reportSemanticAnnotations(const SourceTextInfo &IFaceInfo,
273278
}
274279
}
275280

276-
/// Create the declarations array (sourcekitd::DeclarationsArrayBuilder) from the SourceTextInfo about declarations
281+
/// Create the declarations array (sourcekitd::DeclarationsArrayBuilder) from
282+
/// the SourceTextInfo about declarations
277283
static void reportDeclarations(const SourceTextInfo &IFaceInfo,
278-
EditorConsumer &Consumer) {
284+
EditorConsumer &Consumer) {
279285
for (auto &Dcl : IFaceInfo.Decls) {
280-
if(!Dcl.Dcl)
286+
if (!Dcl.Dcl)
281287
continue;
282288
UIdent Kind = SwiftLangSupport::getUIDForDecl(Dcl.Dcl);
283289
if (Kind.isInvalid())
284290
continue;
285-
Consumer.handleDeclaration(Dcl.Range.Offset, Dcl.Range.Length, Kind, Dcl.USR);
291+
Consumer.handleDeclaration(Dcl.Range.Offset, Dcl.Range.Length, Kind,
292+
Dcl.USR);
286293
}
287294
}
288295

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,11 +2456,12 @@ static void printInterfaceGen(sourcekitd_variant_t Info, bool CheckASCII) {
24562456
sourcekitd_variant_t structure =
24572457
sourcekitd_variant_dictionary_get_value(Info, KeySubStructure);
24582458
printRawVariant(structure);
2459-
sourcekitd_variant_t declarations =
2459+
sourcekitd_variant_t declarations =
24602460
sourcekitd_variant_dictionary_get_value(Info, KeyDeclarations);
2461-
// only output declarations if there are any (because this might have been disabled in the request itself)
2462-
if(sourcekitd_variant_get_type(declarations) != SOURCEKITD_VARIANT_TYPE_NULL)
2463-
printRawVariant(declarations);
2461+
// only output declarations if there are any (because this might have been
2462+
// disabled in the request itself)
2463+
if (sourcekitd_variant_get_type(declarations) != SOURCEKITD_VARIANT_TYPE_NULL)
2464+
printRawVariant(declarations);
24642465
}
24652466

24662467
static void printRelatedIdents(sourcekitd_variant_t Info, StringRef Filename,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ struct CompactVariantFuncs<DeclarationsArray> {
148148

149149
template <typename FnTy>
150150
static auto getElement(sourcekitd_variant_t dict, sourcekitd_uid_t key,
151-
const FnTy &Fn) -> decltype(Fn(nullptr, nullptr, 0, 0, nullptr)) {
151+
const FnTy &Fn) -> decltype(Fn(nullptr, nullptr, 0, 0,
152+
nullptr)) {
152153
void *Buf = (void*)dict.data[1];
153154
size_t Index = dict.data[2];
154155

tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-XPC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "sourcekitd/CodeCompletionResultsArray.h"
14-
#include "sourcekitd/DeclarationsArray.h"
1514
#include "sourcekitd/DictionaryKeys.h"
1615
#include "sourcekitd/DocStructureArray.h"
1716
#include "sourcekitd/DocSupportAnnotationArray.h"
1817
#include "sourcekitd/TokenAnnotationsArray.h"
1918
#include "sourcekitd/ExpressionTypeArray.h"
2019
#include "sourcekitd/VariableTypeArray.h"
20+
#include "sourcekitd/DeclarationsArray.h"
2121
#include "sourcekitd/RawData.h"
2222
#include "sourcekitd/RequestResponsePrinterBase.h"
2323
#include "SourceKit/Support/UIdent.h"

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
280280
StringRef swiftVersion,
281281
bool EnableDeclarations);
282282
283-
static void editorOpenSwiftSourceInterface(
284-
StringRef Name, StringRef SourceName, ArrayRef<const char *> Args,
285-
SourceKitCancellationToken CancellationToken, ResponseReceiver Rec,
286-
bool EnableDeclarations);
283+
static void
284+
editorOpenSwiftSourceInterface(StringRef Name, StringRef SourceName,
285+
ArrayRef<const char *> Args,
286+
SourceKitCancellationToken CancellationToken,
287+
ResponseReceiver Rec,
288+
bool EnableDeclarations);
287289
288290
static void
289291
editorOpenSwiftTypeInterface(StringRef TypeUsr, ArrayRef<const char *> Args,
@@ -941,7 +943,8 @@ handleRequestEditorOpenInterface(const RequestDict &Req,
941943
Req.getInt64(KeySynthesizedExtension, SynthesizedExtension,
942944
/*isOptional=*/true);
943945
std::optional<StringRef> InterestedUSR = Req.getString(KeyInterestedUSR);
944-
bool EnableDeclarations = Req.getOptionalInt64(KeyEnableDeclarations).value_or(false);
946+
bool EnableDeclarations =
947+
Req.getOptionalInt64(KeyEnableDeclarations).value_or(false);
945948
return Rec(editorOpenInterface(*Name, *ModuleName, GroupName, Args,
946949
SynthesizedExtension, InterestedUSR,
947950
EnableDeclarations));
@@ -976,11 +979,11 @@ static void handleRequestEditorOpenHeaderInterface(
976979
if (swiftVerVal.has_value())
977980
swiftVer = std::to_string(*swiftVerVal);
978981
}
979-
bool EnableDeclarations = Req.getOptionalInt64(KeyEnableDeclarations).value_or(false);
980-
return Rec(editorOpenHeaderInterface(*Name, *HeaderName, Args,
981-
UsingSwiftArgs.value_or(false),
982-
SynthesizedExtension, swiftVer,
983-
EnableDeclarations));
982+
bool EnableDeclarations =
983+
Req.getOptionalInt64(KeyEnableDeclarations).value_or(false);
984+
return Rec(editorOpenHeaderInterface(
985+
*Name, *HeaderName, Args, UsingSwiftArgs.value_or(false),
986+
SynthesizedExtension, swiftVer, EnableDeclarations));
984987
}
985988
}
986989
@@ -998,10 +1001,10 @@ static void handleRequestEditorOpenSwiftSourceInterface(
9981001
if (!FileName.has_value())
9991002
return Rec(createErrorRequestInvalid("missing 'key.sourcefile'"));
10001003
// Reporting the declarations array is off by default
1001-
bool EnableDeclarations = Req.getOptionalInt64(KeyEnableDeclarations).value_or(false);
1002-
return editorOpenSwiftSourceInterface(*Name, *FileName, Args,
1003-
CancellationToken, Rec,
1004-
EnableDeclarations);
1004+
bool EnableDeclarations =
1005+
Req.getOptionalInt64(KeyEnableDeclarations).value_or(false);
1006+
return editorOpenSwiftSourceInterface(
1007+
*Name, *FileName, Args, CancellationToken, Rec, EnableDeclarations);
10051008
}
10061009
}
10071010
@@ -3550,7 +3553,8 @@ class SKEditorConsumer : public EditorConsumer {
35503553
void handleSemanticAnnotation(unsigned Offset, unsigned Length, UIdent Kind,
35513554
bool isSystem) override;
35523555

3553-
void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind, StringRef USR) override;
3556+
void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind,
3557+
StringRef USR) override;
35543558

35553559
bool documentStructureEnabled() override { return Opts.EnableStructure; }
35563560

@@ -3743,11 +3747,10 @@ sourcekitd_response_t SKEditorConsumer::createResponse() {
37433747
if (Opts.EnableStructure) {
37443748
Dict.setCustomBuffer(KeySubStructure, DocStructure.createBuffer());
37453749
}
3746-
if(Opts.EnableDeclarations){
3750+
if (Opts.EnableDeclarations) {
37473751
Dict.setCustomBuffer(KeyDeclarations, Declarations.createBuffer());
37483752
}
37493753

3750-
37513754
return RespBuilder.createResponse();
37523755
}
37533756

@@ -3776,7 +3779,8 @@ void SKEditorConsumer::handleSemanticAnnotation(unsigned Offset,
37763779
SemanticAnnotations.add(Kind, Offset, Length, isSystem);
37773780
}
37783781

3779-
void SKEditorConsumer::handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind, StringRef USR) {
3782+
void SKEditorConsumer::handleDeclaration(unsigned Offset, unsigned Length,
3783+
UIdent Kind, StringRef USR) {
37803784
assert(Kind.isValid());
37813785
Declarations.add(Kind, Offset, Length, USR);
37823786
}

unittests/SourceKit/SwiftLang/EditingTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class TestConsumer : public EditorConsumer {
6969
Annotations.push_back({Offset, Length, Kind, isSystem});
7070
}
7171

72-
void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind, StringRef USR) override {}
72+
void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind,
73+
StringRef USR) override {}
7374

7475
bool documentStructureEnabled() override { return false; }
7576

unittests/SourceKit/SwiftLang/NullEditorConsumer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class NullEditorConsumer : public EditorConsumer {
2929
void handleSemanticAnnotation(unsigned Offset, unsigned Length, UIdent Kind,
3030
bool isSystem) override {}
3131

32-
void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind, StringRef USR) override {}
32+
void handleDeclaration(unsigned Offset, unsigned Length, UIdent Kind,
33+
StringRef USR) override {}
3334

3435
bool documentStructureEnabled() override { return false; }
3536

0 commit comments

Comments
 (0)