Commit Graph

84 Commits

Author SHA1 Message Date
Alex Hoppen
1780d06c45 Add option to allow SourceKit-LSP to prepare a target without lazy type checking
rdar://130333458
2024-07-25 17:16:21 -07:00
Pavel Yaskevich
8a6df8ac5e Remove availableLibraries argument from loadPackageGraph
Prebuilt/provided libraries feature is reverted by https://github.com/swiftlang/swift-package-manager/pull/7800
2024-07-19 16:09:55 -07:00
Paul LeMarquand
f830432322 Fix incorrect ConfiguredTargets for Package.swift w/ multiple workspaces
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in #1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that #1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
2024-07-16 13:32:38 -04:00
Alex Hoppen
d8651a3b73 Fix a compilation issue caused by #1533 and #1524 racing 2024-06-28 22:57:48 +02:00
Alex Hoppen
68bff7f216 Make background indexing a proper option in SourceKitLSPOptions
This allows us to flip the default in the future more easily. It also allows users to disable background indexing when it’s enabled by default.

rdar://130280855

# Conflicts:
#	Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
2024-06-28 22:36:11 +02:00
Alex Hoppen
5440ba2d57 Support using SourceKit-LSP for projects that are cross-compiled
We previously always assumed that the project was being built for the host.

Fixes #786
Fixes #1475
rdar://129662080
rdar://113099964
2024-06-28 22:35:27 +02:00
Alex Hoppen
3e9c682cc9 Allow configuring of SourceKit-LSP’s options using .sourcekit-lsp configuration files
The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options.

The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP.

For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files.

Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit.

# Conflicts:
#	Sources/SourceKitLSP/SourceKitLSPServer+Options.swift
#	Sources/SourceKitLSP/Swift/SwiftLanguageService.swift
#	Sources/sourcekit-lsp/SourceKitLSP.swift
#	Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
#	Tests/SourceKitLSPTests/ExecuteCommandTests.swift
2024-06-28 22:35:15 +02:00
Alex Hoppen
252d5be7e3 Merge pull request #1512 from ahoppen/6.0/dont-reload-on-random-file-add
[6.0] Add test case that we don't reload the package if a `.swift` file get added in a folder that doesn't affect compilation
2024-06-26 22:28:36 +02:00
Alex Hoppen
55f6dee5c8 Update links for repositories moved to the swiftlang org on GitHub 2024-06-25 06:57:00 -07:00
Alex Hoppen
cad2964434 Add test case that we don't reload the package if a .swift file get added in a folder that doesn't affect compilation
rdar://128573306
2024-06-24 17:59:47 -07:00
Alex Hoppen
18d1944fab Merge pull request #1506 from ahoppen/6.0/watch-package-resolved 2024-06-24 17:06:04 -07:00
Alex Hoppen
5929cf93af Watch for changes to Package.resolved
We need to watch for changes to `Package.resolved` so that we can update the dependency checkouts in `.index-build` when the user runs `swift package update`.

rdar://130103181
2024-06-22 07:01:41 -07:00
Alex Hoppen
0ebe641f6e Merge commit 'a111b4748be9fbc893abb8a6c4871bb59dabbde0' into 6.0/merge-main-2024-06-22 2024-06-22 06:50:41 -07:00
Alex Hoppen
8642768902 Fix a few Swift concurrency warnings 2024-06-18 18:07:22 -07:00
Alex Hoppen
bc6751eb36 Merge branch 'main' into 6.0/merge-main-2024-06-17 2024-06-17 17:20:44 -07:00
Alex Hoppen
c9e6348302 Merge pull request #1447 from ahoppen/atomics-not-unsafe
Change all variables that are `Atomic*` types to not be `nonisolated(unsafe)`
2024-06-12 09:12:31 -07:00
Alex Hoppen
7f90508e51 Add a document to describe which log level to use
Also change a few log levels and make all log messages consistently start with an uppercase letter.
2024-06-11 12:01:50 -07:00
Pavel Yaskevich
6a6bc4dd20 [SwiftPMBuildSystem] Adjust BuildParameters use to indicate a destination
The change is introduced by https://github.com/apple/swift-package-manager/pull/7593

