Commit Graph

81 Commits

Author SHA1 Message Date
Ben Barham
333e950df2 Allow workspace options to affect build system search
There were a few places that options only took place *after* determining
a build system, even though we have multiple that impact the search (eg.
`defaultBuildSystem` and `searchPaths`).

Additionally track project root and configuration paths separately, so
that when searching for implicit workspaces we can make sure to skip
creating duplicates.

(cherry picked from commit 0c896696c9)
2025-01-23 15:17:48 -08:00
Alex Hoppen
b7fbb47b65 Do not realpath the project root of a SwiftPMBuildSystem
If you have a package located at `/pkg` and a symlink at `/symlink` and you open `/symlink` as a workspace, the SwiftPMBuildSystem’s project root would be `/pkg`. This would mean that it also only knew about build settings for files in `/pkg`, not in `/symlink`. Thus, whenever we were opening a file in `/symlink` we would create an implicit workspace to handle it (but which ended up having a project root at `/symlink` again) – or something close to this.

We shouldn’t need to realpath here. If you open `/symlink`, we should view `/symlink` as the project root of your workspace.

(cherry picked from commit 8617b8bbcc)
2025-01-23 15:17:26 -08:00
Alex Hoppen
f8002f72fd Support building SourceKit-LSP without a dependency on SwiftPM
(cherry picked from commit 5326852ea8)
2025-01-23 11:43:10 -08:00
Kabir Oberai
d6ae675663 Forward cross-compilation args when indexing 2025-01-21 12:02:33 -05:00
Alex Hoppen
7a06eb0ddf Merge pull request #1858 from ahoppen/symlink-target
Fix background indexing behavior if a source file is included in two targets via a symlink
2024-12-10 15:00:46 -08:00
Alex Hoppen
a087692725 Return compiler arguments for invalid package manifests
Currently, when there‘s a syntax error in a package manifest, we don’t get any build settings from it in SourceKit-LSP and thus loose almost all semantic functionality. If we can’t parse the package manifest, fall back to providing build settings by assuming it has the current Swift tools version.

Currently, when there‘s a syntax error in a package manifest, we don’t get any build settings from it in SourceKit-LSP and thus loose almost all semantic functionality. If we can’t parse the package manifest, fall back to providing build settings by assuming it has the current Swift tools version.

Fixes #1704
rdar://136423767
2024-12-09 15:25:38 -08:00
Alex Hoppen
5eb460f148 Fix background indexing behavior if a source file is included in two targets via a symlink
Consider the following scenario: A project has target A containing A.swift an target B containing B.swift. B.swift is a symlink to A.swift. When A.swift is modified, both the dependencies of A and B need to be marked as having an out-of-date preparation status, not just A.
2024-12-09 15:06:39 -08:00
Alex Hoppen
247acf6ae7 Merge pull request #1874 from ahoppen/allow-dependency-updates
Allow dependency updates in the `index-build` folder
2024-12-09 14:31:38 -08:00
Alex Hoppen
ddbd6543c4 Allow dependency updates in the index-build folder
When we have background indexing enabled, SourceKit-LSP manages the dependencies. We should thus allow it to update them, eg. after `Package.resolved` was updated.
2024-12-06 11:30:02 -08:00
Alex Hoppen
388789472c Create child scopes for SwiftPM operations
Some SwiftPM functions check whether their observability scope has errors. If we use the same observability scope for all SwiftPM operations during SourceKit-LSP’s lifetime, a single SwiftPM error will set the `hasError` bit in that observability scope for the entirety of SourceKit-LSP’s lifetime, impacting all upcoming SwiftPM operations.

Creating a separate child scope for every operation fixes
2024-12-06 11:26:13 -08:00
Alex Hoppen
b42e62f42d Merge pull request #1862 from ahoppen/log-package-reload-trigger
Log which file caused the package to be reloaded
2024-12-06 09:02:36 -08:00
Alex Hoppen
1c9a15eeb0 Log which file caused the package to be reloaded 2024-12-05 20:27:32 -08:00
Alex Hoppen
5914efd9b4 Log package loading messages to the index log 2024-12-05 20:26:50 -08:00
Matthew Bastien
f900b4ef2c Merge pull request #1853 from matthewbastien/include-all-build-target-resources
Include all resources in a build target's sources list
2024-12-05 16:49:06 -05:00
Matthew Bastien
f2fed7afa5 reduce code duplication
Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2024-12-05 10:48:56 -05:00
Matthew Bastien
3ea9a65d77 include all resources in a build target's sources list 2024-12-05 09:53:42 -05:00
Alex Hoppen
cddd810455 Provide build settings for version-specific package manifests
Fixes #1670
rdar://136014520
2024-11-22 22:04:20 +01:00
Alex Hoppen
76304db5e2 Fix merge conflict
https://github.com/swiftlang/sourcekit-lsp/pull/1824 and https://github.com/swiftlang/sourcekit-lsp/pull/1832 raced.
2024-11-19 15:47:52 -08:00
Alex Hoppen
8d13afa73d Merge pull request #1824 from kateinoigakukun/katei/interpret-relative-scratch-dir
Allow `scratchPath` to be a relative path
2024-11-19 11:14:40 -08:00
Yuta Saito
184fa12389 Allow scratchPath to be relative paths
Interpret it as relative to the project root directory if it's a
relative path.
2024-11-19 11:19:54 +09:00
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
c23b4ff776 Merge pull request #1803 from ahoppen/indexbuild-subfolder
Make `.index-build` a subdirectory of `.build`
2024-11-14 12:54:20 -08:00
Alex Hoppen
8c2def8ef9 Rename SKSupport to LanguageServerProtocolExtensions 2024-11-13 16:53:58 -08:00
Alex Hoppen
47f3cd506b Split TSCExtensions into a separate module 2024-11-13 13:58:36 -08:00
Alex Hoppen
06f58db5c8 Use build/taskStart, build/taskProgress and build/taskFinish to communicate progress from a BSP server to the client
Instead of defining BSP extensions for `window/workDoneProgress/create` and `$/progress`, we should be able to use the standard `build/taskStart`, `build/taskProgress` and `build/taskFinish` messages to the same effect, as suggested by https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400/9.

