Commit Graph

566 Commits

Author SHA1 Message Date
Alex Hoppen
63171abcea Merge pull request #1178 from ahoppen/nil-for-empty-prepare-type-hierarchy
Instead of returning an empty array in `prepareTypeHierarchy`, sourcekit-lsp should return `nil`
2024-04-17 14:02:33 -07:00
Doug Gregor
a8b61a52d3 Introduce new refactoring code actions based on the Swift syntax tree.
This change includes a number of new refactoring code actions that
build on the syntax refactorings for the SwiftRefactor module of swift-syntax:

  * Add digit separators to an integer literal, e.g., `1000000` ->
    `1_000_000`.
  * Remove digit separators from an integer literal, e.g., 1_000_000 ->
    1000000.
  * Format a raw string literal, e.g., `"Hello \#(world)"` ->
    `##"Hello\#(world)"##`
  * Migrate to new if let syntax, e.g., `if let x = x { ... }` ->
    `if let x { ... }`
  * Replace opaque parameters with generic parameters, e.g.,
    `func f(p: some P)` --> `func f<T1: P>(p: T1)`.

This is generally easy to do, requiring one conformance to provide a name for the refactoring:

    extension AddSeparatorsToIntegerLiteral: SyntaxRefactoringCodeActionProvider {
      public static var title: String { "Add digit separators" }
    }
2024-04-16 23:00:20 -07:00
Alex Hoppen
f482982c47 Instead of returning an empty array in prepareTypeHierarchy, sourcekit-lsp should return nil
Eg. when requesting type hierarchy of a class when the project hasn’t been built, sourcekit-lsp returns an empty array. That causes VS Code to fail with very ambiguous error messages
- MISSING provider
- Cannot read properties of null (reading 'kind')

To work around this, instead of returning an empty array, return `nil` instead.

rdar://126228814
2024-04-16 11:25:56 -07:00
Alex Hoppen
5a5b501283 Merge pull request #1166 from ahoppen/dont-repeat-function-in-call-hierarchy
Don’t repeat a function in `incomingCalls` if it contains multiple calls to the same function
2024-04-12 16:37:44 -07:00
Alex Hoppen
1e3488bfb4 Don’t repeat a function in incomingCalls if it contains multiple calls to the same function
Eg. if we have the following, and we get the call hierarchy of `foo`, we only want to show `bar` once, with multiple `fromRanges` instead of having two entries for `bar` in the call hierarchy.

```swift
func foo() {}
func bar() {
  foo()
  foo()
}
```
2024-04-11 14:35:33 -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
Alex Hoppen
15189bb2fa Merge pull request #1149 from ahoppen/ahoppen/structured-tests
Return tests discovered by `workspace/tests` and `textDocument/tests` in a hierarchical format
2024-04-11 11:03:56 -07:00
Alex Hoppen
44b8a82f9e Merge pull request #1165 from ahoppen/container-name-as-call-hierarchy-detail
Show container name as the detail of a call hierarchy item
2024-04-08 16:34:08 -07:00
Alex Hoppen
67a73f47c1 Return document tests in a hierarchical format
Same as for workspace tests, instead of returning a flat list of symbols, return a hierarchical structure.
2024-04-05 20:18:46 -07:00
Alex Hoppen
65b9505081 Return workspace tests in a hierarchical format
This ways the client doesn’t need to create a hierarchical structure using the container names. It is also more flexible and allows nesting of test suites + the addition of labels and tags for swift-testing.

The data structure for `TestItem` has been heavily inspired by VS Code’s `TestItem` for the test explorer, which should make it fairly straightforward to integrate these results into the VS Code test explorer.
2024-04-05 20:16:06 -07:00
Alex Hoppen
0de726d280 Merge pull request #1161 from ahoppen/unify-position-conversion-error-logging
Unify logging of errors during position conversions
2024-04-05 14:02:26 -07:00
Alex Hoppen
30bc65a554 Show container name as the detail of a call hierarchy item
The container name, showing the class a method is defined on, is more useful than the module name.
2024-04-05 10:20:01 -07:00
Alex Hoppen
4ed62392e7 Merge pull request #1162 from ahoppen/fewer-fatal-errors
Replace usages of `fatalError` that are recoverable by non-fatal error propagation constructs
2024-04-05 10:07:18 -07:00
Alex Hoppen
d62c4ce9fa Unify logging of errors during position conversions
Instead of logging errors in position translation ad-hoc at the caller’s side (and ofter forgetting to do so), log these errors in `LineTable`. To be able to debug where the position conversion error is coming from, also log the file name and line number of the caller.

rdar://125545620
2024-04-05 06:56:59 -07:00
Alex Hoppen
479e87bbed Merge pull request #1160 from ahoppen/indentation-of-expanded-closure
Don’t add the indentation of the current line to the insert text of subsequent lines when expanding trailing closures
2024-04-05 06:30:28 -07:00
Alex Hoppen
e3bc561077 Don’t fatalError when calling splitToSingleLineRanges on a range that exceeds past the document 2024-04-04 11:05:53 -07:00
Alex Hoppen
f41feb7d28 Don’t fatalError if applying an edit in sourcekitd fails 2024-04-04 11:05:53 -07:00
Alex Hoppen
cb14bd0948 Don’t fatalError if TextDocumentContentChangeEvent could not be converted to a SourceEdit 2024-04-04 11:05:53 -07:00
Alex Hoppen
34acdb0249 Don’t fatalError for Fix-Its that make no changes 2024-04-04 11:05:53 -07:00
Alex Hoppen
8e9c19ac61 Don’t fatalError when constructing DocumentURI from an invalid URL 2024-04-04 11:05:49 -07:00
Alex Hoppen
5c549cec72 Support rename initiated from the end of an identifier
rdar://124727045
2024-04-04 10:55:56 -07:00
Alex Hoppen
7780ec590e Make sure the range returned by PrepareRenameRequest always contains the position from which the rename was initiated
VS Code rejects the placeholder name returned by the `PrepareRenameRequest`. When initiating rename on `x` in the following, this means that VS Code picks its own internal symbol name as the placeholder text, opening the rename textbox with `x`.

