Commit Graph

364 Commits

Author SHA1 Message Date
Alex Hoppen
73016af24e Make workspace/synchronize a non-experimental request
This request is generally useful, not only for tests within SourceKit-LSP but also:
- In editor tests that want to test the integration with SourceKit-LSP
- In code analysis tools that want to gather project information using SourceKit-LSP and need an up-to-date index for that.

Remove the experimental feature guard from `workspace/_synchronize`, consequently rename it to `workspace/synchronize` and only guard the `buildServerUpdates` option on the synchronize request by an experimental feature because its long-term usefulness is still not fully understood yet.
2025-03-26 10:08:20 -07:00
Alex Hoppen
5fba1699bd Generalize PollIndexRequest and BarrierRequest into a single SynchronizeRequest
This new request also allows us to wait for build system updates without waiting for background indexing to finish.
2025-03-12 14:25:50 -07:00
Alex Hoppen
8aa8fa0ff8 Remove offensive terms from the codebase 2025-03-07 13:58:02 -08: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
2a1fd10295 Add an experimental LSP request to return the output paths for all files in a target 2025-03-06 08:30:47 -08:00
Alex Hoppen
655a93f05a Add structure to the index logs
When the client supports it, communicate the structure of tasks that were stared during background indexing or by the build server to the client. If there are multiple operations happening in parallel, this allows the client to display them in separate log tracks instead of interspersing them with the emoji prefixes like we do today.
2025-03-04 16:36:26 -08:00
Alex Hoppen
3fc3616988 Merge pull request #2019 from ahoppen/sourcekitoptions-improvements
Small improvements to `workspace/_sourceKitOptions` request
2025-02-28 15:35:55 -08:00
Alex Hoppen
112252632d Make response of workspace/_sourceKitOptions request non-optional
The response was not specified as being optional and shouldn’t be.
2025-02-27 19:03:50 -08:00
Alex Hoppen
6a1d923f5b Add a request to check if SourceKit-LSP is currently performing any indexing 2025-02-27 12:52:28 -08:00
Alex Hoppen
f4e015b3c0 Merge pull request #1988 from ahoppen/sourcekitoptions
Add an experimental request to return the build settings that SourceKit-LSP uses to process a file
2025-02-26 16:06:20 -08:00
Alex Hoppen
9496b49c72 Add an experimental request to return the build settings that SourceKit-LSP uses to process a file
This can be useful to IDEs that want to perform some additional semantic processing of source files, which requires knowledge of a file’s build settings.
2025-02-26 09:12:47 -08:00
Alex Hoppen
db792c536f Add a send method to InProcessSourceKitLSPClient and Connection in which the client specifies the request ID 2025-02-26 08:41:30 -08:00
Alex Hoppen
baa3b70f7c A couple refinements to the window/didChangeActiveDocument notification
- Clarify that this must only be called with documents that are open in SourceKit-LSP and add a check for that.
- Allow sending `null` to indicate that no SourceKit-LSP document is currently active.
- Cancel preparation tasks for other workspaces that don’t contain the currently active document.
2025-02-24 13:58:19 -08:00
Alex Hoppen
1d1f1fb3dc Merge pull request #1989 from ahoppen/didchangactivedocument
Add notification to inform SourceKit-LSP about the currently active document
2025-02-23 21:27:23 -08:00
Alex Hoppen
f1aeb6c196 Add an experimental request to pause background indexing
This request allows IDEs to disable SourceKit-LSP’s background indexing functionality when it requires all compute resources for other, more interactive, tasks.
2025-02-21 08:09:34 -08:00
Alex Hoppen
4d00c9089b Add notification to inform SourceKit-LSP about the currently active document
SourceKit-LSP prepares the currently active file for editor functionality and currently infers the currently active document from whichever received the last `TextDocumentRequest`.

If an editor is capable of doing so, it should be able to report the document that the user currently has focused so that SourceKit-LSP does not have to infer this information from other requests.

