Skip to content

Preserve language service when closing generated interface#2648

Merged
rintaro merged 3 commits into
swiftlang:mainfrom
rintaro:language-service-close
May 14, 2026
Merged

Preserve language service when closing generated interface#2648
rintaro merged 3 commits into
swiftlang:mainfrom
rintaro:language-service-close

Conversation

@rintaro
Copy link
Copy Markdown
Member

@rintaro rintaro commented May 14, 2026

Fixes a bug where closing a generated interface document (e.g. a sourcekit-lsp:// Swift interface) would remove the language service for the originating source file, breaking subsequent requests like hover.
Both the generated interface and its originating source file share the same buildSettingsFile key in Workspace.languageServices, so closing the interface caused the service to be removed even while the source document was still open.

Based on #2598 by @edwardlee. The test has been updated to use IndexedSingleSwiftFileTestProject with -ignore-module-source-info to avoid CI failures on source-built toolchains, where sourcekitd resolves stdlib types to real source files rather than generated interfaces.

edwardlee and others added 3 commits May 13, 2026 15:56
Closing a generated interface document (sourcekit-lsp:// URI) was
removing the language service for the originating source file because
both share the same buildSettingsFile key. Guard the removal so it
only happens when no other open document shares that key.

Relates to swiftlang#2209
The buildSettingsFile key is an implementation detail of Workspace's
language-service dictionary, so the guard that prevents removing a
still-needed service belongs there rather than in SourceKitLSPServer.
…on CI

Use IndexedSingleSwiftFileTestProject with -ignore-module-source-info
to force the generated interface code path. Without this, CI toolchains
(built from source) resolve String to actual stdlib source files, causing
GetReferenceDocumentRequest to receive a file:// URI instead of
sourcekit-lsp://, resulting in an "Invalid Scheme" error.
@rintaro
Copy link
Copy Markdown
Member Author

rintaro commented May 14, 2026

@swift-ci Please test

@rintaro rintaro enabled auto-merge May 14, 2026 22:10
@rintaro rintaro merged commit a559d60 into swiftlang:main May 14, 2026
3 checks passed
Copy link
Copy Markdown
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM, one small nitpick.

}
""",
capabilities: ClientCapabilities(experimental: [
GetReferenceDocumentRequest.method: .dictionary(["supported": true])
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.

Should be able to use LSPAny conformance to ExpressibleByDictionaryLiteral.

Suggested change
GetReferenceDocumentRequest.method: .dictionary(["supported": true])
GetReferenceDocumentRequest.method: ["supported": true]

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.

4 participants