Commit Graph

198 Commits

Author SHA1 Message Date
Alex Hoppen
3f7d9a7b76 Fix a non-deterministic test failure in testPrepareTargetAfterEditToDependency
We could get a `DiagnosticsRefreshRequest` before the modified target had been re-prepared.
2024-05-22 14:46:03 -07:00
Alex Hoppen
9e49f67455 Rename TestSourceKitLSPClient.handleNextRequest to handleSingleRequest
Since `handleNextRequest` handling doesn’t have to be in the order that the request handlers were specified anymore, the naming was misleading.
2024-05-22 13:31:58 -07:00
Alex Hoppen
da96d45443 Add a development subcommand to index a project
This allows us to run `sourcekit-lsp index --project /path/to/project` to index a project. Intended to debugging purposes, eg.
- Profile the time it takes to index a project
- See if the project can be indexed successfully
- Look at signposts generated during indexing in Instruments to see whether indexing or preparation is the bottleneck and how well we can parallelize tasks.
2024-05-21 22:29:52 -07:00
Alex Hoppen
3e6319c3b9 Produce an index log for the client
This allows a user of SourceKit-LSP to inspect the result of background indexing. This allows a user of SourceKit-LSP to inspect the result of background indexing. I think this gives useful insights into what SourceKit-LSP is indexing and why/how it fails, if it fails, also for users of SourceKit-LSP.

rdar://127474136
Fixes #1265
2024-05-21 22:18:06 -07:00
Alex Hoppen
d12c946988 Merge pull request #1321 from ahoppen/target-preparation-testing 2024-05-20 20:02:01 -07:00
Alex Hoppen
815fea827e Add infrastructure to test which targets are being prepared 2024-05-20 09:49:24 -07:00
Alex Hoppen
195d3af74e Move LocalConnection to LSPTestSupport
We weren’t logging requests sent to a `TestSourceKitLSPClient` because we were assuming that `JSONRPCConnection` logs those requests in `SourceKitLSPServer`. But no logging happens in `LocalConnection`, which `TestSourceKitLSPClient` uses.

Since `LangaugeServerProtcol` can’t depend on `LSPLogging`, move the type to `LSPTestsSupport`.
2024-05-17 11:59:40 -07:00
Alex Hoppen
546bb3230e Update index as files are modified on disk
Fixes #1251
rdar://127476161
2024-05-15 11:00:13 -07:00
Alex Hoppen
fae712b278 Make SKTestSupport build in Swift 6 mode 2024-05-14 15:04:33 -07:00
Alex Hoppen
66ecdd35b7 Make SKSwiftPMWorkspaceTests build in Swift 6 mode 2024-05-14 15:00:43 -07:00
Alex Hoppen
c09b47f164 Make SKCoreTests build in Swift 6 mode 2024-05-14 15:00:43 -07:00
Alex Hoppen
f8407b9f40 Make DiagnoseTests build in Swift 6 mode 2024-05-14 15:00:43 -07:00
Alex Hoppen
c9b51f9b34 Allow client request handlers specified on TestSourceKitLSPClient to be executed in any order 2024-05-14 06:38:22 -07:00
Alex Hoppen
eaa378f390 Plumb capabilities to SwiftPMTestProject and add a closure that can be executed before SourceKit-LSP is initialized 2024-05-14 06:38:22 -07:00
Alex Hoppen
13176b012d Address review comments 2024-05-10 14:43:32 -07:00
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07:00
Alex Hoppen
1a5d1321a1 Implement initial background indexing of a project
Implements an initial background index when the project is opened.

The following will be implemented in follow-up PRs:
- Resolving package dependencies
- Preparing dependent modules
- Watching for file updates
2024-05-05 14:26:52 -07:00
Alex Hoppen
e5254c0c8e Allow serverOptions to be specified on SwiftPMTestProject
This will allow us to conditionally enable background indexing in tests
2024-05-03 14:48:15 -07:00
Alex Hoppen
0ea9ae7187 Don’t use workingDirectory when creating a SwiftPMDependencyProject
Creating `Process` on Amazon Linux fails with: `workingDirectory is not supported in this platform`. Instead of setting a working directory, pass the working directory as `-C` to `git` when creating a `SwiftPMDependencyProject`.
2024-05-02 11:47:25 -07:00
Alex Hoppen
1d9b67b0b9 Don’t include files from package dependencies in the syntactic test index
`SwiftPMBuildSystem.testFiles()` returned all source files in the package, including files of package dependencies. This caused us to index those files for tests in the syntactic test index, which we should not.