Also clean up some handling code for experimental capabilities.
2025-02-20 12:29:30 -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
Matthew Bastien
6675d275fe address review comments 2025-01-17 11:11:56 -05:00
Matthew Bastien
bf8e86f752 add encoding and decoding tests 2025-01-17 11:11:55 -05:00
Matthew Bastien
5c3136694f use built-in LSP ResponseError with code RequestFailed for errors 2025-01-17 11:11:55 -05:00
Matthew Bastien
0a95899dd1 make position optional 2025-01-17 11:11:55 -05:00
Matthew Bastien
f03ae0bb88 rename request to textDocument/doccDocumentation 2025-01-17 11:11:55 -05:00
Matthew Bastien
d4b63a2af5 add textDocument/convertDocumentation request to SourceKit-LSP 2025-01-17 11:11:54 -05:00
Alex Hoppen
03d58e8415 Normalize Windows drive letter to be uppercase
VS Code spells file paths with a lowercase drive letter, while the rest of Windows APIs use an uppercase drive letter. Normalize the drive letter spelling to be uppercase.

Fixes #1855
rdar://141001203
2024-12-10 16:16:27 -08:00
Matthew Bastien
9f3de1b21e mark the tutorial language as a LSP extension 2024-12-05 14:24:31 -05:00
Matthew Bastien
8fd30908e7 handle *.md and *.tutorial files for Swift DocC 2024-12-05 11:18:49 -05:00
Alex Hoppen
c85dd7c5e4 Merge pull request #1843 from ahoppen/empty-path-crash
Don’t crash when opening a file with an empty path
2024-12-03 14:39:55 -08:00
Alex Hoppen
14b8588221 Don’t crash when opening a file with an empty path
Fixes #1739
rdar://137886470
2024-11-22 15:59:07 +01:00
Alex Hoppen
e073a01bbc Reply with null to shutdown request
The LSP spec says the result of `shutdown` is `null`, not an empty object.

Fixes #1733
rdar://137886488
2024-11-22 15:52:27 +01:00
Alex Hoppen
5c7d495ebd Merge pull request #1808 from ahoppen/member-import-visibility
Adopt `MemberImportVisibility`
2024-11-07 15:38:05 -08:00
Alex Hoppen
06f58db5c8 Use build/taskStart, build/taskProgress and build/taskFinish to communicate progress from a BSP server to the client
Instead of defining BSP extensions for `window/workDoneProgress/create` and `$/progress`, we should be able to use the standard `build/taskStart`, `build/taskProgress` and `build/taskFinish` messages to the same effect, as suggested by https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400/9.

