Commit Graph

29 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
44acd0d550 Merge pull request #1325 from ahoppen/fix-topological-sorting
Fix issue that caused topological order to be incorrect
2024-05-21 22:03:41 -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
ce34ec25a3 Fix issue that caused topological order to be incorrect 2024-05-21 18:05:11 -07:00
Alex Hoppen
af6cdeba37 Merge pull request #1313 from ahoppen/only-mark-dependent-targets-as-out-of-date
When a file is changed, only mark targets that depend on it as out-of-date
2024-05-20 13:40:51 -07:00
Alex Hoppen
a850cb6849 When a file is changed, only mark targets that depend on it as out-of-date 2024-05-17 14:32:49 -07:00
Alex Hoppen
372673f3c2 Address review comments to #1249 2024-05-17 06:23:08 -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
31f2674b80 Don’t rely on working directory during index preparation
Amazon Linux and CentOS don’t support working directory. We can work around this by passing `--package-path` to `swift build`.

rdar://128037023
2024-05-13 21:07:18 -07:00
Alex Hoppen
740262cb24 Don’t set forceResolvedVersions to true when we have an index build directory
When `SwiftPMBuildSystem` operates on a ` .index-build` directory, it owns the checkouts and is thus also allowed to resolve the package versions. This is necessary
2024-05-10 14:43:32 -07:00
Alex Hoppen
13176b012d Address review comments 2024-05-10 14:43:32 -07:00
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07:00
Alex Hoppen
4d93848eef Merge pull request #1249 from ahoppen/configured-targets
Introduce a notion of `ConfiguredTargets` into the build system
2024-05-09 12:02:17 -07:00
Alex Hoppen
d4dd57861c Introduce a notion of ConfiguredTargets into the build system
Instead of asking for build settings of a file, the build system manager asks for the targets of a file and then asks for the build settings of that file in a specific target. This has two advantages:
- We know about targets and can prepare the targets for background indexing
- Once we support build systems in which a single file can be part of multiple targets, we can have a centralized place that picks preferred targets for a file, eg. based on user configuration
2024-05-08 16:02:11 -07:00
Alex Hoppen
cefb3df929 Merge pull request #1233 from xedin/adopt-modulesgraph-api-change
Adopt SwiftPM ModulesGraph initializer API adjustment
2024-05-08 11:59:58 -07:00
Pavel Yaskevich
2270631a32 Adopt SwiftPM ModulesGraph initializer API adjustment
`ModulesGraph.init` was changed by https://github.com/apple/swift-package-manager/pull/7530
to accept `packages` as a way to avoid having to recompute the full
list of packages by walking roots.
2024-05-07 00:07:22 -07:00
Alex Hoppen
f3f8860d7a Return fileHandlingCapability.handled for all files that SwiftPMBuildSystem has build settings for
Previously, `SwiftPMBuildSystem` would report `.unhandled` as the file handling capability for `Package.swift`. In single workspace-folder setups, this was not an issue because we would always default to using the build system of the first/only workspace folder, which was the only `SwiftPMBuildSystem` and then returned compiler arguments despite saying that it couldn’t handle `Package.swift`.

This, however, breaks if you have a setup with multi workspace folders, where we can’t rely on the first workspace folder being able to provide build settings for the package manifest.

To fix this, report `.handled` file handling capability for all files that `SwiftPMBuildSystem` can compute build settings for.

Fixes #1210
rdar://127351614
2024-05-06 18:30:37 -07:00
Alex Hoppen
9ff1ff1430 Allow querying the build system for the language of a document
The build system has potentially  more information about a document's language than we do based on the file’s extension.
2024-05-03 14:48:15 -07:00
Alex Hoppen
5e4f1b03bf Generalize BuildSystem.testFiles to return all source files in a project 2024-05-03 14:48:15 -07:00
Alex Hoppen
ab68dc5502 Merge pull request #1201 from ahoppen/no-tests-from-package-dependencies
Don’t include files from package dependencies in the syntactic test index
2024-05-01 14:41:59 -07:00
Pavel Yaskevich
bde432b75c Remove obsolete availableLibraries argument from loadPackageGraph
[SwiftPM PR](https://github.com/apple/swift-package-manager/pull/7496)
consolidates use of provided libraries around Workspace and PubGrub
dependency resolver.
2024-04-26 09:25:50 -07:00
Alex Hoppen
1d9b67b0b9 Don’t include files from package dependencies in the syntactic test index
`SwiftPMBuildSystem.testFiles()` returned all source files in the package, including files of package dependencies. This caused us to index those files for tests in the syntactic test index, which we should not.

Make `SwiftPMBuildSystem.testFiles` only return files from the root package.

Also add test infrastructure to be able to test cross-package functionality.

rdar://126965614
2024-04-24 11:13:40 -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
4b7c16f2d4 Inherit actor isolation of closure passed to orLog
This allows us to express that `body` will run on the same actor isolation domain as the caller of `orLog`, which effectively makes `orLog` usable from actors again.
2024-03-29 09:50:10 +01:00
Alex Hoppen
4bc1e80d2f Make SKSwiftPMWorkspace build with strict concurrency 2024-03-21 10:22:28 +01:00
Alex Hoppen
582a1000c8 Rename SwiftPMWorkspace to SwiftPMBuildSystem
All other types that conform to `BuildSystem` (which in sourcekit-lsp terms is something that can provide compiler arguments) had the `BuildSystem` suffix. `SwiftPMWorkspace` was an oddity here and was easily confused with the `Workspace` term in LSP, which essentially represents a single root folder that is being opened.
2024-03-20 22:51:28 +01:00