Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,8 +1673,13 @@ ImmutableTextSnapshotRef SwiftEditorDocument::replaceText(
}

void SwiftEditorDocument::updateSemaInfo() {
if (Impl.SemanticInfo) {
Impl.SemanticInfo->processLatestSnapshotAsync(Impl.EditableBuffer);
Impl.AccessMtx.lock();
auto EditableBuffer = Impl.EditableBuffer;
auto SemanticInfo = Impl.SemanticInfo;
Impl.AccessMtx.unlock(); // Not a recursive mutex, so unlock before processing

if (SemanticInfo) {
SemanticInfo->processLatestSnapshotAsync(EditableBuffer);
}
}

Expand Down Expand Up @@ -1978,6 +1983,7 @@ void SwiftEditorDocument::expandPlaceholder(unsigned Offset, unsigned Length,
}

ImmutableTextSnapshotRef SwiftEditorDocument::getLatestSnapshot() const {
llvm::sys::ScopedLock L(Impl.AccessMtx);
return Impl.EditableBuffer->getSnapshot();
}

Expand Down
4 changes: 3 additions & 1 deletion unittests/SourceKit/SwiftLang/EditingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void EditTest::doubleOpenWithDelay(useconds_t delay, bool closeDoc) {
// be queried, since the semantic info from the first open is unreachable.
for (int i = 0; i < 2; ++i) {
bool expired = waitForDocUpdate(/*reset=*/true);
ASSERT_FALSE(expired) << "no second notification";
ASSERT_FALSE(expired) << "no " << (i ? "second " : "") << "notification";
replaceText(DocName, 0, 0, StringRef(), Consumer);
if (!Consumer.Diags.empty())
break;
Expand All @@ -262,6 +262,8 @@ void EditTest::doubleOpenWithDelay(useconds_t delay, bool closeDoc) {

ASSERT_EQ(1u, Consumer.Diags.size());
EXPECT_STREQ("use of unresolved identifier 'unknown_name'", Consumer.Diags[0].Description.c_str());

close(DocName);
}

// This test is failing occassionally in CI: rdar://42483323
Expand Down