Fixes #1783
rdar://138653131
2024-11-06 09:39:09 -08:00
Alex Hoppen
1d7c27bc4b Adopt MemberImportVisibility 2024-11-05 21:04:01 -08:00
Paul LeMarquand
d8b0577465 Fix inadvertent shadowing of ClientCapabilities subtypes
When removing the LanguageServerProtocol namespace from types in
ClientCapabilities (#1734), some types inadvertently started shadowing
themselves. This lead to client initialization errors when the
initialization request couldn't be decoded:

```
type mismatch at params.capabilities.textDocument.completion.completionItemKind.valueSet.Index 0 : Expected to decode Dictionary<String, Any> but found number instead.
```

Disambiguating these inner types in ClientCapabilities fixes decoding.
2024-10-08 12:24:24 -04:00
Alex Hoppen
aa7389c60f Merge pull request #1735 from ahoppen/frozen-messagekind
Mark `MessageDecodingError.MessageKind` as `@frozen`
2024-10-04 15:55:51 -07:00
Alex Hoppen
06f6f8f17b Remove references to the LanguageServerProtocol modules in that module itself 2024-10-02 14:16:33 -07:00
Alex Hoppen
2e61d33645 Mark MessageDecodingError.MessageKind as @frozen 2024-10-02 09:34:49 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
5d1eb73a68 Revert "Add an extra percent encoding layer when encoding DocumentURIs to LSP requests"
This reverts commit b2c17c748d.

The workaround isn’t needed anymore because we have a proper fix in the VS Code extension: https://github.com/swiftlang/vscode-swift/pull/1026
2024-09-10 14:51:28 -07:00
Alex Hoppen
b4d04ce983 Introduce a BuiltInBuildSystemAdapter that can be used to transition BuildSystem to a type that implements BSP 2024-09-09 16:31:00 -07:00
Alex Hoppen
b2c17c748d Add an extra percent encoding layer when encoding DocumentURIs to LSP requests
The URI standard RFC 3986 is ambiguous about whether percent encoding and their represented characters are considered equivalent. VS Code considers them equivalent and treats them the same:

```js
vscode.Uri.parse("x://a?b=xxxx%3Dyyyy").toString() -> 'x://a?b%3Dxxxx%3Dyyyy'
vscode.Uri.parse("x://a?b=xxxx%3Dyyyy").toString(/*skipEncoding=*/true) -> 'x://a?b=xxxx=yyyy'
```

This causes issues because SourceKit-LSP's macro expansion URLs encoded by URLComponents use `=` do denote the separation of a key and a value in the outer query. The value of the `parent` key may itself contain query items, which use the escaped form '%3D'. Simplified, such a URL may look like `scheme://host?parent=scheme://host?line%3D2`.

But after running this through VS Code's URI type `=` and `%3D` get canonicalized and are indistinguishable.

To avoid this ambiguity, always percent escape the characters we use to distinguish URL query parameters, producing the following URL: `scheme://host?parent%3Dscheme://host%3Fline%253D2`.
2024-08-19 21:41:50 -07:00
Alex Hoppen
0bb605d641 Remove a few workarounds that should no longer be needed 2024-08-07 10:00:04 -07:00
Alex Hoppen
50a28bb86a Change FIXME and TODO comments to always have an associated issue
Do one of the following for every `FIXME` or `TODO` comment
- Add an issue that tracks the task
- Remove the comment if we are not planning to address it
2024-08-07 10:00:04 -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
Paul LeMarquand
960317b6cc Enumerate supported code lens commands 2024-07-21 07:40:17 -04:00
Paul LeMarquand
3e8f413b6b Let client supply code lenses it can run
As part of its initialization options the client can pass a
textDocument/codeLens object that lists the supported commands the
client can handle.

It is in the form of a dictionary where the key is the lens name
recognized by SourceKit-LSP and the value is the command as recognized
by the client.

```
initializationOptions: {
    "textDocument/codeLens": {
        supportedCommands: {
            "swift.run": "clientCommandName_Run",
            "swift.debug": "clientCommandName_Debug",
        }
    }
}
```
2024-07-21 07:37:29 -04: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
Paul LeMarquand
b288767675 Add TriggerReindexRequest to buildinRequests
`TriggerReindexRequest` was missing from the list of builtinRequests,
which caused the LSP to respond with a methodNotFound error when it
recieved a `workspace/triggerReindex` request.
2024-07-10 11:57:06 -04:00
Lokesh T R
0221475b70 Implement PeekDocumentsRequest and update ShowDocumentRequest.
-------------------------------------------------------------------------------

This implements an LSP Extension `PeekDocumentsRequest` to let `ExpandMacroCommand` to open the macro expansions in a "peeked" editor window.
For this to work, the client has to pass "workspace/peekDocuments" enabled to `ClientCapabilities.experimental` and the client should handle the `PeekDocumentsRequest` and show the expansions in a "peeked" editor window.

PR to support the above capability in the "Swift for VS Code" Extension: https://github.com/swiftlang/vscode-swift/pull/945
The "Swift for VS Code" extension cannot send the client capability, so it instead passes the same through `initializationOptions` in the `InitializeRequest`.

For editors which doesn't support this capability, `sourcekit-lsp` sends a `ShowDocumentRequest`.
The `ShowDocumentRequest` is updated to show all the macro expansions in a single generated file. Moreover, its folder structure is updated to use hex string of MD5 hash of concatenation of buffer names of expansions.

Fixes https://github.com/swiftlang/vscode-swift/issues/564
Fixes https://github.com/swiftlang/sourcekit-lsp/issues/1498 ( rdar://130207754 )
2024-07-03 15:32:40 +05:30
Alex Hoppen
ef2dc17806 Merge pull request #1543 from ahoppen/time-out-sourcekitd
Add a maximum duration for sourcekitd requests
2024-07-03 01:48:37 +02:00
Alex Hoppen
191d366a2c Add a maximum duration for sourcekitd requests
VS Code does not cancel semantic tokens requests. If a source file gets into a state where an AST build takes very long, this can cause us to wait for the semantic tokens from sourcekitd for a few minutes, effectively blocking all other semantic functionality in that file.

To circumvent this problem (or any other problem where an editor might not be cancelling requests they are no longer interested in) add a maximum request duration for SourceKitD requests, defaulting to 2 minutes.

rdar://130948453
2024-07-02 22:47:27 +02:00