Commit Graph

180 Commits

Author SHA1 Message Date
Alex Hoppen
9efa7e8cff Merge pull request #1844 from ahoppen/fully-qualified-names
Fully qualify type names in call hierarchy, type hierarchy and workspace symbols
2024-12-03 14:40:13 -08:00
Alex Hoppen
7a95075fcb Merge pull request #1842 from ahoppen/shutdown-null
Reply with `null` to `shutdown` request
2024-12-03 14:39:22 -08:00
Alex Hoppen
eb72e10886 Fully qualify type names in call hierarchy, type hierarchy and workspace symbols
Previously, we didn’t take outer types into account or only took one level of container type into account.

Fixes #1673
rdar://136078089
2024-11-22 21:33:26 +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
MahdiBM
a2eb7b9b2c Handle on-type formatting requests 2024-11-21 16:07:22 +03:30
Alex Hoppen
be546308ca Use URL in many cases where we used AbsolutePath
We made quite a few fixes recently to make sure that path handling works correctly using `URL` on Windows. Use `URL` in most places to have a single type that represents file paths instead of sometimes using `AbsolutePath`.

While doing so, also remove usages of `TSCBasic.FileSystem` an `InMemoryFileSystem`. The pattern of using `InMemoryFileSystem` for tests was never consistently used and it was a little confusing that some types took a `FileSystem` parameter while other always assumed to work on the local file system.
2024-11-18 18:19:48 -08:00
Alex Hoppen
9c84a344c8 Merge pull request #1817 from ahoppen/bsp-review 2024-11-14 08:10:02 -08:00
Alex Hoppen
8c2def8ef9 Rename SKSupport to LanguageServerProtocolExtensions 2024-11-13 16:53:58 -08:00
Alex Hoppen
1aa96fa099 Share common pattern of determining the build system for a workspace and creating it 2024-11-13 10:31:15 -08:00
Alex Hoppen
0fbb6466e7 Make BuildSystemKind a struct and rename to BuildSystemSpec 2024-11-13 10:23:43 -08:00
MahdiBM
8f3253d773 support range formatting 2024-11-08 15:25:48 +03:30
Paul LeMarquand
857cb61c79 XCTests in extensions have no parent ID
If the workspace has been indexed then TestItems are pulled from
indexed symbols. In this code path XCTests defined in extensions don't
have their parent class name appended to their ID.

As a result, when the user freshly opened a test file that contained
XCTests defined in extensions then their IDs would be incorrect.
However as soon as they made a change to the file then the method to
produce the document tests would switch over to getting the tests from
`languageService.syntatciDocumentTests(for:in:)` which does handle
tests in extensions correctly, and the issue would dissapear.
2024-10-30 16:23:26 -07:00
Alex Hoppen
951e923245 Use withUnsafeFileSystemRepresentation to get the path of a URL on disk
`URL.path` returns forward slashes in the path on Windows (https://github.com/swiftlang/swift-foundation/issues/973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
2024-10-21 11:12:30 -07:00
Alex Hoppen
ee29e31fb4 Merge pull request #1719 from ahoppen/explicit-bsp-shutdown
Explicitly shut down the build server when SourceKit-LSP is shut down
2024-10-02 10:27:15 -07:00
Alex Hoppen
3c7aa6f438 Merge pull request #1715 from ahoppen/bsp-cancellation
Share implementation of message handling on an `AsyncQueue` between `BuildSystemIntegration` and `SourceKitLSPServer`
2024-09-30 15:31:54 -07:00
Alex Hoppen
84878fe3a9 Merge pull request #1705 from ahoppen/watch-files-by-build-system
Allow build systems to specify the files to watch for changes
2024-09-30 15:31:41 -07:00
Alex Hoppen
d25b65c307 Explicitly shut down the build server when SourceKit-LSP is shut down
The build server is automatically shut down using a background task when `BuildSystemManager` is deallocated.

This, however, leads to possible race conditions where the shutdown task might not finish before the test is done, which could result in the connection being reported as a leak. To avoid this problem, we want to explicitly shut, down the build server when the `SourceKitLSPServer` gets shut down.
2024-09-30 11:57:39 -07:00
Alex Hoppen
4e53c01944 Merge pull request #1729 from ahoppen/reduce-public-imports
Reduce the number of public imports
2024-09-30 11:43:44 -07:00
Alex Hoppen
7befd0c648 Share implementation of message handling on an AsyncQueue between BuildSystemIntegration and SourceKitLSPServer
This gives us cancellation support for `BuiltInBuildSystemAdapter`.
2024-09-30 10:42:46 -07:00
Alex Hoppen
36478d87ed Allow build systems to specify the files to watch for changes
rdar://136014553
Resolves #1671
2024-09-30 10:33:32 -07:00
Alex Hoppen
d842579402 Merge pull request #1712 from ahoppen/build-system-logging-improvements
Improve logging surrounding build systems
2024-09-30 08:11:40 -07:00
Alex Hoppen
947e5269c4 Reduce the number of public imports 2024-09-30 07:50:12 -07:00
Alex Hoppen
bd422cf5d7 Improve logging surrounding build systems 2024-09-27 11:07:39 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
78b4955d6c Log full initialize request and response
The initialize request and response are often critical to debug issues with editor setups. Log them completely over multiple log messages, instead of truncating them in the normal logging path.
2024-09-23 08:52:19 -07:00
Alex Hoppen
444ce41dec Log all options when opening a SourceKit-LSP workspace
Previously, OSLog was truncating these options after ~1000 bytes, which left out valuable information about the setup.
2024-09-23 08:52:18 -07:00
Alex Hoppen
6762bb3e25 Remove resolved FIXME 2024-09-16 10:10:26 -07:00
Alex Hoppen
d00722e33f Use BSP to log messages from preparation in the build system 2024-09-16 10:06:35 -07:00
Alex Hoppen
6cc2cc4e95 Implement reloadPackageStatusCallback using BSP messages 2024-09-15 16:28:12 -07:00
Alex Hoppen
3d95375043 Use a LocalConnection to communicate between BuildSystemManager and BuildSystem 2024-09-15 16:28:12 -07:00
Alex Hoppen
12923b6d73 Implement toolchain(for:) using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
3a118980b4 Migrate BuildSystem.prepare to a BSP request 2024-09-11 09:48:50 -07:00
Alex Hoppen
236f566977 Instead of having FileHandlingCapability for a source file, check if it belongs to any targets 2024-09-11 08:27:12 -07:00
Alex Hoppen
37f7540ebe Merge pull request #1656 from ahoppen/workspace-delegate
Make `Workspace` the delegate of a `BuildSystemManager`
2024-09-11 08:23:25 -07:00
Alex Hoppen
57055d4135 Make Workspace the delegate of a BuildSystemManager
`Workspace` is responsible for creating the `BuildSystemManager` and responds to most of the delegate calls. It should thus also be the delegate of `BuildSystemManager`.
2024-09-10 15:22:18 -07:00
Alex Hoppen
f9e468ffba Use BSP requests to get build settings of a source file 2024-09-10 09:30:36 -07:00
Alex Hoppen
027f3ee1f4 Push creation of BuiltInBuildSystem into the workspace
This way we create the `BuiltInBuildSystem` at the same time that we create the `BuildSystemManager`, which gets us one step closer to creating the `BuiltInBuildSystem` from the `BuiltInBuildSystemAdapter`.
2024-09-09 17:59:46 -07:00
Alex Hoppen
6a9dcd2349 Split determining which build system to use for a workspace and the workspace creation
This allows us to create the build system from a `BuiltInBuildSystemAdapter` when it receives an `InitializeRequest`, which will be done in a follow-up commit.
2024-09-09 17:42:15 -07:00
Alex Hoppen
b490a6fef1 Use buildTarget/inverseSources from BSP to get targets of a source file 2024-09-09 16:31:30 -07:00
Alex Hoppen
fd0573e4b8 Rename BuildSystem to BuiltInBuildSystem 2024-09-09 16:30:13 -07:00
Alex Hoppen
4d1fa7a7ee Fix a race condition that could cause the build graph to not be generated when doing initial background indexing
We were making the initial `generateBuildGraph` call in `SourceKitLSPServer` from a `Task`. This means that `generateBuildGraph` could be executed after `waitForUpToDateBuildGraph` was called by `SemanticIndexManager`. Thus `waitForUpToDateBuildGraph` returned immediately and no files were background indexed.

Make `generateBuildGraph` immediately schedule a package reload for SwiftPM build systems instead of doing the hop through a `Task`, fixing the race condition.

rdar://135551812
2024-09-09 11:50:18 -07:00
Alex Hoppen
33e955ab6c Merge pull request #1632 from ahoppen/lazy-workspace-loading
Don’t block the generation of a build system by build graph generation
2024-09-07 02:27:19 -07:00
Alex Hoppen
6e0281f79a Don’t block the generation of a build system by build graph generation
We currently load the entire package before generating a `SwiftPMBuildSystem`. That means that the initialize request to SourceKit-LSP is blocked until the package has been loaded, preventing us from offering any sort of functionality, including syntactic functionality like formatting.

Decouple build system creation and build graph generation (aka. package loading for SwiftPM). We can operate with fallback build settings until the build graph has been loaded and reopen the document once the proper build settings are available.

rdar://126644596
2024-09-06 22:51:53 -07:00
Alex Hoppen
d86a32bc19 Remove custom decoding function from SourceKitLSPOptions
We forgot to decode the following keys in the custom decode function, which meant that you couldn’t set them using SourceKit-LSP’s `config.json` file.
- `backgroundPreparationMode`
- `sourcekitdRequestTimeout`
- `cancelTextDocumentRequestsOnEditAndClose`

We had the custom decoder function so that the keys weren’t required in the JSON but we could access eg. `SwiftPMOptions` without needing to deal with optionals in the codebase.

Make the accesses to these nested options structs a little more verbose but eliminate the source of the above bug, which seems like a good tradeoff.
2024-09-06 13:45:24 -07:00
Alex Hoppen
5833322218 Merge pull request #1631 from ahoppen/nested-macro-expansions
Support expansion of nested macros
2024-08-18 11:58:36 -07:00
Alex Hoppen
90e0f3f5fa Support expansion of nested macros
The basic idea is that a `sourcekit-lsp://swift-macro-expansion` URL should have sufficient information to reconstruct the contents of that macro buffer without relying on any state in SourceKit-LSP. The benefit of not having any cross-request state in SourceKit-LSP is that an editor might can send the `workspace/getReferenceDocument` request at any time and it will succeed independent of the previous requests. Furthermore, we can always get the contents of the macro expansion to form a `DocumentSnapshot`, which can be used to provide semantic functionality inside macro expansion buffers.

To do that, the `sourcekit-lsp:` URL scheme was changed to have a parent instead of a `primary`, which is the URI of the document that the buffer was expanded from. For nested macro expansions, this will be a `sourcekit-lsp://swift-macro-expansion` URL itself.

With that parent, we can reconstruct the macro expansion chain all the way from the primary source file. To avoid sending the same expand macro request to sourcekitd all the time, we introduce `MacroExpansionManager`, which caches the last 10 macro expansions.

`SwiftLanguageService` now has a `latestSnapshot` method that returns the contents of the reference document when asked for a reference document URL and only consults the document manager for other URIs. To support semantic functionality in macro expansion buffers, we need to call that `latestSnapshot` method so we have a document snapshot of the macro expansion buffer for position conversions and pass the following to the sourcekitd requests.
```
keys.sourceFile: snapshot.uri.sourcekitdSourceFile,
keys.primaryFile: snapshot.uri.primaryFile?.pseudoPath,
```

We should consider if there’s a way to make the `latestSnapshot` method on `documentManager` less accessible so that the method which also returns snapshots for reference documents is the one being used by default.

Co-Authored-By: Lokesh T R <lokesh.t.r.official@gmail.com>
2024-08-16 14:51:05 -07:00
Alex Hoppen
1e409c97e2 Implicitly cancel text document requests when the document is edited or closed
As a user makes an edit to a file, these requests are most likely no longer relevant. It also makes sure that a long-running sourcekitd request can't block the entire language server if the client does not cancel all requests. For example, consider the following sequence of requests:
 - `textDocument/semanticTokens/full` for document A
 - `textDocument/didChange` for document A
 - `textDocument/formatting` for document A

If the editor is not cancelling the semantic tokens request on edit (like VS Code does), then the `didChange` notification is blocked on the semantic tokens request finishing. Hence, we also can't run the `textDocument/formatting` request. Cancelling the semantic tokens on the edit fixes the issue.

rdar://133987424
2024-08-15 15:32:26 -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
Alex Hoppen
a537ed1f87 Merge pull request #1616 from ahoppen/container-name-of-accessors
Type-qualify accessors in call hierarchy
2024-08-06 21:08:59 -07:00
Alex Hoppen
d9ea15568c Merge pull request #1612 from ahoppen/log-cancellation-singpost-event
Log a signpost event when a request is cancelled
2024-08-06 12:52:21 -07:00