164 Commits

Author SHA1 Message Date
Alex Hoppen 3522158207 Merge pull request #2679 from somiljain2006/Local-variable-refrence
Fix references for local variables and parameters
2026-06-15 10:15:28 -07:00
Rintaro Ishizaki b9e4c67793 Delete SwiftExtensions duplicates of swift-tools-protocols APIs
Delete `Collection+Only.swift`, `Duration+Seconds.swift`,
`FileManagerExtensions.swift`, `PipeAsStringHandler.swift`, and
`URLExtensions.swift` from `Sources/SwiftExtensions/`. The same
APIs now live in swift-tools-protocols as `@_spi(SourceKitLSP)
public` declarations.

Update each call site to add `@_spi(SourceKitLSP) import
ToolsProtocolsSwiftExtensions` next to the existing
`import SwiftExtensions`. Add the
`_ToolsProtocolsSwiftExtensionsForPlugin` dependency and the
`ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin`
module alias to the `SwiftSourceKitClientPlugin` target in both
`Package.swift` and the corresponding `CMakeLists.txt`.
2026-06-08 21:08:24 -07:00
somiljain2006 5b47421f8b Fix the filtering logic 2026-06-02 01:04:38 +05:30
somiljain2006 477d33c89c Fix references for local variables and parameters 2026-05-30 21:55:01 +05:30
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
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 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
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
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
25harsh f185bc404f [SwiftSyntaxCodeActions] Moved syntactic code actions into a new module 2026-05-11 11:10:40 +05:30
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 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 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 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
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
Steffeeen aa3497e96c Rename DocumentSnapshot.absolutePositionRange() to positionRange()
This matches the naming of the `position` and `absolutePosition`
methods.
2026-04-07 10:47:59 +02:00
Rintaro Ishizaki df14928358 Merge pull request #2553 from Tabonx/convert-comment-to-doc-comment
Add ConvertCommentToDocComment refactoring action
2026-03-31 09:53:26 -07:00
Pavel Kroupa f22a8f8475 Add code action to CMakeLists 2026-03-23 17:24:18 +01:00
Rintaro Ishizaki a9566ac183 [LSPAny] Replace manual LSPAnyCodable impl with Codable-backed default
Remove hand-written `init?(fromLSPDictionary:)` / `encodeToLSPAny()`
from LSPAnyCodable types, relying instead on the default implementations
backed by `LSPAnyEncoder`/`LSPAnyDecoder`
2026-03-22 08:01:17 -07:00
Rintaro Ishizaki 894496e9be Merge pull request #2549 from Tabonx/feature/codeAction-resolve-support 2026-03-22 06:11:21 -07:00
Pavel Kroupa 394bc3e19e Merge branch 'main' into convert-comment-to-doc-comment
# Conflicts:
#	Tests/SourceKitLSPTests/CodeActionTests.swift
2026-03-21 21:30:43 +01:00
Pavel Kroupa 8639c19347 Add codeAction/resolve support 2026-03-21 10:38:44 +01:00
Alex Hoppen b7a0ab98dd Merge pull request #2458 from ahoppen/report-convert-to-stored
Report convert-to-computed and convert-to-stored refactoring actions
2026-03-16 08:46:18 +01:00
Pavel Kroupa a58a89c31b Add ConvertCommentToDocComment refactoring action 2026-03-15 20:32:54 +01:00
Alex Hoppen d13471cc74 Merge pull request #2485 from Steffeeen/semantic-tokens
Only create semantic tokens in cases where they are actually needed
2026-03-15 13:33:15 +01:00
Steffeeen dc2da5cc58 Add reportSyntacticHighlightInSemanticTokens config option
When this option is set to `true` the results for
`textDocument/semanticTokens` include semantic tokens for syntactic
highlighting obtained from swift-syntax. If this option is set to
`false` only the semantic tokens obtained from SourceKit are included.
This option defaults to `false`.
2026-03-13 17:02:47 +01:00
Rintaro Ishizaki c752c1832b Merge pull request #2500 from rintaro/test-discovery-combine
[TestDiscovery] Prefer syntactic scan results over semantic index
2026-03-09 13:44:36 -07:00
Rintaro Ishizaki 26f8efed5f [TestDiscovery] Use file modification time to filter semantic index
Instead of querying the index twice (once for up-to-date files, once for
outdated ones), collect file modification timestamps during the syntactic
scan phase and use them to filter a single semantic index query.
For files that don't support syntactic scans, use the semantic index
results even if outdated.

