Skip to content

[SourceKit] Map line and column using the latest snapshot #37547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2021
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
11 changes: 11 additions & 0 deletions test/SourceKit/CursorInfo/cursor_after_edit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t)

// RUN: touch %t/empty.swift
// RUN: echo "func foo() {}" >> %t/func.swift

// Edit previously did not update the syntax info. Cursor info was using its
// buffer to calculate line and column (before rdar://78161348).
// RUN: %sourcekitd-test \
// RUN: -req=open -text-input %t/empty.swift %t/func.swift -- %t/func.swift == \
// RUN: -req=edit -offset=0 -length=0 -replace="func foo() {}" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/func.swift -- %t/func.swift == \
// RUN: -req=cursor -offset=5 %t/func.swift -- %t/func.swift
11 changes: 0 additions & 11 deletions tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2308,17 +2308,6 @@ ImmutableTextSnapshotRef SwiftEditorDocument::getLatestSnapshot() const {
return Impl.EditableBuffer->getSnapshot();
}

std::pair<unsigned, unsigned>
SwiftEditorDocument::getLineAndColumnInBuffer(unsigned Offset) {
llvm::sys::ScopedLock L(Impl.AccessMtx);

auto SyntaxInfo = Impl.getSyntaxInfo();
auto &SM = SyntaxInfo->getSourceManager();

auto Loc = SM.getLocForOffset(SyntaxInfo->getBufferID(), Offset);
return SM.getLineAndColumnInBuffer(Loc);
}

void SwiftEditorDocument::reportDocumentStructure(SourceFile &SrcFile,
EditorConsumer &Consumer) {
ide::SyntaxModelContext ModelContext(SrcFile);
Expand Down
1 change: 0 additions & 1 deletion tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class SwiftEditorDocument :
void removeCachedAST();

ImmutableTextSnapshotRef getLatestSnapshot() const;
std::pair<unsigned, unsigned> getLineAndColumnInBuffer(unsigned Offset);

void resetSyntaxInfo(ImmutableTextSnapshotRef Snapshot,
SwiftLangSupport &Lang, bool BuildSyntaxTree,
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ static void mapLocToLatestSnapshot(
}

std::tie(Location.Line, Location.Column) =
EditorDoc->getLineAndColumnInBuffer(Location.Offset);
LatestSnap->getBuffer()->getLineAndColumn(Location.Offset);
}


Expand Down