Fixes #1783
rdar://138653131
2024-11-06 09:39:09 -08:00
Alex Hoppen
ec0a7c4ef3 Make .index-build a subdirectory of .build
This means that users of SourceKit-LSP’s background indexing don’t need to add another directory to their `.gitignore`.
2024-11-04 15:34:59 -08: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
aa0aa927ca Stop using TSCBasic.resolveSymlinks and URL.resolvingSymlinksInPath 2024-10-09 13:16:57 -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
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
2ec571b529 Revert "Require a Swift 6 compiler to build SourceKit-LSP"
This reverts commit 7ab7c01cdc.

# Conflicts:
#	Package.swift
2024-09-26 18:23:59 -07:00
Alex Hoppen
d8b41d4eff Merge pull request #1685 from ahoppen/only-scan-test-targets
Only scan test targets for tests
2024-09-19 20:41:40 -07:00
Alex Hoppen
120bd8688b Only scan test targets for tests
Don’t run the syntactic test scanner on files that we know are only part of non-test targets.

rdar://126493903
2024-09-19 13:42:40 -07:00
Alex Hoppen
40cc4c60c6 Adjustments because traverseModules no longer returns depth
We no longer need `depth`. Adopt a faster version of `traverseModules` that doesn’t return the depth.

rdar://136107035
2024-09-19 13:40:45 -07:00
Alex Hoppen
14765bbca8 Fix an issue that caused us to not get compiler arguments when opening a SwiftPM package at a symlink
When you had a package at `/pkg_real` and a symlink `/pkg` pointing to `/pkg_real`, then opened a workspace at `/pkg`, we wouldn’t get any build settings for any of the files. This was masked in tests because they still called `SwiftPMBuildSystem.targets(for:)`, which handled symlink resolution but wasn’t called in production.

Handle symlink resolution `BuildSystemManager`, remove `SwiftPMBuildSystem.targets(for:)` and its related members/methods, and migrate the tests to go through `BuildSystemManager`, which is what production code does. A nice side effect of this is that the tests will log the requests sent to the build system.
2024-09-18 17:41:36 -07:00
Alex Hoppen
7ab7c01cdc Require a Swift 6 compiler to build SourceKit-LSP
Xcode 16 with Swift 6 has been released, we can drop support for building and testing SourceKit-LSP using a Swift 5.10 toolchain. This allows us to remove a number of workarounds.
2024-09-17 16:53:13 -07:00
Alex Hoppen
e15bdd7e90 Review SwiftPMBuildSystem.swift 2024-09-16 10:13:20 -07:00
Alex Hoppen
0bdbb507c9 Review CompilationDatabaseBuildSystem 2024-09-16 10:12:58 -07:00
Alex Hoppen
3a78b650c1 Share logic to infer language from file extension between BuildSystemManager and FileBuildSettings.patching 2024-09-16 10:10:26 -07:00
Alex Hoppen
85b2f1fd30 Review BuildServerProtocol module for consistency 2024-09-16 10:10:26 -07:00
Alex Hoppen
5870ad9eb4 Implement InverseSourcesRequest in BuildSystemManager
`buildTarget/inverseSources` is not required to be implemented by BSP servers and we have almost all information needed for it in `BuildSystemManager`.

This also makes sure that `buildTarget/sources` and `buildTarget/inverseSources` actually match each other. Before this change, we had source files like `Package.swift` for which we returned a target from `buildTarget/inverseSources` but that weren’t part of that target’s sources retrieved using `buildTarget/sources`.
2024-09-16 10:08:14 -07:00
Alex Hoppen
70288465dc Log target name instead of the target's URI 2024-09-16 10:07:31 -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
66f24e3554 Introduce buildSystemTestHooks 2024-09-15 16:28:12 -07:00
Alex Hoppen
a96c0913ad Implement addSourceFilesDidChangeCallback in BuildSystemManager 2024-09-13 11:12:40 -07:00
Alex Hoppen
fac21f5976 Implement waitForUpToDateBuildGraph using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
12923b6d73 Implement toolchain(for:) using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
cc11fe1b02 Implement topologicalSort inside BuildSystemManager using dependency information 2024-09-12 17:26:41 -07:00
Alex Hoppen
bb96ff4c68 Migrate targets(dependingOn:) to BSP 2024-09-12 16:59:03 -07:00