Commit Graph

1114 Commits

Author SHA1 Message Date
Alex Hoppen
e6ca874c1a Merge pull request #2086 from ahoppen/generated-interface-diags
Don’t return diagnostics for generated interfaces
2025-03-25 09:10:46 -07:00
Alex Hoppen
686c225520 Don’t return diagnostics for generated interfaces
Trying to get diagnostics for generated interfaces fails with: `'<…>' is not part of the input files`

rdar://146949806
2025-03-21 17:55:54 -07:00
Alex Hoppen
dd2d2aff49 Fix some more quadratic performance issues in AsyncQueue
We would hit quadratic behavior in `AsyncQueue` when the build system floods us with `build/logMessage` or `build/task(Start|Progress|Finish)` notifications because we record a dependency on all of the pending log message handling tasks.

We can extend the improvement made in https://github.com/swiftlang/sourcekit-lsp/pull/1840 to fix this quadratic problem: If the current task depends on a task with metadata that depends on itself (ie. all tasks of metadata that needs to be executed in-order), we only need to depend on the last task with that metadata.

This covers many message types and we can now only get into quadratic behavior if we get flooded with two different kinds of messages: One that does not have a self-dependency and one that depends on the message without a self-dependency. In terms of LSP messages, this could be a document read followed by a document update, but I think this is a lot more unlikely than getting spammed with one type of message.
2025-03-21 17:33:55 -07:00
Alex Hoppen
d10c868497 Support indexing a file in the context of multiple targets
If a source file is part of multiple targets, we should index it in the context of all of those targets because the different targets may produce different USRs since they might use different build settings to interpret the file.
2025-03-14 15:49:59 -07:00
Alex Hoppen
3cd38658cb Merge pull request #2065 from ahoppen/refresh-diags-sourcekitd-restored
Refresh diagnostics when sourcekitd has been restored
2025-03-14 15:11:30 -07:00
Alex Hoppen
1f1e440dd8 Merge pull request #2060 from ahoppen/synchronize-request
Generalize `PollIndexRequest` and `BarrierRequest` into a single `SynchronizeRequest`
2025-03-14 15:10:13 -07:00
Alex Hoppen
6c74631aca Refresh diagnostics when sourcekitd has been restored
After sourcekitd has been restored, we can provide diagnostics again, so tell the editor to reload them.
2025-03-13 21:17:48 -07:00
Alex Hoppen
9c867df103 Merge pull request #2057 from ahoppen/test-timeout
Add a few timeout checks to tests
2025-03-13 13:46:06 -07:00
Alex Hoppen
5fba1699bd Generalize PollIndexRequest and BarrierRequest into a single SynchronizeRequest
This new request also allows us to wait for build system updates without waiting for background indexing to finish.
2025-03-12 14:25:50 -07:00
Alex Hoppen
d645f44735 Merge pull request #2054 from ahoppen/file-change-freestanding
Handle file did change notifications as freestanding messages
2025-03-12 14:21:42 -07:00
Alex Hoppen
209fb1b602 Merge pull request #2053 from ahoppen/index-progress
Don't increment in-progress task counter for files that cannot be indexed
2025-03-12 14:21:34 -07:00
Alex Hoppen
572660ae26 Add timeouts to most subprocess calls in tests
Just a speculative fix to avoid timeouts during the `swift test` invocation
2025-03-11 09:20:44 -07:00
Alex Hoppen
55b514f6a4 Log the source files that are marked in-progress when updating the index status
If we have a bug in index status tracking, this helps figure out which files are considered to be currently indexed.
2025-03-11 08:31:21 -07:00
Alex Hoppen
bdd6ab1ecc Merge pull request #2048 from ahoppen/diag-refresh-capability
Do not send `DiagnosticsRefreshRequest` to the client if it doesn't support it
2025-03-11 02:42:38 -07:00
Alex Hoppen
ce75053555 Handle file did change notifications as freestanding messages
Technically, the watched files notification can change the response of any other request (eg. because a target needs to be re-prepared). But treating it as a `globalConfiguration` inserts a lot of barriers in request  handling and significantly prevents parallelism. Since many editors batch file change notifications already, they might have delayed the file change notification even more, which is equivalent to handling the  notification a little later inside SourceKit-LSP. Thus, treating it as `freestanding` should be acceptable.

