Commit Graph

94 Commits

Author SHA1 Message Date
Ben Barham
786f8077d2 Update the compiler arguments used for background AST builds
This fixes two issues:
1. The SwiftPM build system was setup without passing through whether it
   should prepare or not. This meant that we lost eg. the argument to
   allow compiler errors when building the AST (even though it was set
   when building the modules)
2. The compiler argument adjustment to remove harmful and unnecessary
   flags only applied to indexing arguments, not those passed to the AST
   builds

Resolves rdar://141508656.

(cherry picked from commit ab12429651)
2025-02-07 16:31:07 -08:00
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
351a7814c6 Allow injection of build systems into SourceKitLSP
This allows us to clean up the creation of `TestBuildSystem` a little bit because the tests can create `TestBuildSystem` instead of retrieving it from the `BuildSystemManager`.

rdar://142906050
(cherry picked from commit 31b1909ce1)
2025-01-23 15:17:14 -08:00
Alex Hoppen
9e10ece2eb Remove imports of SwiftPM modules that are not strictly necessary
(cherry picked from commit 718c0ee809)
2025-01-23 11:43:18 -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
Alex Hoppen
1cd010db98 Merge pull request #1888 from ahoppen/indexstore-relative-compdb
Interpret the `-index-store-path` relative to the command’s directory
2024-12-13 23:47:50 +01:00
Alex Hoppen
b07044d25d Interpret the -index-store-path relative to the command’s directory
Fixes #1856
rdar://141004197
2024-12-13 18:35:13 +01:00
Alex Hoppen
8afacd7d7e Check that we get correct package version even if package manifest is invalid
Addresses https://github.com/swiftlang/sourcekit-lsp/pull/1846/files#r1856529041

rdar://141311942
2024-12-12 16:09:23 -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
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
bce09932ed Merge pull request #1714 from ahoppen/background-indexing-on 2024-11-16 21:58:12 -08:00
Alex Hoppen
84fc3fec1a Enable background indexing by default 2024-11-15 16:58:40 -08:00
Alex Hoppen
5627a4198c Enable testPluginArgs on Windows
This should be fixed by https://github.com/swiftlang/swift-package-manager/pull/8118
2024-11-15 15:10:43 -08:00
Alex Hoppen
9c84a344c8 Merge pull request #1817 from ahoppen/bsp-review 2024-11-14 08:10:02 -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
0fbb6466e7 Make BuildSystemKind a struct and rename to BuildSystemSpec 2024-11-13 10:23:43 -08:00
Alex Hoppen
5c7d495ebd Merge pull request #1808 from ahoppen/member-import-visibility
Adopt `MemberImportVisibility`
2024-11-07 15:38:05 -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
1d7c27bc4b Adopt MemberImportVisibility 2024-11-05 21:04:01 -08:00
Alex Hoppen
a22bf900ad Merge pull request #1781 from ahoppen/no-timer-target-change
Don’t rely on timers for BSP target / settings change tests
2024-10-29 13:02:30 -07:00
Alex Hoppen
64024f6cd7 Don’t rely on timers for BSP target / settings change tests
The timers were racy and on Windows we would get the updated build targets / build settings before we expect them. Change the tests to explicitly tell the build server when to change the targets / settings it reports by sending it a `workspace/didChangeWatchedFiles` notification.

This should also speed up the tests because we don’t have a 1s timer anymore.
2024-10-24 18:00:41 -07:00
Alex Hoppen
5d47358236 Merge pull request #1762 from ahoppen/build-settings-timeout 2024-10-23 23:50:58 -07: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
ee1fc93b7c Remove dependency on ISDBTestSupport
We weren’t using it anymore anyway.
2024-10-17 11:09:39 -07:00
Alex Hoppen
5bae73fca8 Use fallback build settings if build system doesn’t provide build settings within a timeout
When we receive build settings after hitting the timeout, we call `fileBuildSettingsChanged` on the delegate, which should cause the document to get re-opened in sourcekitd and diagnostics to get refreshed.

