Commit Graph

3084 Commits

Author SHA1 Message Date
Bri Peticca da0c9a9ad9 Fix spm API usage for appropriate trait configuration
The `WorkspaceConfiguration.default` was being used to populate
the `Workspace`; there was an extra step here needed to assure that
we are propagating the trait configuration to the workspace.

The added test assures that non-default traits that are enabled are
indeed processed as enabled.
2026-05-27 12:57:16 -04:00
Rintaro Ishizaki 70f4c333ea Merge pull request #2662 from rintaro/migrate-atomics-to-synchronization
Migrate atomic call sites to Synchronization.Atomic
2026-05-22 11:34:13 -07:00
Alex Hoppen f53b3eaaf0 Merge pull request #2659 from Steffeeen/rename-fix 2026-05-21 21:50:15 +02:00
Rintaro Ishizaki a6c926fa34 Relax atomic memory orderings; switch semaphore to release/acquire
For ID counters and standalone flags (most sites), drop to .relaxed
since nothing reads other memory based on the atomic's value.

MultiEntrySemaphore.signaled is the exception: it is used as a
signal/wait primitive where waiters proceed to use state set up
before signal(). Use .releasing on store and .acquiring on load so
that pre-signal writes are visible to waiters that observe `true`.
.relaxed there would be incorrect on weakly-ordered architectures.
2026-05-21 11:16:17 -07:00
Rintaro Ishizaki 83de30d29f Migrate atomic call sites to Synchronization.Atomic and ThreadSafeBox
Replace AtomicBool/UInt8/UInt32/Int32 from
ToolsProtocolsSwiftExtensions with Synchronization.Atomic<T> where
the storage is a static, module-level let, or class stored property.
For local lets captured by @Sendable closures (where Atomic's
~Copyable nature prevents capture), use ThreadSafeBox<T> instead.
2026-05-21 10:58:34 -07:00
Steffeeen a7f43dc54c Fix rename target selection for initializer calls
When rename is invoked on a type name in an initializer call, prefer
renaming the nominal type symbol instead of the constructor symbol.
2026-05-21 10:55:47 +02:00
Rintaro Ishizaki a39c92022f Add forOpenDocument label to language service lookup methods
Rename languageServices(for:), primaryLanguageService(for:), and their
internal counterparts to use the `forOpenDocument` label, so the
precondition that the document must already be open is visible at call
sites.

Also make primaryLanguageService(forOpenDocument:) throw instead of
returning an optional, and switch several resolve-style handlers from
the find-or-create primaryLanguageService(for:_:) to
primaryLanguageService(forOpenDocument:), since those call sites already
have an open document in hand.
2026-05-20 10:31:44 -07:00
Rintaro Ishizaki 876fbad114 Merge pull request #2658 from rintaro/warnings-20260518
Fix build warnings
2026-05-19 05:37:48 -07:00
Rintaro Ishizaki b7fc4b5f1b Merge pull request #2655 from femaref/feature/proper-end
provide proper start and end positions in the LSP protocol
2026-05-18 21:03:48 -07:00
Rintaro Ishizaki f56a27b996 Fix build warnings 2026-05-18 18:04:44 -07:00
femaref c4c552203a provide proper start and end positions in the LSP protocol
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
2026-05-19 00:02:17 +02:00
Rintaro Ishizaki 626861d316 Merge pull request #2654 from rintaro/per-workspace-language-services
Scope language service lifetime to workspace
2026-05-18 14:59:47 -07:00
Rintaro Ishizaki f84abc1eb2 Use 'weak let' for immutable weak references (SE-0481)
Replace 'weak var' with 'weak let' for weak reference properties that are
set in init and never reassigned, using the Swift 6.3 feature introduced
by SE-0481.
2026-05-18 09:28:10 -07:00
Rintaro Ishizaki f2a121453d Scope language service instances per workspace
Previously, language services were held in a global registry on
SourceKitLSPServer and shared across workspaces, requiring complex
lifetime tracking (isImmortal, shutdownOrphanedLanguageServices) to
decide when to tear them down. In practice, every language service
already stored workspace-specific properties (buildServerManager,
semanticIndexManagerTask), so sharing them across workspaces was never
truly safe. Giving each Workspace its own service instances simplifies
lifetime management: services are created when needed and shut down
with their workspace.