Also, simplify the logic needed in tests to write modified files to disk because we now need to run a barrier request in tests to ensure that the watched file notification has been handled.
2025-03-10 21:44:35 -07:00
Alex Hoppen
776d019ec9 Do not send DiagnosticsRefreshRequest to the client if it doesn't support it
Check if the client's capabilities to see if it supports `workspace/diagnostic/refresh`.
2025-03-10 14:11:23 -07:00
Alex Hoppen
8aa8fa0ff8 Remove offensive terms from the codebase 2025-03-07 13:58:02 -08:00
Alex Hoppen
1cfa8db1d8 Require Swift 6 to build SourceKit-LSP
This significantly cleans up our `import` statements
2025-03-07 08:05:49 -08:00
Alex Hoppen
698b384a8b Add - to swift-format invocation to indicate that file contents should be read from stdin
To match https://github.com/swiftlang/swift-format/pull/914
2025-03-06 22:53:26 -08:00
Alex Hoppen
2a1fd10295 Add an experimental LSP request to return the output paths for all files in a target 2025-03-06 08:30:47 -08:00
Alex Hoppen
2a12d21378 Merge pull request #2036 from ahoppen/log-invalid-language
Add log message if we can’t infer the language server type for a document that was opened
2025-03-05 23:50:46 -08:00
Alex Hoppen
9f5f06bc57 Merge pull request #2032 from ahoppen/ahoppen/response-file-indexing
Use response files to index files if argument list exceeds maximum number of arguments
2025-03-05 23:50:33 -08:00
Alex Hoppen
2bb79e3888 Add log message if we can’t infer the language server type for a document that was opened
Motivated by https://github.com/swiftlang/sourcekit-lsp/issues/2028#issuecomment-2702162160.
2025-03-05 13:53:28 -08:00
Alex Hoppen
5541060451 Use response files to index files if argument list exceeds maximum number of arguments 2025-03-05 13:33:40 -08:00
Alex Hoppen
51a035dce2 Use the BSP output file paths request to exclude units from the index that are no longer part of any targets 2025-03-05 09:58:37 -08:00
Alex Hoppen
2a05d940ff Merge pull request #2022 from ahoppen/structure-index-log
Add structure to the index logs
2025-03-05 09:56:47 -08:00
Alex Hoppen
655a93f05a Add structure to the index logs
When the client supports it, communicate the structure of tasks that were stared during background indexing or by the build server to the client. If there are multiple operations happening in parallel, this allows the client to display them in separate log tracks instead of interspersing them with the emoji prefixes like we do today.
2025-03-04 16:36:26 -08:00
Alex Hoppen
d696a946cd Merge pull request #2033 from ahoppen/standardized-file-paths
Allow a build system to use standardized paths while indexstore-db return realpaths
2025-03-04 16:34:56 -08:00
Alex Hoppen
f07a4bd531 Mark target preparation out-of-date when it has changed in the build server
When the target changes in the build server, it’s build settings might have changed, which  means that we can no longer assume that it’s up-to-date.
2025-03-04 08:51:53 -08:00
Alex Hoppen
28e3f99319 Allow a build system to use standardized paths while indexstore-db return realpaths
On Darwin platforms, this fixes the following problem: indexstore-db by itself returns realpaths but the build system might be using standardized Darwin paths (eg. realpath is `/private/tmp` but the standardized path is `/tmp`). Because of this, when inferring the main file for a file, we might get a URI that the build system doesn’t know about. To fix this, if the realpath that indexstore-db returns could not be found in the build system's source files but the standardized path is part of the source files, use the standardized path instead.
2025-03-03 21:16:14 -08:00
Alex Hoppen
bafd8babc1 Merge pull request #2013 from ahoppen/clean-background-index-up-to-date-checks
When the build system sends an update for build targets, update the index for the files in those targets
2025-03-03 20:34:13 -08:00
Alex Hoppen
6818cbe45a Log a few strings publicly
Just something I noticed while reading logs
2025-03-03 13:29:29 -08:00
Alex Hoppen
15c34bf849 Do not schedule re-indexing of files if they haven’t been modified since an in-progress index was requested
This fixes the following problem, which caused files to get indexed twice: You open a workspace, which schedules initial indexing. While we are waiting for the build graph generation from the build server, the build servers sends `buildTarget/didChange` notification to SourceKit-LSP (eg. because it has finished loading the build graph). This causes all files in the changed targets to be scheduled for re-indexing since new files might be present in the updated targets. And since we have already started indexing of those files, we assumed that we need to index them again because the contents might have changed.