Also extracts symlink-aware mtime resolution into URL.fileModificationDate
and exposes snapshotHasInMemoryModifications(_:) on DocumentManager.
2026-03-06 15:33:19 -08:00
Rintaro Ishizaki 955a400f6f Merge pull request #2501 from loveucifer/fix/pass-experimental-features-to-swift-parser
Pass experimental features to SwiftParser once we have build settings
2026-03-06 15:28:40 -08:00
Rintaro Ishizaki 1c99daabef [TestDiscovery] Prefer syntactic scan results over semantic index
Previously, test discovery used the semantic index as the primary
source and fell back to the syntactic index only for files where the
semantic index was out-of-date. This meant test locations came from the
semantic index, which only records a point position rather than the
full symbol range.

Flip the priority: use syntactic scan results as the primary source
(which have correct location ranges) and supplement with semantic index
results. The semantic results are range-fixed via
'textDocument/documentSymbol' before being returned.

This logic is unified into a single 'combineTests' helper shared by
both 'workspaceTests' and 'documentTests'.

Also fix 'SyntacticSwiftXCTestScanner' to emit extensions as proper
'AnnotatedTestItem' nodes (with 'isExtension: true') rather than a flat
list of methods, so extension test methods are correctly merged into
their class via 'mergingTestsInExtensions'. The class and extension
visitors are unified through a shared 'handleClassOrExtension' helper.
2026-03-04 16:58:21 -08:00
Alex Hoppen ce86aae504 Merge pull request #2483 from ahoppen/explicitly-close-index 2026-03-01 08:18:19 +01:00
Alex Hoppen ad4b87ce6b Merge pull request #2467 from Steffeeen/selection-range 2026-03-01 08:17:54 +01:00
loveucifer d2736c130e minor fix 2026-03-01 00:33:17 +05:30
Alex Hoppen 07f8686456 Sort code actions in SyntaxRefactoringCodeActionProvider alphabetically
Also move them to the end of the file, where it’s easier to extend the list in the future.
2026-02-28 19:32:19 +01:00
Alex Hoppen 8920d78f3b Report convert-to-computed and convert-to-stored refactoring actions
These were implemented in swift-syntax but never added to the list of refactoring actions reported by SourceKit-LSP.

While at this, also fix two other things:
- Report an error if we non-exhaustively checked that we had an empty array of code actions, since this was a tautology
- Allow ignoring code actions that we don’t want to check for (needed to write sensible exhaustive checks)
- Fixed a bug that caused convert-to-zero-parameter-function to be reported when on a return statement in an accessor block
2026-02-28 19:31:36 +01:00
Alex Hoppen bc58ce982b Add infrastructure to allow easier implementation of code actions that have a non-Void context
Not really needed at the moment but may become useful in the future.
2026-02-28 19:13:32 +01:00
loveucifer 091e802f1c Pass experimental features to SwiftParser using build settings
This commit adds support for passing experimental features to SwiftParser through build settings. It includes:
- Changes to SwiftLanguageService.swift to handle experimental features
- Updates to SyntaxTreeManager.swift to pass these features to the parser
- E2E tests verifying experimental features work with the SyntaxTreeManager
2026-02-28 09:19:43 +05:30
Steffeeen d748f80896 Implement support for textDocument/selectionRange
This enables hierarchical selection expansion in supported editors.

Selection ranges are computed from the AST by walking upward from the
smallest enclosing node to the root. This is implemented by AST nodes
conforming to the `SelectionRangeProvider` protocol. Most nodes use a
default implementation which returns the node's `trimmedRange`.
Other nodes are special-cased to adjust the returned selection ranges
based on other factors.
2026-02-26 09:15:01 +01:00
Karan 7435345133 Add RemoveRedundantParentheses refactoring action
Signed-off-by: Karan <karanlokchandani@protonmail.com>
2026-02-23 01:07:05 +05:30
Alex Hoppen 2f472da57b Merge pull request #2443 from loveucifer/multiline-string-interpolation
add support for multi-line string literals when converting string concatenation to string interpolation
2026-02-16 15:51:23 +01:00
Alex Hoppen 425e1322a1 Explicitly close the index when shutting down SourceKit-LSP
`IndexStoreDB` moves its index to the `saved` directory when it is deallocated. Because `IndexStoreDB` is primarily owned by `UncheckedIndex`, we rely on deallocating this object to save the index store. This is fairly brittle because various parts of the codebase may hold transient references to that object as reported in https://github.com/swiftlang/sourcekit-lsp/issues/2455#issuecomment-3873561003.

Explicitly remove the reference from `UncheckedIndex` to `IndexStoreDB`. While this still isn’t perfect because other parts of the code base may hold references to `IndexStoreDB` but those should be a lot rarer, resulting in a more consistent closing of the index.
2026-02-15 18:02:53 +01:00
loveucifer 5b4af90a81 Apply .indented(by:) 2026-02-15 21:53:01 +05:30
loveucifer f1f46f586f Add TypeDefinition.swift to CMakeLists.txt 2026-02-10 09:23:55 +05:30
loveucifer e1f1e08cc9 some fixes 2026-02-09 16:44:58 +05:30