Make `SwiftPMBuildSystem.testFiles` only return files from the root package.

Also add test infrastructure to be able to test cross-package functionality.

rdar://126965614
2024-04-24 11:13:40 -07:00
Alex Hoppen
ec5c614318 Merge pull request #1175 from ahoppen/syntactic-test-index 2024-04-24 07:01:34 -07:00
Alex Hoppen
fd7b268431 Reload a file when other files within the same module or a .swiftmodule file has been changed
When the client sends us `workspace/didChangeWatchedFiles` notification of an updated `.swift` file, we should refresh the other open files in that module since they might be referencing functions from that updated file.

If a `.swiftmodule` file has been updated, we refresh all the files within the package since they might import that module. Technically, we would only need to refresh files that are in module that are downstream of the updated module but we don’t currently have that information easily available from SwiftPM. Also, usually, if the client has a file from a low-level module open, he’ll be working on that module which means that such an optimization won’t help. The real solution here is to wait for us to finish preparation (which we would exactly know when it finishes since sourcekit-lsp would schedule it) but for that we need to implement background preparation.

Fixes #620
Fixes #1116
rdar://99329579
rdar://123971779
2024-04-23 09:34:20 -07:00
Alex Hoppen
a799da39aa Implement a syntactic workspace-wide test index
This workspace-wide syntactic test index is used for two purposes:
- It is used for XCTests instead of the semantic index for files that have on-disk or in-memory modifications to files
- It is uses for swift-testing tests, which are only discovered syntactically.

rdar://119191037
2024-04-23 09:25:31 -07:00
Alex Hoppen
8ed842b96d Show unapplied function references in call hierarchy
With https://github.com/apple/swift/pull/72930 we can use the `containedBy` instead of `calledBy` relation for the call hierarchy, which allows us to show unapplied function references in the call hierarchy as well.

rdar://123769825
2024-04-19 21:47:54 -07:00
Alex Hoppen
08f1595b5b Never return nil for position conversions
Instead of returning `nil` to indicate that the position conversion failed, log a fault and perform a best-effort recovery.

I think this allows us to perform better recovery and also makes code calling these position conversions a lot simpler because it doesn’t need to make decisions about what to do if position conversions fail.
2024-04-11 13:59:17 -07:00
Gremlinflat
3b5d997f49 add missing props 2024-03-26 06:21:14 +07:00
Gremlinflat
f392e2ffe3 feat: clean up & finish all todo 2024-03-26 01:07:41 +07:00
Gremlinflat
0e9c5450f9 chore: deprecate array extension for SyntaxHighlightingToken 2024-03-26 01:06:31 +07:00
Gremlinflat
315fff84f8 feat: add SyntaxHighlightingTokens wrapper struct 2024-03-25 23:43:45 +07:00
Alex Hoppen
161171668c Rename test projects for consistency
Rename all the classes that write files to disk to create a test project that we can open in sourcekit-lsp to end with `TestProject`. This is better than the old `Workspace` suffix because it avoids ambiguities with the `Workspace` type inside sourcekit-lsp.

- IndexedSingleSwiftFileWorkspace -> IndexedSingleSwiftFileTestProject
- MultiFileTestWorkspace -> MultiFileTestProject
- SwiftPMTestWorkspace -> SwiftPMTestProject
2024-03-20 22:50:34 +01:00
Alex Hoppen
4b5f7ffd90 Rename SourceKitServer -> SourceKitLSPServer
This avoid ambiguities whether `SourceKitServer` handles sourcekitd or `sourcekit-lsp`.
2024-03-20 22:50:34 +01:00
Alex Hoppen
3007d9f392 Naming improvements, added comments and typo fixes in connection related code
This should make the code easier to understand. No functionality change.
2024-03-20 08:30:16 +01:00
Alex Hoppen
7c46df3abe Remove clientID from request handling
The client ID was needed when a `MessageHandler` could handle messages from multiple connections. We don’t support this anymore (because it wasn’t needed) and so the client ID doesn’t need to get passed through as well.
2024-03-20 08:28:26 +01:00
Alex Hoppen
331f16dca7 Merge pull request #1091 from ahoppen/ahoppen/markdown-documentation
Emit raw documentation comments instead of parsing XML
2024-03-01 14:05:12 -08:00
Alex Hoppen
1877d470a3 Use pull diagnostics by default in tests
Currently, all tests send publish diagnostics notifications, which is noise in the logs for most tests. Change the tests to use the pull diagnostics model by default and make the push diagnostic model opt-in.