rdar://136332685
Fixes #1693
2024-10-16 10:55:29 -07:00
Rajveer
7b1f59e4a3 Update BSP connection build server config lookup path
Resolves #1695

Adopt `<workspace_root>/.bsp` search locations in addition to
`<workspace_root>/`.
2024-10-14 13:22:22 -07:00
Alex Hoppen
c16e33d281 Miscellaneous adjustments to make tests pass on Windows
This is mostly test infrastructure that needed adjusting.
2024-10-10 09:28:26 -07:00
Alex Hoppen
aa0aa927ca Stop using TSCBasic.resolveSymlinks and URL.resolvingSymlinksInPath 2024-10-09 13:16:57 -07:00
Alex Hoppen
dff72f1807 In withTaskPriorityChangedHandler execute the task that watches for priority changes with high priority
I saw a nondeterministic test failure of `AsyncUtilsTests.testWithTimeoutEscalatesPriority` and I believe this was the cause.

Also refactor a few test helper functions on the way.
2024-10-04 09:57:52 -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
8861f3a88d Merge pull request #1721 from ahoppen/improve-bsp-crash-recovery-test
Improve `BuildServerBuildSystemTests.testCrashRecovery`
2024-09-30 10:23:34 -07:00
Alex Hoppen
794d4936fe Revert "Use fallback build settings if build system doesn’t provide build settings within a timeout"
This reverts commit 78217ec6a6.
2024-09-27 12:32:47 -07:00
Alex Hoppen
f09f7e8714 Improve BuildServerBuildSystemTests.testCrashRecovery
The original idea behind this test was that only opening `Crash.swift` would retrieve build settings for `Crash.swift`. But that wasn’t actually true: Scanning for tests also retrieved build settings (to get the test’s module name). This caused test failures if we set `SOURCEKIT_LSP_TEST_TIMEOUT: 10`, like we do in `settings.json`.

Improve the test to actually check that the BSP server has crashed and increase timeout to be bigger than the 10s restart delay.
2024-09-27 10:58:50 -07:00
Alex Hoppen
b91f72f1d4 Merge pull request #1700 from ahoppen/build-settings-timeout
Use fallback build settings if build system doesn’t provide build settings within a timeout
2024-09-27 10:28:50 -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
78217ec6a6 Use fallback build settings if build system doesn’t provide build settings within a timeout
When we receive build settings after hitting the timeout, we call `fileBuildSettingsChanged` on the delegate, which should cause the document to get re-opened in sourcekitd and diagnostics to get refreshed.

rdar://136332685
2024-09-26 17:50:58 -07:00
Alex Hoppen
2b3d733af6 Restart a BSP server after it has crashed
If a BSP server crashes, we should try to relaunch it. Use a similar relaunch logic as the one we use for `clangd`: Try restarting immediately unless the BSP server has crashed within the last 30 seconds, in which case we delay the restart by 10s.

rdar://136311009
Fixes #1686
2024-09-25 13:57:43 -07:00
Alex Hoppen
1fd700b810 Expose all BSP messages used by SourceKit-LSP to BSP servers
The interaction to an out-of-process BSP server still went through the `BuildServerBuildSystem`, which doesn’t forward all messages to the build system and uses the old push-based model for build settings.

If we discover that the BSP server supports the new pull-based build settings model, we now forward all methods to it directly, without going through `BuiltInBuildSystemAdapter`, which has been renamed to `LegacyBuildServerBuildSystem`.

rdar://136106323
rdar://127606323
rdar://126493405
Fixes #1226
Fixes #1173
2024-09-24 22:47:07 -07:00
Alex Hoppen
5202a8fc1c Add test cases that launch a SourceKitLSP server using a BSP server 2024-09-20 17:15:34 -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
316790ff7a Review BuiltInBuildSystem 2024-09-16 10:12:34 -07:00