Commit Graph

59 Commits

Author SHA1 Message Date
Lokesh.T.R
087ea64ed3 Rename note to notification throughout the codebase wherever necessary 2024-05-29 17:58:04 +00:00
Alex Hoppen
c2bf81cfcd Merge pull request #1360 from ahoppen/show-background-indexing-not-supported-message
Show message if background indexing is enabled but the workspace doesn’t support background indexing
2024-05-29 09:40:41 -07:00
Alex Hoppen
0f86e01cab Merge pull request #1349 from ahoppen/address-review-comments-1322-1329
Address review comments from #1322 and #1329
2024-05-28 17:30:15 -07:00
Alex Hoppen
e87d9e8d5e Show message if background indexing is enabled but the workspace doesn’t support background indexing
If the user has enabled background indexing in sourcekit-lsp but opens a project that doesn’t support background indexing (compilation database, build server), we should show a message after opening the workspace, informing the user that background indexing is only supported in SwiftPM projects at the moment.

Fixes #1255
rdar://127474711
2024-05-28 14:12:19 -07:00
Alex Hoppen
8765bb10ef Merge pull request #1350 from ahoppen/no-side-effects-when-searching-for-workspace
Don’t cause any file system file effects when trying to find an implicit workspace for a file
2024-05-28 11:27:27 -07:00
Alex Hoppen
f85d821839 Don’t cause any file system file effects when trying to find an implicit workspace for a file
When looking for a workspace that can handle a file, we were creating full-fledged workspaces along the way, which we would then discard if they couldn’t handle the file being opened. This had multiple problems:
1. When background indexing is enabled, it caused semantic indexing of the workspace, which wrote files to a `.index-build` directory and was a waste of work
2. When background indexing is enabled, it caused package resolution, which also created a `.index-build` folder to be created
3. It caused a syntactic test index of the workspace, which was a waste of work.

To fix this, do multiple things:
1. When creating a workspace, add a check right after build system creation. This allows us to early exit if the build system can’t handle the file and prevents us from generating the `Workspace`, fixing (1) and (3)
2. Don’t call `reloadPackage` when creating a `SwiftPMWorkspace`. Instead, explicitly call `generateBuildGraph` once we committed to creating the workspace.
2024-05-28 08:29:55 -07:00
Alex Hoppen
24dfbd57f6 Merge pull request #1356 from ahoppen/progress-indicator-current-file-preparation
Show work done progress while a source file is being prepared for editor functionality
2024-05-28 07:03:23 -07:00
Alex Hoppen
aa356cb2a5 Merge pull request #1359 from ahoppen/split-sourcekitlspserver
Split SourceKitLSPServer.swift into multiple files
2024-05-28 06:29:22 -07:00
Alex Hoppen
4f91a987a4 Split SourceKitLSPServer.swift into multiple files
The file was a little large and contained multiple types that can easily be split off. Now you can scroll to the top of the file and see the members of `SourceKitLSPServer`.
2024-05-25 14:05:51 -07:00
Alex Hoppen
a858d30eaf Address review comments on #1329 2024-05-25 13:41:57 -07:00
Alex Hoppen
ecacd7ba2c Show work done progress while a source file is being prepared for editor functionality
While `SemanticIndexManager.inProgressPrepareForEditorTask` is not `nil`, show a work done progress in the editor that the current file is being prepared for editor functionality.

I decided to use the indexing progress indicator for this for now because I think it’s too spammy if SourceKit-LSP has two different progress indicators for preparation and indexing. I’ll need to see how this feels like in practice.

rdar://128722609
2024-05-25 10:40:35 -07:00
Alex Hoppen
069e8a2ca4 Call indexProgressManager.indexStatusDidChange when workspaces in the SourceKitLSPServer are modified
`IndexProgressManager` iterates over all workspaces in the SourceKitLSPServer. Modifying workspaces might thus update the index progress status.
2024-05-24 17:31:00 -07:00
Alex Hoppen
31a8cf333f Merge pull request #1345 from ahoppen/reset-workdoneprogress-state
Reset the state of `WorkDoneProgressState` when the progress has ended
2024-05-24 11:01:52 -07:00
Alex Hoppen
88de421495 Reset the state of WorkDoneProgressState when the progress has ended
Otherwise, we will never show the progress again.
2024-05-24 07:34:46 -07:00
Alex Hoppen
5fffb0a4c9 Watch for changes to source files
We used to only watch for file creation and deletion because that might modify build settings but for background indexing, we also need to watch for changes to the files, so we can invalidate the up-to-date status of the target.
2024-05-23 14:03:33 -07:00
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