(cherry picked from commit 12b848ed58)
2024-06-07 17:37:32 -07:00
Alex Hoppen
6966a6b9c0 Merge branch 'main' into 6.0/merge-main-2024-06-07
# Conflicts:
#	Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift
2024-06-07 09:28:36 -07:00
Alex Hoppen
c43cffd044 Change all variables that are Atomic* types to not be nonisolated(unsafe)
Since the `Atomic*` types can not be marked as `Sendable` (because they aren’t C structs), we can change the variables to constants and can remove `nonisolated(unsafe)`.
2024-06-07 08:49:10 -07:00
Alex Hoppen
76a0db79be Merge pull request #1445 from ahoppen/use-build-setup
Inspect the build setup to determine the extra flags to pass to the `swift build` invocations during preparation
2024-06-06 16:23:29 -07:00
Alex Hoppen
b89d267930 Inspect the build setup to determine the extra flags to pass to the swift build invocations during preparation
The `BuildParameters` that we were previously inspecting contained some parameters that SwiftPM synthesizes and that weren’t specified on the command line. For example, it contains `-g` for all languages. This causes us to add `-Xswiftc -g -Xcc -g -Xcxx -g` to the `swift build` invocations for preparation, which is not necessary.
2024-06-06 13:38:28 -07:00
Alex Hoppen
2692d5f7fb Log the exit status of prepare and index processes to the index log 2024-06-06 13:22:07 -07:00
Alex Hoppen
aa176644f6 Merge pull request #1434 from ahoppen/process-priority
Set the priority of processes launched for background indexing
2024-06-06 13:07:24 -07:00
Alex Hoppen
e656954f1d Merge branch 'main' into 6.0/merge-main-2024-06-06 2024-06-06 09:55:35 -07:00
Alex Hoppen
ce7f36e9ec Let the build system determine which toolchain to use for a document
This allows us to fix a toolchain when using a `SwiftPMBuildSystem`, which is critical to ensure that a target gets prepared using the same toolchain that is used to index it and that is used for sourcekitd.
2024-06-06 09:33:00 -07:00
Alex Hoppen
efabae8808 Take run destinations into account for SwiftPM build targets
We can have two targets with the same name in a SwiftPM workspace, one for a build target and one for the destination. We need to be able to tell them apart based on the run destination.
2024-06-06 09:33:00 -07:00
Alex Hoppen
556fd333b5 Heap allocate our atomics
We used C atomics but these were allocated as Swift variables. Even thought they were atomic, concurrent accesses to them could violate Swift’s exclusivity laws, raising thread sanitizer errors.

Allocate the C atomics using malloc to fix this problem.

rdar://129170128
2024-06-05 23:27:47 -07:00
Alex Hoppen
db9662bcc3 Set the priority of processes launched for background indexing
Unfortunately, `setpriority` only allows reduction of a process’s priority and doesn’t support priority elevation (unless you are a super user). I still think that it’s valuable to set the process’s priority based on the task priority when it is launched because many indexing processes never get their priority escalated and should thus run in the background.

On Windows, we can elevate the process’s priority.

rdar://127474245
2024-06-05 23:13:21 -07:00
Alex Hoppen
11137e1622 Merge branch 'main' into 6.0/update-2024-06-04 2024-06-04 15:42:48 -07:00
Alex Hoppen
b479b2e874 Create a SwiftExtensions module
This allows us to share common Swift utility functions between SourceKit-LSP and LSPLogging.
2024-06-04 07:06:44 -07:00
Alex Hoppen
fff9eb569e Merge pull request #1382 from ahoppen/stream-index-log
Instead of sending a message to the index log when an indexing task finishes, stream results as they come in
2024-06-03 19:33:29 -07:00
Alex Hoppen
f98da773a9 Make passing --experimental-prepare-for-indexing to swift build an experimental feature
I’d like to qualify `--experimental-prepare-for-indexing` independently of background indexing using `swift build`. Because of this, I think there is value in using SourceKit-LSP using background indexing but without `--experimental-prepare-for-indexing`. It could also be useful to determine if bugs we may find are due to `--experimental-prepare-for-indexing` or also occur when running plain `swift build` commands.
2024-06-03 15:22:00 -07:00
Alex Hoppen
f203b3a527 Merge pull request #1395 from ahoppen/uri-everywhere
Use `DocumentURI` instead of `URL` in more locations
2024-06-03 14:05:00 -07:00
Alex Hoppen
09ad77ba8d Instead of sending a message to the index log when an indexing task finishes, stream results as they come in
This also means that you can use the index log to view which tasks are currently being executed.

