1295 Commits

Author SHA1 Message Date
Alex Hoppen
ce86aae504 Merge pull request #2483 from ahoppen/explicitly-close-index 2026-03-01 08:18:19 +01:00
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
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
6028898c13 Optimize index usage for typeDefinition and inlay hint resolve requests. 2026-02-08 23:20:18 +05:30
loveucifer
d73aba2c39 Remove duplicate definitionLocations and call shared function 2026-01-31 13:12:51 +05:30
loveucifer
cccdde295c Use any LanguageService instead of closures 2026-01-30 02:47:52 +05:30
loveucifer
5ee63b7b0c Deduplicate helper functions between DefinitionLocations and SourceKitLSPServer 2026-01-19 17:29:23 +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
0e52fede00 unify definition locations 2026-01-18 16:28:55 +05:30
loveucifer
b7e76ff90e unify typeDefinition 2026-01-17 16:17:59 +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
loveucifer
0695d3c67c Remove typeDefinition remnants 2026-01-12 06:02:46 +05:30
loveucifer
3630ab970c Address review feedback for inlay hint go-to-definition
- Use cursorInfo USR lookup instead of index (more accurate)
- Add document version tracking to reject stale resolve requests
- Make InlayHintResolveData conform to LSPAnyCodable
- Reference swiftlang/swift#86432 for mangled type workaround
- cursorInfoFromTypeUSR takes DocumentSnapshot for version safety
- Remove TypeDefinition.swift (defer to follow-up PR)
- Remove unnecessary comments
- Tests work without index
2026-01-10 07:00:43 +05:30
Alex Hoppen
2d8a44af76 Merge pull request #2422 from loveucifer/fix-language-service-shutdown-2211 2026-01-09 08:46:25 +01:00
loveucifer
27cf04e2ed Implement textDocument/typeDefinition request (#548)
Add support for the textDocument/typeDefinition LSP request, which
finds the type of the symbol at a given position and returns the
location of that type's definition.

This uses the same type definition lookup mechanism as the inlay hint
resolution feature, which queries cursorInfo for the new type
declaration location fields (typeDeclFilePath/Line/Column) with
fallback to index lookup using typeDeclUsr.

Fixes #548
2026-01-08 21:10:47 +05:30
loveucifer
27b536d612 format 2026-01-08 18:36:50 +05:30
loveucifer
2019ab711a mark SwiftLanguageService as immortal to skip shutdown 2026-01-08 05:01:42 +05:30
loveucifer
8e300ee443 add go-to-definition for inlay hints (#2318)
Implements resolveProvider for inlay hints to enable navigating to type
definitions. When an inlay hint showing a type is resolved, the server
looks up the type's definition location using cursorInfo and the index.

- store variable position in InlayHint.data for resolution
- add inlayHintResolve to LanguageService protocol
- implement resolve handler using cursorInfo and index lookup
- enable resolveProvider: true in capabilities
- add test for resolve functionality

Addresses #2318
2026-01-06 19:35:06 +05:30
loveucifer
eeda468639 test case additon 2026-01-06 17:53:12 +05:30
lijunliang.9819
1b0fe79f93 remove not need label and format code 2026-01-06 15:57:02 +08:00
Kila2
7d92d17c44 Merge branch 'swiftlang:main' into feature/optimize_swift_definition_locations 2026-01-05 22:22:02 +08:00
loveucifer
173784e8b7 Closes #2211
Shut down language services when a workspace is closed

- Added allLanguageServices property to Workspace to get all services it references
- Added shutdownOrphanedLanguageServices to clean up services no longer in use
- When workspace folders are removed, we now shut down their associated language services
- This properly terminates clangd and other language server processes when workspaces close
2026-01-05 08:18:32 +05:30
Alex Hoppen
e35c7a91c9 Merge pull request #2409 from loveucifer/fix-language-services-lifecycle
Fix language services lifecycle management in Workspace
2026-01-04 18:26:35 +01:00
Alex Hoppen
53ac4ca1f2 Merge pull request #2396 from DPrakashh/refactor/document-manager-queue
#1597 - Migrate DocumentManager to use ThreadSafeBox
2026-01-03 20:28:10 +01:00
Alex Hoppen
2aea93dac8 Merge pull request #2385 from loveucifer/feature/file-mapping-all-requests
Extend copied file mapping to all LSP requests returning locations
2026-01-03 19:59:29 +01:00
loveucifer
7437d92453 Fix language services lifecycle management in Workspace
Closes #2209

- Only call `setLanguageServices` from `openDocument` to avoid race conditions
- Remove language services when documents are closed via `removeLanguageServices`
- `SourceKitLSPServer.languageServices` now just returns services without storing them
- Fixed a small typo (serveer -> server) while I was in there

This way the languageServices dictionary only tracks documents that are actually open,
and we avoid race conditions since openDocument is a blocking request for that document.
2026-01-03 17:15:13 +05:30
lijunliang.9819
c40476c191 feat: Fallback to swiftmodule interface when index lookup fails for definition
Currently, `indexBasedDefinition` relies heavily on IndexStoreDB. If a symbol
belongs to a binary framework or a library that hasn't been indexed (but has
module info provided by sourcekitd), the definition request fails or returns
empty results.

This change adds a fallback mechanism in `definitionLocations`. When no
occurrences are found in the index, we check if `systemModule` information
is available on the symbol. If so, we trigger `definitionInInterface` to
generate the textual interface (via `editor.open.interface`) and return that
location.

This improves navigation for binary dependencies (XCFrameworks) and SDKs
partially covered by the index.
2025-12-31 13:07:18 +08:00
loveucifer
74b1ee503f additonal fixes 2025-12-22 18:57:30 +05:30
Divya Prakash
0ca0660d99 Refactor DocumentManager threading for Swift 6
Replaces DispatchQueue with ThreadSafeBox, relaxes T: Sendable constraints, and removes @unchecked Sendable from Document.
2025-12-21 19:26:02 +05:30
loveucifer
8fc9f1ccaf compiler fix 2025-12-21 17:45:50 +05:30
Divya Prakash
d9072850e0 Mark Document as @unchecked Sendable to allow storage in ThreadSafeBox 2025-12-20 09:55:20 +05:30
Divya Prakash
447393e085 Refactor DocumentManager to use ThreadSafeBox for document storage 2025-12-20 09:49:54 +05:30
loveucifer
29b1f4c449 few more fixes 2025-12-19 19:52:17 +05:30
loveucifer
f3237fad74 more and more fixes 2025-12-18 21:03:50 +05:30
loveucifer
21adc24144 some more fixes 2025-12-17 19:57:52 +05:30
loveucifer
d254ce1b5d Update Sources/SourceKitLSP/SourceKitLSPServer.swift
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-16 08:16:07 +05:30
loveucifer
71374c1a04 Update Sources/SourceKitLSP/SourceKitLSPServer.swift
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-16 08:15:41 +05:30
loveucifer
2d8c993712 Address remaining code review feedback
- Refactor supertypes/subtypes to use indexToLSPTypeHierarchyItem helper
  instead of duplicating ~80 lines of TypeHierarchyItem creation code
- Remove unused workaround helper functions (indexToLSPLocation2,
  indexToLSPTypeHierarchyItem2)
- Fix test ordering: use deterministic sorted order instead of Set comparison
- Enable testFindImplementationInCopiedHeader test
- Add implementation request support for C/C++/ObjC functions with
  separate declaration and definition (finds definition when declarations
  exist without definitions at the same location)
- Fix whitespace/indentation issues
2025-12-16 08:11:38 +05:30
Adam Ward
64ac7f3f46 Don't scan for playgrounds if swift-play not in the toolchain 2025-12-11 14:29:20 -05:00
loveucifer
cae01c623d Apply code review fixes for copied file handling
- Remove async from workspaceEditAdjustedForCopiedFiles
- Refactor to use uriAdjustedForCopiedFiles helper
- Update dictionary update logic with +=
- Adjust LocationLink creation to use adjusted ranges
- Ensure selectionRange adjustment in prepareCallHierarchy
- Provide default WorkspaceEdit in ClangLanguageService
- Revert asyncMap to map and remove await in SourceKitLSPServer
- Chain workspace and index retrieval in incomingCalls
- Use indexToLSPCallHierarchyItem and shared helper for CallHierarchyItem
- Fix indentation and remove duplicated detail setting
- Use shared helper for TypeHierarchyItem
- Remove .sort() from expected array in tests
- Enable testFindImplementationInCopiedHeader
- Add await for actor-isolated BuildServerManager calls
2025-12-10 23:47:52 +05:30
loveucifer
70d900e799 Extend copied file mapping to all LSP requests returning locations
This addresses issue #2276 by ensuring that all LSP requests that return source file locations
map copied header files back to their original locations, not just jump-to-definition.

Previously, only the definition request applied this mapping. Now, the following requests
also adjust locations for copied files:
- textDocument/references
- textDocument/implementation
- workspace/symbol
- callHierarchy/prepare
- callHierarchy/incomingCalls
- callHierarchy/outgoingCalls
- typeHierarchy/prepare
- typeHierarchy/supertypes
- typeHierarchy/subtypes

This provides consistent navigation behavior, ensuring users are always taken to the original
source files instead of build artifacts when possible.
2025-12-09 12:52:12 +05:30
Adam Ward
5689018f6b Fix build 2025-12-08 15:16:36 -05:00
Adam Ward
25da841307 Revert deduplicate 2025-12-08 15:16:36 -05:00
Adam Ward
3abbffb61f Deduplicate file events 2025-12-08 15:16:36 -05:00
Alex Hoppen
b033b8393b Address my own review comments 2025-12-08 15:16:36 -05:00
Adam Ward
158529270c Only scan tests if part of a test target 2025-12-08 15:16:36 -05:00
Adam Ward
9ba107d0c5 Fix some failing tests 2025-12-08 15:16:36 -05:00
Adam Ward
3d7fd2101e Rename to SyntacticIndex to acknowledge any language code be scanned 2025-12-08 15:16:36 -05:00
Adam Ward
866bc74874 Don't always assume Swift language when scanning 2025-12-08 15:16:36 -05:00