Skip to content

Preserve language service when closing generated interface#2598

Open
edwardlee wants to merge 1 commit intoswiftlang:mainfrom
edwardlee:handle-interface-close
Open

Preserve language service when closing generated interface#2598
edwardlee wants to merge 1 commit intoswiftlang:mainfrom
edwardlee:handle-interface-close

Conversation

@edwardlee
Copy link
Copy Markdown

Closing a generated interface was removing the language service for the originating file because both share the same buildSettingsFile key. https://github.com/swiftlang/sourcekit-lsp/blob/main/Sources/SourceKitLSP/ReferenceDocumentURL.swift#L125
Guard the removal by when no other open document shares that key.
See #2209 and 7437d92

@rintaro
Copy link
Copy Markdown
Member

rintaro commented Apr 9, 2026

Good find, thanks! Could you add a test case that fails without this change?

@rintaro
Copy link
Copy Markdown
Member

rintaro commented Apr 9, 2026

On second thought, what if the documentManager document is closed first while the related generated interfaces are still open? Do they lose the language service?
Perhaps the language service should be tied to the uri itself, not the buildSettingsFile?

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
@edwardlee edwardlee force-pushed the handle-interface-close branch from 30d1d29 to 0c3a2f9 Compare April 16, 2026 15:49
@edwardlee
Copy link
Copy Markdown
Author

Added test similar to testNoDiagnosticsInGeneratedInterface. Since the logic checks for any remaining open file with the key before shutting down LSP, both cases work. Tying to the uri makes sense, this was just simpler.

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