rdar://123241539
2024-02-27 19:06:20 -08:00
Alex Hoppen
a6b8cbecad Emit raw documentation comments instead of parsing XML
Fixes #1014
rdar://120685874
2024-02-26 19:55:23 -08:00
Alex Hoppen
a60690858c Show message in the client if no compiler arguments could be found for a file
This should help users debug issues when functionality is not working because compiler arguments are missing.

Note that when opening a standalone Swift file, we consider that file as having non-fallback build settings, even though the build settings are synthesized from the fallback build system. Thus, this will only pop up when the user is in a context that has some build system (like a compilation database or a Swift package) but the current file isn’t handled by that.

rdar://119741960
2024-02-23 23:46:49 -08:00
Alex Hoppen
3d82a89d32 If sourcekitd doesn't support the semantic tokens request, return results from swift-syntax
This offers a better fallback than not returning any results at all.

Fixes #1009
rdar://120124113
2024-02-22 22:19:25 -08:00
Alex Hoppen
4117a77c6c Support rename of a function’s name started from a parameter or argument label
When starting rename from a function parameter’s label, we should be performing a rename of the function signature. To do that, we need to do some adjustments of th rename positions in order to get the position of the function’s base name and use that for the rename requests sent to sourcekitd.

rdar://119875277
2024-02-21 11:02:15 -08:00
Alex Hoppen
e184dc0385 Skip formatting tests if host toolchain doesn’t contain swift-format 2024-02-16 16:06:01 -08:00
Alex Hoppen
20e734e6b1 Skip tests that require the workspace/indexedRename request if clangd doesn’t have support for it 2024-02-14 12:52:32 -08:00
Alex Hoppen
0c79a6b644 Add infrastructure for skipping tests if the host toolchain doesn't support them
Up until now we have skipped tests on a very ad-hoc basis and some of these skips have lingered around much longer than they were needed.

Add infrastructure to check if a given host toolchain has a feature required by a test. The key ideas here are:
- The skip check specifies a Swift version in which the required feature was introduced. Any newer Swift versions are always considered to support this feature. This allows us to remove the checks once the minimum required version to test sourcekit-lsp exceeds the specified version.
- If the toolchain version is the same as the Swift version that introduces the feature, we execute a closure that performs a fine-grained check to see if the feature is indeed supported. This differentiates toolchain snapshots which contain the feature from those that don’t.
- Tests are never skipped in Swift CI. This ensures that we don’t get passing tests because we hit the skip condition even though we are not expecting to hit it in Swift CI, which should have built an up-to-date toolchain.
- Use this new infrastructure to skip tests that aren’t passing using older Swift versions.

rdar://121911039
2024-02-02 21:16:09 -08:00
Alex Hoppen
378b62d8e1 Fix warnings when building sourcekit-lsp 2024-01-31 17:59:05 -08:00
Alex Hoppen
6505ec8f7e Make ToolchainRegistry initializer synchronous
This requires a bit of a restructuring of `ToolchainRegistry` because calling `scanForToolchain` on `self` is a suspension point. Instead, we need to implement the entire toolchain discovery in the initializer itself, which really isn’t that bad anyway.

This allows us to make the `SourceKitLSP.run` function synchronous again.

Fixes #1023
rdar://120976054
2024-01-18 15:25:00 -08:00
Alex Hoppen
70fdb1a428 Use withTestScratchDir instead of withTemporaryDirectory
`withTestScratchDir` respects the SourceKit-LSP test environment variable to keep temporary files.
2024-01-17 15:02:33 -08:00
Alex Hoppen
1e72500f1a Merge pull request #1017 from ahoppen/ahoppen/secondary-cursor-info-results
Report secondary cursor info results
2024-01-11 09:30:10 -08:00
Alex Hoppen
7572fb96ee Report secondary cursor info results
rdar://119163908
2024-01-10 21:05:31 -08:00
Alex Hoppen
6f342e2b82 Remove static shared toolchain registry
Global state is never a good thing and we needed to modify it in tests. The design becomes a lot cleaner if we explicitly pass the toolchain registry around.
2024-01-09 17:17:31 -08:00
Alex Hoppen
3e73f11de0 Migrate ToolchainRegistry to be an actor 2024-01-09 17:17:31 -08:00
Alex Hoppen
e0fe9d6aa1 Merge pull request #1012 from krzyzanowskim/marcin/semantictokentypes
Refactor SemanticTokenTypes, SemanticTokenModifiers
2024-01-08 18:14:28 -08:00