Commit Graph

50 Commits

Author SHA1 Message Date
Adam Ward
308375a135 Move syntactic index back to Workspace 2025-12-08 15:16:36 -05:00
Adam Ward
9602433d2a Add new workspace/playgrounds request 2025-12-08 15:16:36 -05:00
Owen Voorhees
f04b971726 Adopt swift-tools-protocols 2025-10-31 14:11:11 -07:00
Ahmed Elrefaey
a5854f4ecf Add signature help LSP request support (#2250)
Depends on https://github.com/swiftlang/swift/pull/83378

---

Adds support for the LSP signature help request.

> [!NOTE]
> As of https://github.com/swiftlang/swift/pull/83378, SourceKitD still
doesn't separate parameter documentation from the signature
documentation and thus parameters don't have their own separate
documentation. This should just work once SourceKitD implements this
functionality and we'll only need to modify the tests.
2025-09-05 14:52:56 +01:00
Alex Hoppen
ef665080c9 Explicitly implement syntacticTestItems in DocumentationLanguageService
`SyntacticTestIndex` queries all language services for a document for its syntactic test items. This caused `syntacticDocumentTests not implemented in DocumentationLanguageService` to be logged for every Swift file in the project. Remove the default implementation of `syntacticDocumentTests` in `LanguageService` and instead provide an implementation that returns an empty array in `DocumentationLanguageService`.

While at it, also log the files for which unimplemented methods are called on `LanguageService`. This makes it easier to dermine why they are called.
2025-09-01 16:52:31 +02:00
Matthew Bastien
58096eb822 cache snapshots opened in sourcekitd by textDocument/doccDocumentation requests 2025-08-27 15:30:50 +02:00
Alex Hoppen
4040a5e4ac Add default implementations to LanguageService for methods that are not expected to be implemented by all language services
With the introduction of secondary language services, we don’t expect every language service to implement every request anymore. To simplify the addition of language services like `DocumentationLanguageService` add default implementations for methods that satisfy the following criteria:
 - `SourceKitLSPServer` does not expect side effects to happen when they are called
 - The method can throw or there is a reasonable default value
 - It is reasonable to expect that not all language services need to implement it
2025-08-26 16:10:36 +02:00
Alex Hoppen
64fe439f24 Make DocumentationLanguageService the only module that imports DocCDocumentation 2025-08-21 10:10:54 +02:00
Alex Hoppen
1ca9780cd7 Merge pull request #2248 from ahoppen/lang-service-init-not-failable
Make `LanguageService` initializer non-failable
2025-08-20 06:51:27 +02:00
Alex Hoppen
08faa197af Make LanguageService initializer non-failable 2025-08-20 00:21:45 +02:00
Alex Hoppen
22fae21153 Handle documentation requests for Swift files in DocumentationLanguageService
This cleanly separates the responsibilities for handling documentation from those of handling Swift files. It also simplifies providing docc support for clang because we just need to implement the two `symbolGraph` methods in `ClangLanguageService` and can re-use the remaining infrastructure from `DoccLanguageService`.
2025-08-20 00:20:27 +02:00
Alex Hoppen
615dead31c Remove a couple references to DocCDocumentation 2025-08-17 22:22:47 +02:00
Alex Hoppen
c14f5dd7fd Move SwiftLanguageService into its own module 2025-08-14 11:12:31 +02:00
Alex Hoppen
7f4f92e5bd Rename build system to build server in most cases
The term *build system* predated our wide-spread adoption of BSP for communicating between SourceKit-LSP to the build system and was never really the correct term anyway – ie. a `JSONCompilationDatabaseBuildSystem` never really sounded right. We now have a correct term for the communication layer between SourceKit-LSP: A build server. Rename most occurrences of *build system* to *build server* to reflect this. There are unfortunately a couple lingering instances of *build system* that we can’t change, most notably: `fallbackBuildSystem` in the config file, the `workspace/waitForBuildSystemUpdates` BSP extension request and the `synchronize-for-build-system-updates` experimental feature.
2025-08-02 08:45:01 +02:00
Matthew Bastien
a8eae3c6d8 remove protocols from DocCDocumentation module 2025-04-16 14:44:12 -04:00
Matthew Bastien
49b3f531eb move SwiftDocC related functionality into its own module 2025-04-16 14:44:11 -04:00
Matthew Bastien
39bf4852b0 handle Markdown and Tutorial files in textDocument/doccDocumentation 2025-04-16 14:44:11 -04:00
Alex Hoppen
1cfa8db1d8 Require Swift 6 to build SourceKit-LSP
This significantly cleans up our `import` statements
2025-03-07 08:05:49 -08:00
Alex Hoppen
f6b83dbb1e Support completionItem/resolve to compute documentation of code completion item
Fixes #1935
2025-02-05 10:26:44 -08:00
Alex Hoppen
98b1294ad9 Support opening documents within the same workspace with sourcekitd/clangd from different toolchains
rdar://142909783
2025-01-24 22:32:05 -08:00
Alex Hoppen
31b1909ce1 Allow injection of build systems into SourceKitLSP
This allows us to clean up the creation of `TestBuildSystem` a little bit because the tests can create `TestBuildSystem` instead of retrieving it from the `BuildSystemManager`.

rdar://142906050
2025-01-15 15:57:21 -08:00
MahdiBM
a2eb7b9b2c Handle on-type formatting requests 2024-11-21 16:07:22 +03:30
MahdiBM
8f3253d773 support range formatting 2024-11-08 15:25:48 +03:30
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
014ebbeee5 Close code completion session when a document’s dependencies are updated
Even after sending the `dependencyUpdated` request to sourcekitd, the code completion session has state from before the AST update. Close it and open a new code completion session on the next completion request.
2024-09-17 15:06:20 -07:00
Lokesh T R
0522e1aff6 Allow macro expansions to be viewed through GetReferenceDocumentRequest instead of storing in temporary files 2024-07-31 19:03:12 +05:30
Alex Hoppen
66f2d86775 Rename SKCore to BuildSystemIntegration 2024-07-25 09:11:13 -07:00
Alex Hoppen
6d34d70883 Split SourceKitLSPOptions out of SKCore
This only leaves build system functionality in SKCore, which allows us to rename SKCore.
2024-07-25 09:11:13 -07:00
Alex Hoppen
cfe18f1256 Split toolchain-related functionality out of SKCore 2024-07-25 09:11:13 -07:00
Paul LeMarquand
293f638186 Add Run/Debug CodeLens Support
Adds a response to the textDocument/codeLens request that returns two
code lenses on the `@main` attribute of an application.

The LSP documentation breaks out the code lens requests into a
[`Code Lens Request`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeLens)
and a
[`Code Lens Resolve Request`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeLens_resolve),
stating this is for performance reasons. However, there is no intensive
work we need to do in order to resolve the commands for a CodeLens;
we know them based on context at the time of discovery. For this reason
we return resolved lenses with Commands for code lens requests.

A missing piece is only returning code lenses if the file resides in an
executable product. To my knoledge Libraries and Plugins can't have an
`@main` entrypoint and so it doesn't make sense to provide these code
lenses in those contexts.

Some guidance is required on how to best determine if the textDocument
in the request is within an executable product.

`testCodeLensRequestWithInvalidProduct` asserts that no lenses are
returned with the `@main` attribute is on a file in a `.executable`, and
is currently failing until this is addressed.
2024-07-21 07:37:00 -04:00
Alex Hoppen
2877675bd5 Adopt package access level
Change a l public declarations to the `package` access level, accept for:
- The `LanguageServerProtocol` module
- The `BuildServerProtocol` module
- `InProcessClient.InProcessSourceKitLSPClient`
- `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public)

Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be:
- Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI`
- Use `@testable` import in the test targets and mark the methods as `internal`

Resolves #1315
rdar://128295618
2024-07-19 09:54:30 -07:00
Louis Qian
3be034233b fix: SwiftLanguageService instead of ClangLanguageService
fix!: remove `documentManager` property

fix!: remove `documentManager` in constructor

fix: added documentManager as a computed Property

fix: remove old documentmanager resetting step

fix!: get throws instead of crashing server

fix: throw ResponseError instead of NSError

fix: adding try & orLog where necesary

fix: refined orLog usage

style: ran swift-format

fix: document being opened twice

fix(DocumentManager): remove unwanted comments

lint: ran swift format
2024-07-03 23:48:49 -05:00
Kai Lau
eb6f919b5e removed OpenGeneratedInterfaceRequest
deleted OpenInterfaceRequest.swift and moved GeneratedInterfaceDetails to LanguageService.swift
replaced usages by passing its members as parameters directly, refactored usage of TextDocumentIdentifier to DocumentURI
removed from Messages.builtinRequests
removed from SwiftInterfaceTests
removed from Documentation/`LSP Extensions.md`
removed from Sources/LanguageServerProtocol/CMakeLists.txt
2024-07-01 15:14:44 -07:00
Alex Hoppen
d1cddb8c41 Allow configuring of SourceKit-LSP’s options using .sourcekit-lsp configuration files
The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options.

The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP.

For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files.

Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit.
2024-06-27 17:36:16 +02:00
Alex Hoppen
518aac47d5 Merge pull request #1459 from ahoppen/testable-methods
Change methods that were only public for testing purposes to be `@_spi(Testing)`
2024-06-12 09:26:45 -07:00
Alex Hoppen
97ef5f46d7 Merge pull request #1460 from ahoppen/generated-interface-improvements
A couple of improvements for generated interfaces
2024-06-11 19:06:22 -07:00
Alex Hoppen
33d803f1d1 Change methods that were only public for testing purposes to be @_spi(Testing)
Fixes #876
Fixes #877
rdar://116705648
rdar://116705669
2024-06-11 19:03:26 -07:00
Alex Hoppen
202d723c77 When performing jump-to-definition on a method implementing a protocol requirement, jump to the requirement
rdar://129412482
2024-06-08 10:29:18 -07:00
Alex Hoppen
2a0f8c79b9 A couple of improvements for generated interfaces
- Rename methods to highlight that we’re talking about generated interfaces here, not `.swiftinterface` files
- Don’t open the generated interface in `documentManager`. Opening documents in `documentManager` should only be done by the `textDocument/didOpen` notification from the LSP client. Otherwise we might indefinitely keep the document in the document manager
- After getting the generated interface from sourcekitd, close the document in sourcekitd again. We don’t provide semantic functionality in the generated interface yet, so we can’t interact with the generated interface path. Before, we left it open in sourcekitd indefinitely.
- A couple of code simplifications.

Fixes #878
rdar://116705653
2024-06-08 07:56:19 -07:00
Alex Hoppen
d04bf84893 Don’t cancel in-progress diagnostic generation when calling DiagnosticReportManager.removeItemsFromCache
This was causing a non-deterministic test failure: When target preparation finishes while a diagnostic request is in progress, it will re-open the document, which calls `DiagnosticReportManager.removeItemsFromCache` for that document’s URI. With the old implementation, we would thus cancel the diagnostics sourcekitd request and return a cancelled error to the diagnostics LSP request.

While doing this, I also realized that there was a race condition: Document re-opening would happen outside of the SourceKit-LSP message handling queue and could thus run concurrently to any other request. This means that a sourcekitd request could run after `reopenDocument` had closed the document but before it was opened again. Introduce an internal reopen request that can be handled on the main message handling queue and thus doesn’t have this problem
2024-06-03 17:51:23 -07:00
Alex Hoppen
113bd0dbec Move syntactic XCTest scanner to a separate file
The swift-testing scanner is in its own file and the XCTest scanner should be as well, for consistency.

rdar://126529507
2024-06-01 10:23:32 -07:00
Lokesh.T.R
087ea64ed3 Rename note to notification throughout the codebase wherever necessary 2024-05-29 17:58:04 +00:00
Alex Hoppen
7e7df04b48 Make the SourceKitLSP module build in Swift 6 mode
Swift 6 mode didn’t find any notable data races. But it’s good to know Swift 6 will prevent future ones.
2024-05-13 21:28:42 -07:00
Paul LeMarquand
e740bb3394 Dont expose isExtension on TestItem 2024-05-08 14:30:16 -04:00
Alex Hoppen
6a9a95f9fd Fix test discovery for Objective-C XCTests
There were two issues with Objective-C XCTest discovery:
1. We were relying on syntactic test discovery after a document is edited. But since we don't have syntactic test discovery for Objective-C tests, this meant that all tests would disappear as a document got edited. Until we get syntactic test discovery for Objective-C, use the semantic index to discover tests, even if they are out-of-date.
2. We were assuming that the `DocumentSymbols` request returned `[DocumentSymbol]` to find the ranges of tests. But clangd returns the alternative `[SymbolInformation]`, which meant that we were only returning the position of a test function’s name instead of the test function’s range.

rdar://126810202
2024-05-06 08:17:09 -07:00
Alex Hoppen
0685ee7773 Enhance syntactic test discovery with information from the semantic index
When the semantic index is out-of-date, we currently purely rely on the syntactic index to discover tests and completely ignore data from the semantic index. This may lead to confusing behavior. For example if you have

```
class MightInheritFromXCTestCaseOrNot {}

class MyClass: MightInheritFromXCTestCaseOrNot {
  func testStuff() {}
}
```

Then we don’t return any tests when the semantic index is up-to-date. But once the file is modified (either on disk or in-memory), we purely rely on the syntactic index, which reports `testStuff` as a test method. After a build / background indexing finishes, the test method disappears again.

We can mitigate this problem as follows: If we have stale semantic index data for the test file, for every test method found by the syntactic index, check if we have an entry for this method in the semantic index. If we do, but that entry is not marked as a test class/method, we know that the semantic index knows about this method but decided that it’s not a test method for some reason. So we should ignore it.

rdar://126492948
2024-05-02 21:10:46 -07:00
Alex Hoppen
67a73f47c1 Return document tests in a hierarchical format
Same as for workspace tests, instead of returning a flat list of symbols, return a hierarchical structure.
2024-04-05 20:18:46 -07:00
Alex Hoppen
fdb8bab22c Implement a syntactic test discovery fallback for XCTests written in Swift
If the index for a given file is not up-to-date, perform a syntactic scan for tests within it.

This should allow editors to run the `textDocument/tests` request while the user is editing a file to scan it for test cases.
2024-03-27 12:42:58 +01:00
Alex Hoppen
0ea35886e8 Rename sourceKitServer -> sourceKitLSPServer
I forgot to rename the variables when renaming the class from `SourceKitServer` to `SourceKitLSPServer`.
2024-03-20 22:51:28 +01:00
Alex Hoppen
ed5c7e2e39 Rename language specific language services
The naming was quite inconsistent here. Let’s rename these to `LanguageService` to highlight that they belong together.

- ToolchainLanguageServer -> LanguageService
- SwiftLanguageServer -> SwiftLanguageService
- ClangLanguageServerShim -> ClangLanguageService
2024-03-20 22:51:28 +01:00