Since we only have a single log stream we can write to, I decided to prefix every line in the index log with two colored emojis that an easy visual association of every log line to the task that generated them.
2024-06-03 13:21:54 -07:00
Alex Hoppen
3c5d8b9119 Change SwiftPMBuildSystem to use DocumentURI instead of URL 2024-06-03 11:26:19 -07:00
Alex Hoppen
259d49e12c Share module cache between test projects
This improves serial test execution time of eg. `DocumentTestDiscoveryTests` from 36s to 22s because we don’t need to re-build the XCTest module from its interface when using an open source toolchain.

This also uncovered that we weren‘t passing the build setup flags to the prepare command.

rdar://126493151
2024-06-03 09:29:16 -07:00
Alex Hoppen
e56c71f4b3 Don’t run a swift build command to prepare a package manifest
Package manifests don’t have an associated target to prepare and are represented by a `ConfiguredTarget` with an empty target ID. We were mistakingly running `swift build` with an empty target name to prepare them, which failed. There is nothing to prepare.
2024-05-31 21:45:12 -07:00
Alex Hoppen
b7a502c1f4 When SwiftPM supports --experimental-prepare-for-indexing pass it to the prepare command
The main purpose for now is that this makes it easier for me to live on background indexing combined with https://github.com/apple/swift-package-manager/pull/7574.
2024-05-31 15:50:33 -07:00
Alex Hoppen
0b6ad2725f Merge pull request #1371 from ahoppen/tests-pass-on-released-xcode
Make tests pass with Xcode 15.4
2024-05-31 15:44:07 -07:00
Pavel Yaskevich
d439d12871 Merge pull request #1361 from xedin/buildplan-parameter-split
[SwiftPMBuildSystem] Adjust `BuildParameters` use to indicate a desti…
2024-05-30 20:17:55 -07:00
Alex Hoppen
6d4953b3ef Make tests pass with Xcode 15.4
We are no longer skipping these tests, which means that we need to make them account for different error messages emitted by Swift 5.10.

I added warnings behind `#if compiler(>=6.1)` to give us a reminder that we can remove these checks when we no longer support running SourceKit-LSP with SwiftPM from Swift 5.10. Swift 6.1 doesn’t have to be this cut-off point but it’s the most likely candidate for now if we want to support the current and last Swift version from tip SourceKit-LSP.
2024-05-30 19:23:45 -07:00
Pavel Yaskevich
12b848ed58 [SwiftPMBuildSystem] Adjust BuildParameters use to indicate a destination
The change is introduced by https://github.com/apple/swift-package-manager/pull/7593
2024-05-30 15:39:50 -07:00
Alex Hoppen
942bb0a6c3 Merge pull request #1366 from ahoppen/fix-modules-include-directory
Support running tests that require building with a Swift 5.10 toolchain
2024-05-30 07:49:50 -07:00
Pavel Yaskevich
9f6021c664 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.

(cherry picked from commit 2270631a32)
(cherry picked from commit b13244fa88f745937044acd6eec27ff57bc96b5d)
2024-05-29 15:57:48 -07:00
Alex Hoppen
48df05478c Support running tests that require building with a Swift 5.10 toolchain
When we detect that we’re running using a 5.10 toolchain, adjust the compiler arguments that we received from SwiftPM to drop any `/Modules` suffixes in the build directory, to account for the fact that 5.10 stores the modules one directory higher up (https://github.com/apple/swift-package-manager/pull/7103).
2024-05-29 14:20:17 -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
bac062f231 Merge branch 'main' into 6.0/merge-main-2024-05-28
# Conflicts:
#	Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift
2024-05-28 11:48:29 -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
9e771aa454 Merge branch 'main' into 6.0/merge-main-2024-05-23 2024-05-23 21:12:26 -07:00