To fix this, keep track of the file’s modification time at the time at which we scheduled indexing for it. If that time hasn’t changed and we have an in-progress indexing operation for it, there is no need to schedule another one.
2025-03-03 13:10:29 -08:00
Alex Hoppen
1c968226f1 When the build system sends an update for build targets, update the index for the files in those targets
For each file in the changed targets, we still check whether it has an up-to-date unit based on timestamps. The important thing for this change is that we start indexing files for which we only receive build settings after an update from the build server.
2025-03-01 09:25:45 -08:00
Alex Hoppen
0a54c25785 Merge pull request #1999 from ahoppen/schedule-initial-syntactic-test-population
Do not block initialization of the build server when build server is unresponsive in returning the list of test files
2025-02-28 15:36:17 -08:00
Alex Hoppen
3fc3616988 Merge pull request #2019 from ahoppen/sourcekitoptions-improvements
Small improvements to `workspace/_sourceKitOptions` request
2025-02-28 15:35:55 -08:00
Alex Hoppen
37aaa9218a Mark workspace/_sourceKitOptions as freestanding
The request doesn’t depend on any document state, so it should be freestanding instead of `workspaceRequest`.
2025-02-27 19:04:26 -08:00
Alex Hoppen
6a1d923f5b Add a request to check if SourceKit-LSP is currently performing any indexing 2025-02-27 12:52:28 -08:00
Alex Hoppen
bd6fb5d04c Do not block initialization of the build server when build server is unresponsive in returning the list of test files
We were blocking the initialization response on `self.buildSystemManager.testFiles`, which requires the list of test files to be determined. Make that operation asynchronous so that a slow build server can’t take down all of SourceKit-LSP.
2025-02-26 16:31:29 -08:00
Alex Hoppen
f4e015b3c0 Merge pull request #1988 from ahoppen/sourcekitoptions
Add an experimental request to return the build settings that SourceKit-LSP uses to process a file
2025-02-26 16:06:20 -08:00
Alex Hoppen
dae74db63c Merge pull request #2011 from ahoppen/client-specified-id
Add a `send` method to `InProcessSourceKitLSPClient` and `LocalConnection` in which the client specifies the request ID
2025-02-26 16:06:05 -08:00
Alex Hoppen
0258d1dd63 Merge pull request #2007 from ahoppen/dont-cache-failed-diag-reports
Do not cache diagnostic reports for sourcekitd requests that have failed
2025-02-26 16:05:42 -08:00
Alex Hoppen
66793ffbb2 Merge pull request #2000 from ahoppen/index-store-path-option
If a build server doesn’t specify `-index-store-path` in the SourceKit options, add it during background indexing
2025-02-26 12:30:07 -08:00
Alex Hoppen
9496b49c72 Add an experimental request to return the build settings that SourceKit-LSP uses to process a file
This can be useful to IDEs that want to perform some additional semantic processing of source files, which requires knowledge of a file’s build settings.
2025-02-26 09:12:47 -08:00
Alex Hoppen
db792c536f Add a send method to InProcessSourceKitLSPClient and Connection in which the client specifies the request ID 2025-02-26 08:41:30 -08:00
Alex Hoppen
c311e1bb13 Merge pull request #2003 from ahoppen/no-poll-index-for-file-change
Don’t poll the index for unit changes on every `filesDidChange` call
2025-02-25 20:56:29 -08:00
Alex Hoppen
abea29c9fa Do not cache diagnostic reports for sourcekitd requests that have failed
Otherwise, we return the failed diagnostic report even after sourcekitd has been restored.

Also, make sure that we don't show the `semantic editor is disabled` error to users.
2025-02-25 20:29:21 -08:00
Alex Hoppen
c40a786a6a Merge pull request #1994 from ahoppen/active-document-refinements
A couple refinements to the `window/didChangeActiveDocument` notification
2025-02-25 20:23:09 -08:00
Alex Hoppen
1209747496 Merge pull request #2001 from ahoppen/add-call-with-no-defaulted-arguments
Add calls with no defaulted arguments to code completion results
2025-02-25 19:53:08 -08:00
Alex Hoppen
447b8b5cbc Don’t poll the index for unit changes on every filesDidChange call
`pollForUnitChangesAndWait` is a costly operation since it iterates through all the unit files on the file system. We should only run it during initial indexing (where we might need to build the initial indexstore-db) but not for any subsequent indexing calls.
2025-02-25 15:15:09 -08:00