Commit Graph

147 Commits

Author SHA1 Message Date
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
loveucifer e786a1450c swift format 2026-02-08 23:25:25 +05:30
loveucifer 6028898c13 Optimize index usage for typeDefinition and inlay hint resolve requests. 2026-02-08 23:20:18 +05:30
loveucifer c6e54fb46a Fix multiline string support in string concatenation to interpolation refactoring 2026-02-05 13:11:40 +05:30
loveucifer 250f6f62aa Fix multiline string indentation stripping and remove duplicate test 2026-01-30 02:58:25 +05:30
loveucifer cccdde295c Use any LanguageService instead of closures 2026-01-30 02:47:52 +05:30
loveucifer cf56bf2ce6 Address PR review feedback
- Add DefinitionLocations.swift to CMakeLists.txt
- Add proper documentation comments to functions in DefinitionLocations.swift
- Make indexToLSPLocation private since it's only used within the file
- Revert unrelated comment changes in InlayHintResolve.swift
- Use .only instead of .first in InlayHintResolve to avoid ambiguous types
- Refactor TypeDefinition.swift to use cleaner control flow with guard/else
- Add test for jumping to generated interface (String)
2026-01-19 17:12:33 +05:30
loveucifer 4770e0c73e address reviewer feedback: use IndentationRemover for trivia-only indentation handling
- Replace custom stripIndentation with IndentationRemover
- Update test expectations to preserve content indentation (trivia-only)
- Add clarifying comment for trailing trivia removal
- Use Swift commas in conditions
- Simplify trailing trivia removal code
2026-01-19 16:44:37 +05:30
loveucifer e0dcca98c4 merge upstream main 2026-01-18 16:37:39 +05:30
loveucifer 0e52fede00 unify definition locations 2026-01-18 16:28:55 +05:30
loveucifer 82a7726297 fix type annotation 2026-01-17 16:17:59 +05:30
loveucifer b7e76ff90e unify typeDefinition 2026-01-17 16:17:59 +05:30
loveucifer 2a360c046e address comments 2026-01-17 16:17:59 +05:30
loveucifer 4d08603e30 fix trivia handling 2026-01-17 15:12:27 +05:30
loveucifer d8b8d71fae Implement textDocument/typeDefinition request 2026-01-16 18:13:12 +05:30
Alex Hoppen 61ba0c92a4 Merge pull request #2436 from loveucifer/inlay-hint-go-to-definition 2026-01-16 13:16:45 +01:00
Alex Hoppen 155b0ce003 Merge pull request #2432 from ahoppen/suppress-superseded-sourcekitd-refactorings
Don’t show sourcekitd refactoring actions that have been superseded by swift-syntax refactoring actions
2026-01-16 07:42:33 +01:00
loveucifer 4ece7f9eea fix trailing trivia handling 2026-01-15 08:02:34 +05:30