Skip to content

Commit 8b037fc

Browse files
committed
[SourceKit] Move all options into a common options struct
1 parent 4b506b2 commit 8b037fc

File tree

8 files changed

+138
-165
lines changed

8 files changed

+138
-165
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ struct DiagnosticEntryInfo : DiagnosticEntryInfoBase {
190190

191191
class EditorConsumer {
192192
virtual void anchor();
193-
194193
public:
195194
virtual ~EditorConsumer() { }
196195

@@ -245,6 +244,10 @@ class EditorConsumer {
245244
std::vector<std::pair<unsigned, unsigned>> ReuseRegions) = 0;
246245

247246
virtual void finished() {}
247+
248+
// FIXME: This is just for bootstrapping incremental syntax tree parsing.
249+
// Remove it once when we are able to incrementally transfer the syntax tree
250+
virtual bool forceLibSyntaxBasedProcessing() = 0;
248251
};
249252

250253
class OptionsDictionary {
@@ -521,8 +524,7 @@ class LangSupport {
521524
codeCompleteSetCustom(ArrayRef<CustomCompletionInfo> completions) = 0;
522525

523526
virtual void editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
524-
bool EnableSyntaxMap, EditorConsumer &Consumer,
525-
bool LibSyntaxBasedProcessing,
527+
EditorConsumer &Consumer,
526528
ArrayRef<const char *> Args) = 0;
527529

528530
virtual void editorOpenInterface(EditorConsumer &Consumer,
@@ -554,8 +556,7 @@ class LangSupport {
554556

555557
virtual void editorReplaceText(StringRef Name, llvm::MemoryBuffer *Buf,
556558
unsigned Offset, unsigned Length,
557-
EditorConsumer &Consumer,
558-
bool LibSyntaxBasedProcessing) = 0;
559+
EditorConsumer &Consumer) = 0;
559560

560561
virtual void editorApplyFormatOptions(StringRef Name,
561562
OptionsDictionary &FmtOptions) = 0;

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,8 +1896,7 @@ void SwiftEditorDocument::parse(ImmutableTextSnapshotRef Snapshot,
18961896
Impl.SyntaxInfo->parse();
18971897
}
18981898

1899-
void SwiftEditorDocument::readSyntaxInfo(EditorConsumer &Consumer,
1900-
bool LibSyntaxBasedProcessing) {
1899+
void SwiftEditorDocument::readSyntaxInfo(EditorConsumer &Consumer) {
19011900
llvm::sys::ScopedLock L(Impl.AccessMtx);
19021901

19031902
Impl.ParserDiagnostics = Impl.SyntaxInfo->getDiagnostics();
@@ -1913,7 +1912,7 @@ void SwiftEditorDocument::readSyntaxInfo(EditorConsumer &Consumer,
19131912

19141913
SwiftSyntaxMap NewMap = SwiftSyntaxMap(Impl.SyntaxMap.Tokens.size() + 16);
19151914

1916-
if (LibSyntaxBasedProcessing) {
1915+
if (Consumer.forceLibSyntaxBasedProcessing()) {
19171916
auto &&SyntaxTree = Impl.SyntaxInfo->getSourceFile().getSyntaxRoot();
19181917

19191918
SyntaxClassifier Classifier;
@@ -2193,14 +2192,12 @@ void SwiftEditorDocument::reportDocumentStructure(SourceFile &SrcFile,
21932192
//===----------------------------------------------------------------------===//
21942193

21952194
void SwiftLangSupport::editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
2196-
bool EnableSyntaxMap,
21972195
EditorConsumer &Consumer,
2198-
bool LibSyntaxBasedProcessing,
21992196
ArrayRef<const char *> Args) {
22002197

22012198
ImmutableTextSnapshotRef Snapshot = nullptr;
22022199
const bool BuildSyntaxTree =
2203-
Consumer.syntaxTreeEnabled() || LibSyntaxBasedProcessing;
2200+
Consumer.syntaxTreeEnabled() || Consumer.forceLibSyntaxBasedProcessing();
22042201
auto EditorDoc = EditorDocuments.getByUnresolvedName(Name);
22052202
if (!EditorDoc) {
22062203
EditorDoc = new SwiftEditorDocument(Name, *this);
@@ -2225,7 +2222,7 @@ void SwiftLangSupport::editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
22252222
EditorDoc->updateSemaInfo();
22262223
}
22272224

2228-
EditorDoc->readSyntaxInfo(Consumer, LibSyntaxBasedProcessing);
2225+
EditorDoc->readSyntaxInfo(Consumer);
22292226
EditorDoc->readSemanticInfo(Snapshot, Consumer);
22302227
}
22312228

@@ -2333,10 +2330,10 @@ void verifyIncrementalParse(SwiftEditorDocumentRef EditorDoc,
23332330
}
23342331
}
23352332

2336-
void SwiftLangSupport::editorReplaceText(StringRef Name, llvm::MemoryBuffer *Buf,
2333+
void SwiftLangSupport::editorReplaceText(StringRef Name,
2334+
llvm::MemoryBuffer *Buf,
23372335
unsigned Offset, unsigned Length,
2338-
EditorConsumer &Consumer,
2339-
bool LibSyntaxBasedProcessing) {
2336+
EditorConsumer &Consumer) {
23402337
bool ValidateSyntaxTree = ::getenv("SOURCEKIT_INCREMENTAL_PARSE_VALIDATION");
23412338

23422339
auto EditorDoc = EditorDocuments.getByUnresolvedName(Name);
@@ -2357,8 +2354,8 @@ void SwiftLangSupport::editorReplaceText(StringRef Name, llvm::MemoryBuffer *Buf
23572354
Snapshot = EditorDoc->replaceText(Offset, Length, Buf,
23582355
Consumer.needsSemanticInfo());
23592356
assert(Snapshot);
2360-
bool BuildSyntaxTree =
2361-
Consumer.syntaxTreeEnabled() || LibSyntaxBasedProcessing;
2357+
bool BuildSyntaxTree = Consumer.syntaxTreeEnabled() ||
2358+
Consumer.forceLibSyntaxBasedProcessing();
23622359

23632360
llvm::Optional<SyntaxParsingCache> SyntaxCache;
23642361
if (EditorDoc->getSyntaxTree().hasValue()) {
@@ -2402,7 +2399,7 @@ void SwiftLangSupport::editorReplaceText(StringRef Name, llvm::MemoryBuffer *Buf
24022399
Consumer.handleSyntaxReuseRegions({});
24032400
}
24042401

2405-
EditorDoc->readSyntaxInfo(Consumer, LibSyntaxBasedProcessing);
2402+
EditorDoc->readSyntaxInfo(Consumer);
24062403

24072404
if (ValidateSyntaxTree) {
24082405
verifyIncrementalParse(EditorDoc, Offset, Length, PreEditText,

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SwiftEditorDocument :
9595
void parse(ImmutableTextSnapshotRef Snapshot, SwiftLangSupport &Lang,
9696
bool BuildSyntaxTree,
9797
swift::SyntaxParsingCache *SyntaxCache = nullptr);
98-
void readSyntaxInfo(EditorConsumer &consumer, bool LibSyntaxBasedProcessing);
98+
void readSyntaxInfo(EditorConsumer &consumer);
9999
void readSemanticInfo(ImmutableTextSnapshotRef Snapshot,
100100
EditorConsumer& Consumer);
101101

@@ -412,8 +412,8 @@ class SwiftLangSupport : public LangSupport {
412412
void
413413
codeCompleteSetCustom(ArrayRef<CustomCompletionInfo> completions) override;
414414

415-
void editorOpen(StringRef Name, llvm::MemoryBuffer *Buf, bool EnableSyntaxMap,
416-
EditorConsumer &Consumer, bool LibSyntaxBasedProcessing,
415+
void editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
416+
EditorConsumer &Consumer,
417417
ArrayRef<const char *> Args) override;
418418

419419
void editorOpenInterface(EditorConsumer &Consumer,
@@ -445,8 +445,7 @@ class SwiftLangSupport : public LangSupport {
445445

446446
void editorReplaceText(StringRef Name, llvm::MemoryBuffer *Buf,
447447
unsigned Offset, unsigned Length,
448-
EditorConsumer &Consumer,
449-
bool LibSyntaxBasedProcessing) override;
448+
EditorConsumer &Consumer) override;
450449

451450
void editorApplyFormatOptions(StringRef Name,
452451
OptionsDictionary &FmtOptions) override;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
646646
sourcekitd_request_dictionary_set_int64(Req, KeyEnableSyntaxMap, true);
647647
sourcekitd_request_dictionary_set_int64(Req, KeyEnableStructure, false);
648648
sourcekitd_request_dictionary_set_int64(Req, KeyEnableSyntaxTree, false);
649-
sourcekitd_request_dictionary_set_int64(Req, KeyLibSyntaxBasedProcessing,
650-
Opts.LibSyntaxBasedProcessing);
649+
sourcekitd_request_dictionary_set_int64(
650+
Req, KeyForceLibSyntaxBasedProcessing, Opts.LibSyntaxBasedProcessing);
651651
sourcekitd_request_dictionary_set_int64(Req, KeySyntacticOnly, !Opts.UsedSema);
652652
break;
653653

@@ -1062,9 +1062,9 @@ static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
10621062
EnableSubStructure);
10631063
sourcekitd_request_dictionary_set_int64(EdReq, KeySyntacticOnly,
10641064
!Opts.UsedSema);
1065-
sourcekitd_request_dictionary_set_int64(EdReq,
1066-
KeyLibSyntaxBasedProcessing,
1067-
Opts.LibSyntaxBasedProcessing);
1065+
sourcekitd_request_dictionary_set_int64(
1066+
EdReq, KeyForceLibSyntaxBasedProcessing,
1067+
Opts.LibSyntaxBasedProcessing);
10681068

10691069
sourcekitd_response_t EdResp = sendRequestSync(EdReq, Opts);
10701070
sourcekitd_response_description_dump_filedesc(EdResp, STDOUT_FILENO);

0 commit comments

Comments
 (0)