Commit Graph

2802 Commits

Author SHA1 Message Date
Anthony Latsis
b5bc65308c Fix build after https://github.com/swiftlang/swift-docc/pull/1331 2025-11-15 01:41:54 +00:00
Alex Hoppen
ff2f984dbb Merge pull request #1562 from antigluten/code-action-zero-parameter-function 2025-11-14 15:22:36 +01:00
Vladimir Gusev
9647dcc3dc Convert between computed properties and zero-parameters functions 2025-11-14 12:00:46 +03:00
Alex Hoppen
5fe1079a75 Merge pull request #2352 from Kila2/main
fix failed to override buildSettingsTimeout when override is nil
2025-11-13 02:41:31 +01:00
lijunliang.9819
239e45597e fix failed to override buildSettingsTimeout when override is nil 2025-11-12 12:45:43 +08:00
Adam Ward
927d347778 Fix spelling error in CMakelist 2025-11-11 13:48:06 -05:00
Adam Ward
2830c55fc0 Fix Swift format error 2025-11-11 13:46:02 -05:00
award999
0366a4dcbb Update Sources/SwiftLanguageService/CMakeLists.txt
Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2025-11-11 07:52:52 -05:00
Adam Ward
0f82f33f96 Use utf8 column 2025-11-10 11:14:25 -05:00
Adam Ward
ddcddded67 Support swift.play in textDocument/codelens request
- New `swift.play` CodeLens support that is an experimental feature while [swift play](https://github.com/apple/swift-play-experimental/) is still experimental
- Add #Playground macro visitor to parse the macro expansions
- File must `import Playgrounds` to record the macro expansion
- The `swift-play` binary must exist in the toolchain to
- TextDocumentPlayground will record the id and optionally label to match detail you get from
```
$ swift play --list
Building for debugging...
Found 1 Playground
* Fibonacci/Fibonacci.swift:23 "Fibonacci"
```
- Add LSP extension documentation for designing pending `workspace/playground` request
- Add new parsing test cases
- Update CMake files

Issue: #2339 #2343

Add column to unnamed label

Update Sources/SwiftLanguageService/SwiftCodeLensScanner.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Update Sources/SwiftLanguageService/SwiftPlaygroundsScanner.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Update Sources/SwiftLanguageService/SwiftPlaygroundsScanner.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Update Tests/SourceKitLSPTests/CodeLensTests.swift

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>

Address review comments

Fix test failures

Fix more review comments

Update for swift-tools-core
2025-11-07 15:51:17 -05:00
Ben Barham
d046c7be2d Temporarily skip macro tests on Amazon Linux
These are failing on the 2023 bootstrap job, skip for now to allow
getting a toolchain out.
2025-11-06 07:15:10 +10:00
Mishal Shah
0876b7d403 Merge pull request #2324 from owenv/owenv/adopt-swift-tools-protocols
Adopt swift-tools-protocols
2025-11-05 09:02:00 -08:00
Alex Hoppen
1be4895224 Merge pull request #2331 from ahoppen/arg-completion-closing-paren
Add a closing parenthesis to function argument completions
2025-11-03 07:42:56 +01:00
Doug Gregor
95f2fc673a Merge pull request #2345 from gottesmm/rdar146378329
Add [weak self] in two places.
2025-11-01 06:34:12 -07:00
Michael Gottesman
43dd488d00 Add [weak self] in two places.
The reason why I am making the first change is because in a separate PR in
swiftlang I am fixing a bug that caused certain captured parameters to be
treated as sending parameters incorrectly. This allowed for parameters to
incorrectly be allowed to be sent from one isolation domain to another.

The specific problem here can be seen with the following swift code:

```swift
actor B {
  init(callback: @escaping @Sendable () -> Void) async {}
}

actor A {
  private func poke() {}
  func schedule() async {
    _ = await B(
      callback: { [weak self] in // closure 1
        Task.detached { // closure 2
          await self?.poke()
        }
      })
  }
}
```

When we capture the weak self from closure 1 in closure 2, we are not actually
capturing self directly. Instead we are capturing the var box which contains the
weak self. The box (unlike self) is actually non-Sendable. Since closure 2 is
not call(once), the compiler must assume semantically that the closure can be
invoked potentially multiple times meaning that it cannot allow for self to be
used in Task.detached. The fix for this is to perform an inner [weak self]
capture. As follows:

```swift
actor A {
  private func poke() {}
  func schedule() async {
    _ = await B(
      callback: { [weak self] in // closure 1
        Task.detached { [weak self] // closure 2
          await self?.poke()
        }
      })
  }
}
```

The reason why this works is that when we form the second weak self binding, we
perform a load from the outer weak self giving us an Optional<A>. Then we store
that optional value back into a new weak box. Since Optional<A> is Sendable, we
know that the two non-Sendable weak var boxes are completely unrelated, so we
can send that new var box into the new Task.detached safely.

The second `[weak self]` is just something I noticed later in the function. The
`[weak self]` just makes the detached function safer.
2025-10-31 14:52:37 -07:00
Owen Voorhees
f04b971726 Adopt swift-tools-protocols 2025-10-31 14:11:11 -07:00
Rintaro Ishizaki
a0c6c6ed91 Merge pull request #2342 from rintaro/base-message-protocols
[LSP/BSP] Separate base message protocol for LSP and BSP message types
2025-10-31 09:26:10 -07:00
Alex Hoppen
79562ebfe6 Merge pull request #2334 from ahoppen/relative-compile-commands
Interpret the working directories in `compile_commands.json` relative to the directory that contains `compile_commands.json`
2025-10-31 09:54:52 +01:00
Rintaro Ishizaki
651d4da6b4 [LSP/BSP] Separate base message protocol for LSP and BSP message types
Introduce `LSPRequest`, `LSPNotification`, `BSPRequest`, and
`BSPNotification`. And change the protocol of the each concrete type.
This is beneficial for implementing LSP/BSP only message handlers.
2025-10-30 11:38:35 -07:00
Alex Hoppen
d9295b2c93 Add a closing parenthesis to function argument completions
Fixes #782
2025-10-30 14:38:33 +01:00
Alex Hoppen
bf7680471b Don’t set empty array values in the SourceKitLSPOptions from command-line arguments 2025-10-30 08:38:58 +01:00
Alex Hoppen
c34d9e20fe Interpret the working directories in compile_commands.json relative to the directory that contains compile_commands.json
Fixes #1908
2025-10-30 08:38:08 +01:00
Alex Hoppen
d19f829774 Fix issue that caused background indexing to be disabled when sourcekit-lsp is launched without options
When launching sourcekit-lsp without any command-line arguments, we would set `backgroundIndexing = false` in the options. Unless the user overwrites this somehow, this means that background indexing is disabled.

This is not an issue in VS Code, because it explicitly enables background indexing in the initialization request but for all other editors this means that background indexing was likely disabled by default.

Simply remove that line since `backgroundIndexing` defaults to `true` by now anyway.
2025-10-27 20:26:37 +01:00
Alex Hoppen
79964c8d7d Merge pull request #2326 from ahoppen/remove-unused-imports
Add a code action to remove unused imports in a source file
2025-10-23 22:10:46 +02:00
Alex Hoppen
4c957506e8 Add a code action to remove unused imports in a source file
The idea is pretty simple: When `MemberImportVisibility` is enabled, we know that imports can only affect the current source file. So, we can just try and remove every single `import` declaration in the file, check if a new error occurred and if not, we can safely remove it.
2025-10-22 23:56:09 +02:00
Alex Hoppen
4dac2bb7f3 Add missing parentheses around logging scope computation
The modulo operator associated `0` and `100`, so the computation here was essentially `handle?.numericValue ?? (0 % 100)`, equivalent to `handle?.numericValue ?? 0`, which means that we didn’t acutally perform modulo operations on the numeric value, which means that we would exceed the maximum number of `os_log_t` objects after some time.

rdar://162891887
2025-10-22 23:25:51 +02:00
Alex Hoppen
16c60b5914 Merge pull request #2322 from ahoppen/build-settings-from-sibling
Infer build settings from sibling file if a file’s target cannot be determined
2025-10-17 13:49:25 +02:00
Alex Hoppen
76847dbf27 Do not try to infer build settings from a sibling file if determining the target timed out 2025-10-16 07:44:54 +02:00
Alex Hoppen
2ad02363a3 Show inlay hints of #if conditions at their corresponding #endif directives
Fixes #2221
2025-10-13 16:35:05 +02:00
Alex Hoppen
c360cfa8c1 Make buildSettings(for:in:langauge:fallbackAfterTimeout:) require a target
This simplifies the control flow to get build settings slightly.
2025-10-11 12:20:13 +02:00
Alex Hoppen
f7dba31ac9 Infer build settings from a sibling file if current file doesn’t have build settings 2025-10-11 12:20:12 +02:00
Alex Hoppen
abf98b9283 Merge pull request #2314 from ahoppen/new-upcoming-features
Enable `InferIsolatedConformances` and `NonisolatedNonsendingByDefault`
2025-10-09 20:46:03 +02:00
Alex Hoppen
9dff775010 Enable InferIsolatedConformances and NonisolatedNonsendingByDefault
This allows us to easily get rid of some `@_inheritActorContext`. The others seem to be a little more tricky and I haven’t spent too much time at trying to figure out how to remove the attribute from those.
2025-10-09 00:46:48 +02:00
Hamish Knight
9e552ddd47 Avoid crashing on invalid range in editDocument
Rename `LineTable.replace(utf8Offset:length:with)` to `tryReplace`
and bail if the provided range is out of bounds of the buffer. This
ensures we match the behavior of SourceKit when handling an
`editor.replacetext` request.

rdar://161268691
2025-10-02 14:47:04 +01:00
Hamish Knight
c3c1b8e116 NFC: Remove a couple of unused functions 2025-10-02 14:47:04 +01:00
Doug Gregor
555816c651 Merge pull request #2312 from DougGregor/swift-if-config-dependency
Add SwiftIfConfig as a dependency for macro testing
2025-09-30 18:08:20 -07:00
Doug Gregor
8f6da7c439 Add SwiftIfConfig as a dependency for macro testing 2025-09-30 09:20:29 -07:00
Alex Hoppen
331f15659c Merge pull request #2311 from ahoppen/long-build-server-init
Do not block SourceKit-LSP functionality when a build server takes long to initialize
2025-09-30 08:22:24 +01:00
Alex Hoppen
b4230109f7 Merge pull request #2310 from ahoppen/flush-log 2025-09-30 07:48:52 +01:00
Ben Barham
72b6e756ef Merge pull request #2308 from bnbarham/remove-precondition
Avoid crashing when loading client plugins from the same path
2025-09-29 07:48:12 -07:00
Alex Hoppen
a6c291b84e Do not block SourceKit-LSP functionality when a build server takes long to initialize
We previously waited for the initialization response from the build server during the creation of a `Workspace` so that we could create a `SemanticIndexManager` with the index store path etc. that was returned by the `build/initialize` response. This caused all functionality (including syntactic) of SourceKit-LSP to be blocked until the build server was initialized.

Change the computation of the `SemanticIndexManager` and related types to happen in the background so that we can provide functionality that doesn’t rely on the build server immediately.

Fixes #2304
2025-09-29 13:02:08 +01:00
Alex Hoppen
6b494ddf95 Flush logs at the end of test execution
Otherwise it sometimes happens that shutdown and other messages are logged during the next test’s execution, which makes it harder to diagnose issues.
2025-09-29 13:51:09 +02:00
Ben Barham
8c4f1ad847 Log when absolute compilation DB search paths are skipped
Absolute search paths were being ignored without logging, which makes it
somewhat difficult to diagnose. Log when they're skipped.

Also remove a duplicate options merging block - both
`createWorkspaceWithInferredBuildServer` and `findImplicitWorkspace`
(the only callers of `createWorkspace`) already merge in the workspace
options.
2025-09-26 14:25:55 -07:00
Ben Barham
add109d2d8 Avoid crashing when loading client plugins from the same path
When `DYLD_(FRAMEWORK|LIBRARY)_PATH` is set, `dlopen` will first check
if the basename of the provided path is within any of its search paths.
Thus it's possible that only a single library is loaded for each
toolchain, rather than a separate like we expect. The paths should be
equal in this case, since the client plugin is loaded based on the path
of `sourcekitd.framework` (and we should only have one for the same
reason). Allow this case and just avoid re-initializing.
2025-09-26 12:22:59 -07:00
Alex Hoppen
95538e7de9 Migrate appendingPathComponent to appending(component:)
`appending(component:)` is the more modern API and can take multiple path components at the same time.
2025-09-23 16:57:56 +02:00
Alex Hoppen
32e919c0cd Merge pull request #2302 from ahoppen/multi-file-indexing-batch-size
Match the batch size for multi-file indexing to the driver's batch size
2025-09-23 16:53:57 +02:00
Alex Hoppen
868e218e6f Merge pull request #2303 from ahoppen/active-processor-count
Use `activeProcessorCount` instead of `processorCount` in short-lived use-cases
2025-09-23 16:53:34 +02:00
Ben Barham
d4047382c7 Merge pull request #2289 from bnbarham/infinite-root-2
Standardize file paths when attempting to find toolchains
2025-09-22 13:29:17 -07:00
Alex Hoppen
aa7ff70042 Merge pull request #2300 from ahoppen/drop-6.1
Drop support for building with Swift 6.1
2025-09-22 14:16:39 +02:00
Alex Hoppen
05c04decf2 Match the batch size for multi-file indexing to the driver's batch size
Until we have better measurements that would motivate a different batching strategy, copying the driver’s batch size seems like the most reasonable thing to do.
2025-09-22 09:52:44 +02:00