Remove LanguageService.isImmortal, the workspace parameter from
canHandle(toolchain:), and the initialize/clientInitialized protocol
requirements.
2026-05-18 09:21:01 -07:00
Alex Hoppen 0cacc26db3 Merge pull request #2591 from ahoppen/require-6.3
Require Swift 6.3
2026-05-18 15:27:18 +02:00
Rintaro Ishizaki a559d60451 Merge pull request #2648 from rintaro/language-service-close
Preserve language service when closing generated interface
2026-05-14 16:26:50 -07:00
Rintaro Ishizaki 1d20e3f32e Merge pull request #2647 from rintaro/open-quickly-revise
Move Open Quickly and Jump to Definition docs to Contributor Documentation
2026-05-14 06:41:48 -07:00
Rintaro Ishizaki b60b9582ac Move language-service retention check into Workspace
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.
2026-05-13 20:59:29 -07:00
Edward Lee ca91f5ff4f Preserve language service when closing generated interface documents
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 #2209
2026-05-13 15:56:27 -07:00
Rintaro Ishizaki 292985e7dd Remove redundant fragment-clearing when constructing moduleFileURI 2026-05-13 10:25:09 -07:00
25harsh 90ceac197d Use ExpressibleByLiteral conformances for LSPAny 2026-05-13 16:19:42 +05:30
Rintaro Ishizaki 223a88cb8c Add workspace/symbolNames and workspace/symbolInfo LSP extensions (#2619)
- **`sourcekit/workspace/symbolNames`** — returns a flat, deduplicated
list of every symbol name in the workspace index (source and indexed
system modules). Clients use this to drive their search UI locally.

- **`sourcekit/workspace/symbolInfo`** — given a list of exact symbol
names, returns `WorkspaceSymbolItem` for each occurrence across all
workspaces, for display in the search result list. Source-file symbols
get `SymbolInformation` with a `file://` location. SDK/stdlib symbols
get a `WorkspaceSymbol` with `location: .uri(…)` The client must call
`workspaceSymbol/resolve` after the user selects an SDK/stdlib symbol to
obtain the concrete interface location.

- **`workspaceSymbol/resolve`** — resolves the deferred
`WorkspaceSymbol` location from `sourcekit/workspace/symbolInfo`. Parses
the `?module=` value into `moduleName`/`groupName`, finds a real source
file via `mainFiles(containing:)`, calls `openGeneratedInterface`, and
returns the symbol with `location` replaced by a full
`sourcekit-lsp://generated-swift-interface/` URI + range (or a temp
`file://` path for clients without `workspace/getReferenceDocument`
support).
2026-05-12 22:21:17 -07:00
Alex Hoppen 0dbad3f7fe Merge pull request #2642 from 25harsh/code-actions-to-module
[SwiftSyntaxCodeActions] Moved syntactic code actions into a new module
2026-05-12 15:49:34 +02:00
Rintaro Ishizaki 127492d655 Merge pull request #2640 from rintaro/copied-file-map-missing-adjustment
Fix and simplify CopiedFileMap adjustments
2026-05-11 09:32:57 -07:00
25harsh f185bc404f [SwiftSyntaxCodeActions] Moved syntactic code actions into a new module 2026-05-11 11:10:40 +05:30
Rintaro Ishizaki e638498119 Merge pull request #2580 from Steffeeen/local-sourcekit-build-docs
[ContributorDoc] Add detailed docs for using a local build of SourceKit
2026-05-10 17:59:30 -07:00
Rintaro Ishizaki eab4f58f32 Simplify adjusted(for:) implementations in LSP+CopiedFileMap
The range is never changed by URI adjustment, so there's no need to
construct intermediate Location values just to extract the URI.
2026-05-10 17:12:15 -07:00
Rintaro Ishizaki 2d320b288c Fix missing CopiedFileMap adjustments for WorkspaceEdit and TypeHierarchyItem
- WorkspaceEdit.adjusted(for:) was using originalURI(for:) ?? uri, which
  skips the file-existence check; switch to adjustedURI(for:)
- TypeHierarchyItem.adjusted(for:) was not adjusting the URI stored in
  data, unlike CallHierarchyItem
2026-05-10 17:12:12 -07:00
Rintaro Ishizaki 01b793dab4 Merge pull request #2637 from rintaro/lsp-messsage-metadata-structs
Replace manual LSPAny data handling with typed structs
2026-05-10 11:22:35 -07:00
Steffeeen 7166514240 Add SOURCEKIT_LSP_RUN_SOURCEKITD_IN_PROCESS environment variable
This environment variable can be used to force SourceKit-LSP to run
SourceKitD in-process on macOS. This can be useful for debugging.
2026-05-10 16:40:40 +02:00
Rintaro Ishizaki 2773bcdfa2 Merge pull request #2633 from rintaro/sourcekitd-inject
Allow injection of a pre-initialized sourcekitd connection
2026-05-07 19:57:41 -07:00
Rintaro Ishizaki 83afc9d1e1 Move CopiedFileMap LSP adjustments to extensions on LSP types
`CopiedFileMap` previously held methods like
`workspaceEditAdjustedForCopiedFiles`,
`callHierarchyItemAdjustedForCopiedFiles`, etc. that encoded knowledge
of high-level LSP message types into `BuildServerIntegration`.

Replace them with `adjusted(for:)` methods on each LSP type
(`Location`, `[Location]`, `LocationsOrLocationLinksResponse`,
`WorkspaceEdit`, `CallHierarchyItem`, `TypeHierarchyItem`) in a new
`LSP+CopiedFileMap.swift` in the SourceKitLSP module. The primitive
URI remapping is extracted into `CopiedFileMap.adjustedURI(for:)`
which remains in `BuildServerIntegration`.

`CallHierarchyItem.adjusted(for:)` also drops manual `LSPAny`
dictionary construction in favour of `HierarchyItemData`.
2026-05-07 16:10:02 -07:00
Rintaro Ishizaki 070bc52b8c Use typed structs for LSP item data fields instead of manual LSPAny 2026-05-07 15:25:18 -07:00
Rintaro Ishizaki 4b2fa3193a Allow injection of a pre-initialized sourcekitd connection
Introduce `SourceKitDCore` as the protocol boundary between dylib
lifecycle management and the high-level `SourceKitD` API. Its single
lifecycle entry point, `initializeService(api:notificationCallback:)`,
receives the already-loaded `sourcekitd_api_functions_t` from
`SourceKitD.init(core:)`.

`SourceKitDCoreImpl` is the standard implementation: `init` opens the
dylib; `initializeService` registers any plugin paths, calls
`api.initialize()`, and wires the notification handler; `deinit` calls
`shutdown()` and closes the handle. Pre-initialized conformances
implement `initializeService` as a no-op.

Wire a `sourcekitdCoreInjector` hook through `Hooks` so an embedding
host can return a pre-initialized `SourceKitDCore` for a given toolchain
path, preventing `sourcekitd_initialize()` from being called a second
time.

Declare `SourceKitDCoreForPlugin` at its use sites so each call site
can express the exact deinit behavior it needs: `dlclose` for handles
acquired via `RTLD_NOLOAD`, and `leak` for externally-owned handles.
2026-05-07 09:58:47 -07:00
Alex Hoppen 234890c484 Merge pull request #2607 from DeeSee/fix-duplicate-rename-edits
Make RenameLocation unique
2026-05-04 19:23:37 +02:00
Alexander Skvortsov 0b1a2cb372 Make RenameLocation unique 2026-04-30 17:27:19 +03:00
Alex Hoppen caa4b97c57 Merge pull request #2597 from Steffeeen/inlay-hint-performance
Cache inlay hints to avoid flickering
2026-04-30 15:37:42 +02:00
Steffeeen c5593c09c6 Cache inlay hints to avoid flickering
Previously, we always recomputed the inlay hints by calling into
SourceKit. If the document that we compute inlay hints for has recently
changed, SourceKit may need a bit of time to recompute the semantic
analysis. The inlay hints may thus need roughly 200-700ms to be
computed. This causes flickering in VSCode as it removes the old inlay
hints immediately and only displays them again when SourceKit-LSP
returned them.

With this commit we cache the inlay hints and recompute them in the
background. After the recompute is finished we use
`workspace/inlayHint/refresh` request to tell the client to refresh its
inlay hints. On each textDocument/didChange request the cached inlay
hints are shifted according to the text edits to ensure their positions
are still correct. This avoids the flickering as we can always return
the cached inlay hints immediately. The returned hints may however
temporarily show outdated type information until the background
recompute is finished.
2026-04-29 20:45:23 +02:00
Rintaro Ishizaki 3d7ebf7f20 Factor out CopiedFileMap as a Sendable value type
Extract the copied-file adjustment logic from BuildServerManager into a
Sendable value type CopiedFileMap. Call sites snapshot cachedCopiedFileMap
once per request (hoisted before loops) instead of awaiting the actor on
every iteration.
2026-04-28 12:12:40 -07:00
Rintaro Ishizaki ec0080e821 Merge pull request #2625 from rintaro/symbollocation-to-lsplocation
Add `SymbolLocation.lspPosition`, `lspLocation`
2026-04-28 11:57:24 -07:00
Rintaro Ishizaki 4fa1b30d52 Add SymbolLocation.lspPosition, lspLocation, and make documentUri optional
Add computed properties to `SymbolLocation` that centralise the
index-to-LSP coordinate conversion:

- `uri: DocumentURI?` — returns nil when `path` is empty.
- `lspPosition: Position` — converts the 1-based line/utf8Column to a
  0-based LSP Position, using UTF-8 column as a UTF-16 approximation.
- `lspLocation: Location?` — wraps `documentUri` + `lspPosition` into
  an LSP Location, returning nil when `path` is empty.

Update all call sites.
2026-04-28 06:56:55 -07:00
Bassam Khouri d3b39dafa0 Improve build system inferrence
SwiftPM PR #9985 introduce files in the scratch path whose contents
indicate which build system was used to build artifact for a given build
configuration.  if this file exist, use it's contents to infer the build
system. Otherwise, fallback to the existing behaviour.

Fixes: #2576
2026-04-26 17:21:58 -04:00
Rintaro Ishizaki 174a0d009a Merge pull request #2608 from Steffeeen/dev-docs-modules
[ContributorDoc] Cleanup Modules.md
2026-04-24 11:08:23 -07:00
Rintaro Ishizaki 0a432b94d2 [SwiftPM] Ignore file events in scratch directory
Binary targets backed by remote `.artifactbundleindex` URLs cause
SwiftPM to re-extract the artifact bundle into the scratch directory
on every package load. The resulting file-change events (delete +
create) for the extracted files triggered another reload, causing an
infinite loop.

Add `isInScratchDirectory` to `fileEventShouldTriggerPackageReload`
to filter out events before the build-settings check. It covers
both the configured scratch directory and the default `.build/`
directory (which receives regular `swift build` output even when
a custom scratch path is configured).

Also add tests using local zip-based binary targets to cover both
the default and custom-scratch-path scenarios. Local zips are used
in the tests to avoid a network dependency; they exercise the same
`isInScratchDirectory` code path even though the infinite loop in
practice requires a remote `.artifactbundleindex` target (where
SwiftPM's checksum mismatch causes re-extraction on every load).

https://github.com/swiftlang/sourcekit-lsp/issues/2615
2026-04-22 10:55:45 -07:00
Gabe Braden 61eb1d6aad Added forceResolvedVersions option 2026-04-17 16:57:51 -04:00
Steffeeen 2d4c2325b8 Remove SKLoggingForPlugin symbolic link
SKLogging was removed from this repository in f04b9717.
2026-04-14 13:51:51 +02:00
Alex Hoppen b4fafb64b3 Fix build warnings
Fix all build warnings except those caused by using old DocC request/response types, which are a little harder to resolve.
2026-04-12 16:11:11 +10:00
Alex Hoppen d3847f023e Merge pull request #2417 from ahoppen/no-implicit-cancellation
Don’t implicitly cancel requests when an edit is detected
2026-04-09 06:56:18 +10:00
Alex Hoppen 93872a0f08 Merge pull request #2574 from ahoppen/implicittargets
Fix build failure caused by `BuildTargetPrepareRequest` changing its return type
2026-04-09 06:55:07 +10:00
Alex Hoppen 322a667711 Merge pull request #2589 from ahoppen/container-name-lookup
Query `containerNamesCache` when looking up container name of an extension
2026-04-09 06:54:32 +10:00