Skip to content

provide proper start and end positions in the LSP protocol#2655

Merged
rintaro merged 1 commit into
swiftlang:mainfrom
femaref:feature/proper-end
May 19, 2026
Merged

provide proper start and end positions in the LSP protocol#2655
rintaro merged 1 commit into
swiftlang:mainfrom
femaref:feature/proper-end

Conversation

@femaref
Copy link
Copy Markdown
Contributor

@femaref femaref commented May 17, 2026

vscode provides an alternative action if the target of goto definition is in the same character range we requested. this requires the start and end in the LSP response to be properly set, so vscode can see that the current character is actually part of the request. Currently, this functionality only works when invoking "go to definition" on the start of the character range.

Screenshot 2026-05-18 at 00 09 05
broken.mp4
fixed.mp4

@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 17, 2026

@swift-ci please test

Copy link
Copy Markdown
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix.
Please update the test cases 🙏

Comment on lines +83 to +86
location = Location(
uri: uri,
range: Range(uncheckedBounds: (lower: positionStart, upper: positionEnd))
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use ..<? There's no reason to use "unchecked" version here.

Suggested change
location = Location(
uri: uri,
range: Range(uncheckedBounds: (lower: positionStart, upper: positionEnd))
)
location = Location(uri: uri, range: positionStart..<positionEnd)

let line: Int = dict[keys.line],
let column: Int = dict[keys.column]
let column: Int = dict[keys.column],
let length: Int = dict[keys.length]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know length is always there in cursorInfo response, but just to be on the safe side, could you do make it defaulted to zero? i.e. (dict[keys.length] ?? 0), so it's not going to be a part of if conditions.

@femaref
Copy link
Copy Markdown
Contributor Author

femaref commented May 18, 2026

Nice fix. Please update the test cases 🙏

apologies, I'm inexperienced with the tooling - it showed green checkmarks at the end, but that doesn't actually seem to be a global summary.

@femaref femaref force-pushed the feature/proper-end branch from 8b996cc to 3b4a908 Compare May 18, 2026 05:49
@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 18, 2026

@swift-ci Please test

@femaref
Copy link
Copy Markdown
Contributor Author

femaref commented May 18, 2026

I just realized it's more than that test failing.

@femaref femaref force-pushed the feature/proper-end branch from 3b4a908 to 0021490 Compare May 18, 2026 21:07
}

let location: Location?
let length = (dict[keys.length] ?? 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this inside if let snapshot { branch.

vscode provides an alternative action if the target of goto definition is in the same character range we requested.
this requires the start and end in the LSP response to be properly set, so vscode can see that the current character
is actually part of the request
@femaref femaref force-pushed the feature/proper-end branch from 0021490 to c4c5522 Compare May 18, 2026 22:03
@femaref
Copy link
Copy Markdown
Contributor Author

femaref commented May 18, 2026

I think I have now caught everything. I'm still getting two more failures, but those also happen on main:

Test Case '-[SourceKitLSPTests.SwiftInterfaceTests testJumpToSynthesizedExtensionMethodInSystemModuleWithoutIndex]' started.
/Users/femaref/assembly/sourcekit-lsp/Tests/SourceKitLSPTests/SwiftInterfaceTests.swift:269: error: -[SourceKitLSPTests.SwiftInterfaceTests testJumpToSynthesizedExtensionMethodInSystemModuleWithoutIndex] : XCTAssertTrue failed - Full line was: '@inlinable public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element]
'
Test Case '-[SourceKitLSPTests.SwiftInterfaceTests testJumpToSynthesizedExtensionMethodInSystemModuleWithoutIndex]' failed (1.413 seconds).
Test Case '-[SourceKitLSPTests.SwiftInterfaceTests testJumpToSynthesizedExtensionMethodInSystemModuleWithIndex]' started.
/Users/femaref/assembly/sourcekit-lsp/Tests/SourceKitLSPTests/SwiftInterfaceTests.swift:288: error: -[SourceKitLSPTests.SwiftInterfaceTests testJumpToSynthesizedExtensionMethodInSystemModuleWithIndex] : XCTAssertTrue failed - Full line was: '@inlinable public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element]
'
Test Case '-[SourceKitLSPTests.SwiftInterfaceTests testJumpToSynthesizedExtensionMethodInSystemModuleWithIndex]' failed (0.829 seconds).

@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 18, 2026

@swift-ci Please test

@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 18, 2026

@swift-ci Please test Windows

@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 18, 2026

I'm still getting two more failures, but those also happen on main:

Those 2 tests fails if you're testing against older SDK where swiftlang/swift#87020 has not been applied. We probably should update the tests to accept both signatures...

@rintaro rintaro enabled auto-merge May 19, 2026 02:48
@rintaro rintaro merged commit b7fc4b5 into swiftlang:main May 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants