Commit Graph

44 Commits

Author SHA1 Message Date
Alex Hoppen
3e6319c3b9 Produce an index log for the client
This allows a user of SourceKit-LSP to inspect the result of background indexing. This allows a user of SourceKit-LSP to inspect the result of background indexing. I think this gives useful insights into what SourceKit-LSP is indexing and why/how it fails, if it fails, also for users of SourceKit-LSP.

rdar://127474136
Fixes #1265
2024-05-21 22:18:06 -07:00
Alex Hoppen
a88798129d Add an option to show the files that are currently being index / targets being prepared in the work done progress 2024-05-21 22:09:22 -07:00
Alex Hoppen
41b810b80c Cancel preparation tasks for editor functionality if the preparation task hasn't been started yet and the document is no longer active
When the user opens documents from three targets A, B, and C in quick succession, then we don’t want to schedule preparation of wait until A *and* B are finished preparing before preparing C.

Instead, we want to
- Finish for preparation of A to finish if it has already started by the time the file in C is opened. This is done so we always make progress during preparation and don’t get into a scenario where preparation is always cancelled if a user switches between two targets more quickly than it takes to prepare those targets.
- Not prepare B because it is no longer relevant and we haven’t started any progress here. Essentially, we pretend that the hop to B never happened.
2024-05-21 18:12:24 -07:00
Alex Hoppen
d12c946988 Merge pull request #1321 from ahoppen/target-preparation-testing 2024-05-20 20:02:01 -07:00
Alex Hoppen
9524753826 Introduce test hooks that can be used to monitor when preparation and index tasks finish 2024-05-17 16:46:14 -07:00
Alex Hoppen
2d27d57b66 Extract indexTaskDidFinish in SourceKitLSPServer.Options into a TestHooks struct 2024-05-17 16:30:47 -07:00
Alex Hoppen
195d3af74e Move LocalConnection to LSPTestSupport
We weren’t logging requests sent to a `TestSourceKitLSPClient` because we were assuming that `JSONRPCConnection` logs those requests in `SourceKitLSPServer`. But no logging happens in `LocalConnection`, which `TestSourceKitLSPClient` uses.

Since `LangaugeServerProtcol` can’t depend on `LSPLogging`, move the type to `LSPTestsSupport`.
2024-05-17 11:59:40 -07:00
Alex Hoppen
72083762a4 When interacting with a document, prepare the target it belongs to
Whenever we get request for a document, open it or edit it, trigger a preparation of its target, but don’t block any interaction based on it. This should ensure that the target is usually prepared when the user is interacting with it.

We need to track the preparation status of targets somewhat accurately in `SemanticIndexManager`, so we don’t unnecessarily re-prepare a target. When updating the index store, it is acceptable to schedule another `UpdateIndexStoreTaskDescription` because it will early exit based on an `mtime` check with the unit file. Null builds of a target take significantly longer and thus we want to avoid them.

Fixes #1252
rdar://127474003
2024-05-16 10:40:47 -07:00
Alex Hoppen
546bb3230e Update index as files are modified on disk
Fixes #1251
rdar://127476161
2024-05-15 11:00:13 -07:00
Alex Hoppen
a6389e58e2 Show a work done progress that shows the index progress
This makes it a lot easier to work on background indexing because you can easily see how background indexing is making progress.

Resolves #1257
rdar://127474057
2024-05-14 06:39:48 -07:00
Alex Hoppen
d70a68f37c Wait until initialization has finished before starting a work done progress 2024-05-14 06:38:22 -07:00
Alex Hoppen
5cce99b920 Make IndexTaskDescription protocol-based instead of enum-based
This simplifies the implementation.
2024-05-14 06:38:21 -07: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
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07:00
Alex Hoppen
a643749def Log an error if we couldn't find the definition of a USR in the index 2024-05-08 10:40:05 -07:00
Alex Hoppen
efba8ce9bc Merge pull request #1216 from ahoppen/background-indexing
Implement initial background indexing of a project
2024-05-08 10:35:18 -07:00
Alex Hoppen
c0d0d8368d Log request ID of received requests
Useful for correlating request IDs with cancellation notifications.
2024-05-06 17:48:35 -07:00
Alex Hoppen
1a5d1321a1 Implement initial background indexing of a project
Implements an initial background index when the project is opened.

The following will be implemented in follow-up PRs:
- Resolving package dependencies
- Preparing dependent modules
- Watching for file updates
2024-05-05 14:26:52 -07:00
Alex Hoppen
47850f47cd Allow overriding the current logging subsystem 2024-05-03 14:48:15 -07:00
Alex Hoppen
8590a4bdc2 Use an atomic for notificationIDForLogging
This allows us to get rid of the lock.
2024-05-03 14:48:15 -07:00
Alex Hoppen
1f87e7fc4b Move CheckedIndex to a new SemanticIndex module 2024-05-03 14:48:15 -07:00
Alex Hoppen
221c9b2852 Move logic to select the toolchain for a document from SourceKitLSPServer to BuildSystemManager
This allows us to determine the toolchain to use during background indexing. It also moves toolchain selection closer to the build system, which is good because when we support multiple toolchains for a single workspace, the build system is what decides which toolchain to use for which document.
2024-05-03 14:48:15 -07:00
Alex Hoppen
9c01f87659 Pass all SourceKitLSPServer.Options to Workspace
This allows us to enable background indexing for a workspace based on a value in `SourceKitLSPServer.Options`.
2024-05-03 14:48:15 -07:00
Alex Hoppen
f23d5d6389 Filter index entries for deleted source files
This introduces an abstraction layer around `IndexStoreDB` (yes, I known another one …) that consults the underlying `IndexStoreDB` and then checks whether the entries are up-to-date with respect to some `IndexCheckLevel`. Requests can specify how picky they want to be about declaring results from the index out-of-date.

The default choice right now is to not include index entries from source files that have been deleted (because those are definitely from lingering unit files) but include results even if the source file has been modified after it was last indexed. We do include results from files that have been modified since they were last indexed because: When a file gets modified, it's likely that some of the line:column locations in it are still correct – eg. if only one line is modified and if lines are inserted/deleted all locations above are still correct. For locations that are out of date, showing stale results is one of the best ways of communicating to the user that the index is out-of-date and that they need to rebuild. We might want to reconsider this default when we have background indexing.

rdar://125230833
rdar://126622963
2024-05-01 14:44:11 -07:00
Alex Hoppen
1eb459e94b Elevate the log level for messages that record which toolchain was used for a document
This is some fairly essential information for troubleshooting and should be logged at the same level as the build settings for a file.
2024-04-24 09:44:47 -07:00
Alex Hoppen
ec5c614318 Merge pull request #1175 from ahoppen/syntactic-test-index 2024-04-24 07:01:34 -07:00
Alex Hoppen
fd7b268431 Reload a file when other files within the same module or a .swiftmodule file has been changed
When the client sends us `workspace/didChangeWatchedFiles` notification of an updated `.swift` file, we should refresh the other open files in that module since they might be referencing functions from that updated file.

If a `.swiftmodule` file has been updated, we refresh all the files within the package since they might import that module. Technically, we would only need to refresh files that are in module that are downstream of the updated module but we don’t currently have that information easily available from SwiftPM. Also, usually, if the client has a file from a low-level module open, he’ll be working on that module which means that such an optimization won’t help. The real solution here is to wait for us to finish preparation (which we would exactly know when it finishes since sourcekit-lsp would schedule it) but for that we need to implement background preparation.

Fixes #620
Fixes #1116
rdar://99329579
rdar://123971779
2024-04-23 09:34:20 -07:00
Alex Hoppen
a799da39aa Implement a syntactic workspace-wide test index
This workspace-wide syntactic test index is used for two purposes:
- It is used for XCTests instead of the semantic index for files that have on-disk or in-memory modifications to files
- It is uses for swift-testing tests, which are only discovered syntactically.

rdar://119191037
2024-04-23 09:25:31 -07:00
Alex Hoppen
771d2a7c23 Merge pull request #1185 from ahoppen/ahoppen/jump-to-system-interface
Fix jump-to-definition to methods in swift interfaces that are in synthesized extensions
2024-04-22 22:59:51 -07:00
Alex Hoppen
8ed842b96d Show unapplied function references in call hierarchy
With https://github.com/apple/swift/pull/72930 we can use the `containedBy` instead of `calledBy` relation for the call hierarchy, which allows us to show unapplied function references in the call hierarchy as well.

rdar://123769825
2024-04-19 21:47:54 -07:00
Alex Hoppen
0d25ce3b97 Merge pull request #1170 from ahoppen/uri-to-workspace-cache-race-condition
Fix a race condition during the computation of `uriToWorkspaceCache`
2024-04-18 18:54:26 -07:00
Alex Hoppen
440dc62e58 Fix jump-to-definition to methods in swift interfaces that are in synthesized extensions
For example when trying to go-to-definition to `filter` on `Array`, we get a USR `s:s14_ArrayProtocolPsE6filterySay7ElementQzGSbAEKXEKF::SYNTHESIZED::s:Sa`. We were trying to look it up in the index, which failed because synthesized extension methods are not indexed.

Instead, consult the `module` and `groupName` that `sourcekitd` returns in the cursor info request to decide which module to jump to.

rdar://126240558
2024-04-18 10:30:18 -07:00
Alex Hoppen
a6f74fc6dc Fix a race condition during the computation of uriToWorkspaceCache
See comment in `workspaceForDocument` that explains the race.
2024-04-17 21:09:47 -07:00
Alex Hoppen
f482982c47 Instead of returning an empty array in prepareTypeHierarchy, sourcekit-lsp should return nil
Eg. when requesting type hierarchy of a class when the project hasn’t been built, sourcekit-lsp returns an empty array. That causes VS Code to fail with very ambiguous error messages
- MISSING provider
- Cannot read properties of null (reading 'kind')

To work around this, instead of returning an empty array, return `nil` instead.

rdar://126228814
2024-04-16 11:25:56 -07:00
Alex Hoppen
1e3488bfb4 Don’t repeat a function in incomingCalls if it contains multiple calls to the same function
Eg. if we have the following, and we get the call hierarchy of `foo`, we only want to show `bar` once, with multiple `fromRanges` instead of having two entries for `bar` in the call hierarchy.

```swift
func foo() {}
func bar() {
  foo()
  foo()
}
```
2024-04-11 14:35:33 -07:00
Alex Hoppen
15189bb2fa Merge pull request #1149 from ahoppen/ahoppen/structured-tests
Return tests discovered by `workspace/tests` and `textDocument/tests` in a hierarchical format
2024-04-11 11:03:56 -07:00
Alex Hoppen
44b8a82f9e Merge pull request #1165 from ahoppen/container-name-as-call-hierarchy-detail
Show container name as the detail of a call hierarchy item
2024-04-08 16:34:08 -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
65b9505081 Return workspace tests in a hierarchical format
This ways the client doesn’t need to create a hierarchical structure using the container names. It is also more flexible and allows nesting of test suites + the addition of labels and tags for swift-testing.

The data structure for `TestItem` has been heavily inspired by VS Code’s `TestItem` for the test explorer, which should make it fairly straightforward to integrate these results into the VS Code test explorer.
2024-04-05 20:16:06 -07:00
Alex Hoppen
30bc65a554 Show container name as the detail of a call hierarchy item
The container name, showing the class a method is defined on, is more useful than the module name.
2024-04-05 10:20:01 -07:00
Alex Hoppen
8e9c19ac61 Don’t fatalError when constructing DocumentURI from an invalid URL 2024-04-04 11:05:49 -07: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
Alex Hoppen
4b5f7ffd90 Rename SourceKitServer -> SourceKitLSPServer
This avoid ambiguities whether `SourceKitServer` handles sourcekitd or `sourcekit-lsp`.
2024-03-20 22:50:34 +01:00