```swift
func foo(
  x: Int
) {}
```

Users then enter `y` in the expectation to rename only the parameter but sourcekit-lsp expects a function name and thus renames `foo` to `y(x:)`, which is unexpected.

rdar://125551489
2024-04-04 10:50:43 -07:00
Alex Hoppen
a691784d8f Don’t add the indentation of the current line to the insert text of subsequent lines when expanding trailing closures
Visual Studio Code automatically inserts the indentation of the current line to any additional lines from code completion.

rdar://125071836
2024-04-04 10:40:05 -07:00
Alex Hoppen
d5e3dbd75e Merge pull request #1148 from ahoppen/ahoppen/syntactic-test-discovery-fallback
Implement a syntactic test discovery fallback for XCTests written in Swift
2024-04-02 07:48:28 +02:00
Gremlinflat
cd4f7c9694 lint 2024-03-28 06:07:50 +07:00
Gremlinflat
13613723a1 fix: build errors 2024-03-28 00:19:18 +07:00
Gremlinflat
b11ad16590 fix: fix mistyped line 2024-03-27 23:35:00 +07:00
Gremlinflat
b4c2f3df02 fix: fix returning empty array 2024-03-27 23:27:06 +07:00
Gremlinflat
f97e41bfd0 feat: add mergingTokens overloading method 2024-03-27 23:25:11 +07:00
Alex Hoppen
fdb8bab22c Implement a syntactic test discovery fallback for XCTests written in Swift
If the index for a given file is not up-to-date, perform a syntactic scan for tests within it.

This should allow editors to run the `textDocument/tests` request while the user is editing a file to scan it for test cases.
2024-03-27 12:42:58 +01:00
Gremlinflat
45d24a86f5 chore: fix typo on copyright 2024-03-26 15:27:28 +07:00
Gremlinflat
cae8a8b1c7 lint: fix formatting 2024-03-26 06:24:06 +07:00
Gremlinflat
f392e2ffe3 feat: clean up & finish all todo 2024-03-26 01:07:41 +07:00
Gremlinflat
315fff84f8 feat: add SyntaxHighlightingTokens wrapper struct 2024-03-25 23:43:45 +07:00
Alex Hoppen
582a1000c8 Rename SwiftPMWorkspace to SwiftPMBuildSystem
All other types that conform to `BuildSystem` (which in sourcekit-lsp terms is something that can provide compiler arguments) had the `BuildSystem` suffix. `SwiftPMWorkspace` was an oddity here and was easily confused with the `Workspace` term in LSP, which essentially represents a single root folder that is being opened.
2024-03-20 22:51:28 +01:00
Alex Hoppen
0ea35886e8 Rename sourceKitServer -> sourceKitLSPServer
I forgot to rename the variables when renaming the class from `SourceKitServer` to `SourceKitLSPServer`.
2024-03-20 22:51:28 +01:00
Alex Hoppen
ed5c7e2e39 Rename language specific language services
The naming was quite inconsistent here. Let’s rename these to `LanguageService` to highlight that they belong together.

- ToolchainLanguageServer -> LanguageService
- SwiftLanguageServer -> SwiftLanguageService
- ClangLanguageServerShim -> ClangLanguageService
2024-03-20 22:51:28 +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
83837ce3bb Merge pull request #1138 from ahoppen/ahoppen/rename-with-multiple-index-entries
Don’t fail rename if there are multiple index entries for the same USR
2024-03-20 22:44:20 +01:00
Alex Hoppen
cd07e2f9ea Merge pull request #1137 from ahoppen/ahoppen/no-work-done-progess-if-client-doesnt-support
Don’t send `WorkDoneProgressRequest` to the client if it doesn’t support work done progress
2024-03-20 14:34:28 +01:00
Alex Hoppen
3e505ed49e Merge pull request #1136 from ahoppen/ahoppen/log-opened-build-system
Log the build system with which a workspace has been opened
2024-03-20 14:34:16 +01:00
Alex Hoppen
c753cc4bf7 Merge pull request #1126 from ahoppen/ahoppen/jsonrpc-strict-concurrency
Make the `LanguageServerProtocolJSONRPC` module build with strict concurrency enabled
2024-03-20 11:35:08 +01:00
Alex Hoppen
c75a3099cd Merge pull request #1135 from ahoppen/ahoppen/fix-leaks
Fix memory leaks
2024-03-20 09:56:43 +01:00
Alex Hoppen
f90d3c9930 If there are multiple definition occurrences and getting the cross-language name fails for one symbol, try the next definition 2024-03-20 09:50:24 +01:00
Alex Hoppen
d1b527e14c Make the LanguageServerProtocolJSONRPC module build with strict concurrency enabled 2024-03-20 08:37:39 +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
252cccc420 Don’t send WorkDoneProgressRequest to the client if it doesn’t support work done progress 2024-03-19 14:38:18 +01:00
Alex Hoppen
d331206967 Log the build system with which a workspace has been opened
I thought there was an issue with opening nested SwiftPM workspaces. Turns out there wasn’t but some logging and a test case don’t hurt.

rdar://124727086
2024-03-17 16:30:11 +00:00
Alex Hoppen
86e1878536 Fix a retain cycle
I don’t remember what the exact retain cycle was after fixing it.
2024-03-17 16:24:01 +00:00