Commit Graph

822 Commits

Author SHA1 Message Date
Kai Lau
db3867bdbb fixed the issue that leading and trailing trivia are lost after string interpolation conversion 2024-07-20 16:45:40 -07:00
Alex Hoppen
e4cb1bdbaa Merge pull request #1551 from AppAppWorks/convert-string-concatenation-to-string-interpolation
Convert String Concatenation to String Interpolation
2024-07-17 18:12:15 -07:00
Kai Lau
17e33a672b Convert String Concatenation to String Interpolation
added `ConvertStringConcatenationToStringInterpolation` to convert string concatenation to string interpolation:
- the string concatenation must contain at least one string literal
- the number of pound symbols in the resulting string interpolation is determined by the highest number of pound symbols among all string literals in the string concatenation
- multiline string literals are not supported
registered in `SyntaxCodeActions.allSyntaxCodeActions`
registered in Sources/SourceKitLSP/CMakeLists
created a test in `CodeActionTests`
2024-07-17 14:57:30 -07:00
Paul LeMarquand
838d4a9eb8 Report workspace/triggerReindex server capability
Report to clients that the server supports the
`workspace/triggerReindex` request. This lets clients expose this
functionality only if SourceKit-LSP is configured to support it.
2024-07-15 08:37:19 -04:00
Louis Qian
3be034233b fix: SwiftLanguageService instead of ClangLanguageService
fix!: remove `documentManager` property

fix!: remove `documentManager` in constructor

fix: added documentManager as a computed Property

fix: remove old documentmanager resetting step

fix!: get throws instead of crashing server

fix: throw ResponseError instead of NSError

fix: adding try & orLog where necesary

fix: refined orLog usage

style: ran swift-format

fix: document being opened twice

fix(DocumentManager): remove unwanted comments

lint: ran swift format
2024-07-03 23:48:49 -05:00
Lokesh T R
0221475b70 Implement PeekDocumentsRequest and update ShowDocumentRequest.
-------------------------------------------------------------------------------

This implements an LSP Extension `PeekDocumentsRequest` to let `ExpandMacroCommand` to open the macro expansions in a "peeked" editor window.
For this to work, the client has to pass "workspace/peekDocuments" enabled to `ClientCapabilities.experimental` and the client should handle the `PeekDocumentsRequest` and show the expansions in a "peeked" editor window.

PR to support the above capability in the "Swift for VS Code" Extension: https://github.com/swiftlang/vscode-swift/pull/945
The "Swift for VS Code" extension cannot send the client capability, so it instead passes the same through `initializationOptions` in the `InitializeRequest`.

For editors which doesn't support this capability, `sourcekit-lsp` sends a `ShowDocumentRequest`.
The `ShowDocumentRequest` is updated to show all the macro expansions in a single generated file. Moreover, its folder structure is updated to use hex string of MD5 hash of concatenation of buffer names of expansions.

Fixes https://github.com/swiftlang/vscode-swift/issues/564
Fixes https://github.com/swiftlang/sourcekit-lsp/issues/1498 ( rdar://130207754 )
2024-07-03 15:32:40 +05:30
Lokesh T R
9fb3d0e417 Add LSP support for showing @attached Macro Expansions 2024-07-03 15:32:40 +05:30
Alex Hoppen
ef2dc17806 Merge pull request #1543 from ahoppen/time-out-sourcekitd
Add a maximum duration for sourcekitd requests
2024-07-03 01:48:37 +02:00
Alex Hoppen
191d366a2c Add a maximum duration for sourcekitd requests
VS Code does not cancel semantic tokens requests. If a source file gets into a state where an AST build takes very long, this can cause us to wait for the semantic tokens from sourcekitd for a few minutes, effectively blocking all other semantic functionality in that file.

To circumvent this problem (or any other problem where an editor might not be cancelling requests they are no longer interested in) add a maximum request duration for SourceKitD requests, defaulting to 2 minutes.

rdar://130948453
2024-07-02 22:47:27 +02:00
Alex Hoppen
83cb1625f4 Merge pull request #1544 from ahoppen/function-output-together
Set `prioritizeKeepingFunctionOutputTogether` in `.swift-format`
2024-07-02 22:46:24 +02:00
Alex Hoppen
f4ea614be6 Set prioritizeKeepingFunctionOutputTogether in .swift-format 2024-07-02 11:06:35 +02:00
Kai Lau
eb6f919b5e removed OpenGeneratedInterfaceRequest
deleted OpenInterfaceRequest.swift and moved GeneratedInterfaceDetails to LanguageService.swift
replaced usages by passing its members as parameters directly, refactored usage of TextDocumentIdentifier to DocumentURI
removed from Messages.builtinRequests
removed from SwiftInterfaceTests
removed from Documentation/`LSP Extensions.md`
removed from Sources/LanguageServerProtocol/CMakeLists.txt
2024-07-01 15:14:44 -07:00
Alex Hoppen
1efb2677ea Merge pull request #1530 from plemarquand/prefix-module-name-to-test-id
Prepend module name to TestItem IDs
2024-07-01 21:31:47 +02:00
Paul LeMarquand
c49d6a997c Revert TestStyle enum changes 2024-07-01 09:31:00 -04:00
Alex Hoppen
16e4f83ec3 Merge pull request #1534 from ahoppen/configuration-improvements
Allow specification of SourceKitLSPOptions in the initialize request and look for SourceKit-LSP options in `$XDG_CONFIG_HOME/sourcekit-lsp`
2024-06-28 22:18:45 +02:00
Paul LeMarquand
14b81cfe6c Fixup DocumentTestDiscoveryTests, make TestStyle an enum 2024-06-28 14:42:00 -04:00
Paul LeMarquand
f7a831ba36 Parse module name for obj-c targets
Parse the obj-c module name for targets by looking at the `-fmodule-name`
flag.
2024-06-28 09:38:59 -04:00
Alex Hoppen
ddbad85c28 Allow specification of SourceKitLSPOptions in the initialize request
This allows editors to provide UI elements to toggle SourceKit-LSP options.
2024-06-28 10:25:37 +02:00
Alex Hoppen
d8e0fff6da Make background indexing a proper option in SourceKitLSPOptions
This allows us to flip the default in the future more easily. It also allows users to disable background indexing when it’s enabled by default.

rdar://130280855
2024-06-28 10:23:29 +02:00
Alex Hoppen
abfe5e9432 Merge pull request #1524 from ahoppen/configuration
Allow configuring of SourceKit-LSP’s options using configuration files
2024-06-28 10:14:20 +02:00
Paul LeMarquand
281c3e0e2e Prepend module name to TestItem IDs
It is possible to have two identically named suites in two different
test targets. These were being erroniously rolled up in to the same
parent TestItem.

Disambiguate these TestItems by prepending the module name. This has the
added benefit of making the TestItem IDs a fully qualified name that can
be passed to `swift test`.

The module name is pulled from the compiler arguments for the target. If
no module name can be found we fall back to the `targetID` for the
`ConfiguredTarget`.
2024-06-27 11:49:00 -04:00
Alex Hoppen
d1cddb8c41 Allow configuring of SourceKit-LSP’s options using .sourcekit-lsp configuration files
The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options.

The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP.

For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files.

Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit.
2024-06-27 17:36:16 +02:00
Alex Hoppen
617cdccc57 Handle diagnostics in secondary files correctly
rdar://130503535
2024-06-27 12:40:44 +02:00
Alex Hoppen
12142c024c Remove configuration options from WorkspaceFolder
This extension was added for VS Code but never used. Let’s remove it in favor of workspace-specific configuration files.
2024-06-27 07:01:24 +02:00
Alex Hoppen
9c6a91da4e Merge pull request #1517 from ahoppen/document-module-purpose
Add documentation about each module's purpose and move some files between modules
2024-06-27 05:09:10 +02:00
Alex Hoppen
d324d71a6c Merge pull request #1500 from ahoppen/fix-index-cancellation
Send `SIGKILL` to `swift-frontend` indexing processes
2024-06-26 22:25:23 +02:00
Alex Hoppen
2ba180b192 Send SIGKILL to swift-frontend indexing processes
We were sending `SIGINT` to `swift-frontend` processes if they didn’t terminate after 2 minutes. However, `swift-frontend` doesn’t listen to `SIGINT`.

If a task running `waitUntilExitStoppingProcessOnTaskCancellation` is cancelled and the process doesn’t terminate on a `SIGINT` after 2 seconds, kill it.

rdar://130103147
2024-06-26 09:43:05 +02:00
Alex Hoppen
80a35aabe8 Translate the semantic token legend used by clangd to the semantic token legend used by SourceKit-LSP
clangd uses a completely different semantic token legend than SourceKit-LSP (it doesn’t even adhere to the ordering of the pre-defined token types) but we were passing index offsets from clangd through assuming that clangd uses the same legend, which was incorrect.

When retrieving semantic tokens from clangd, translate the semantic tokens from clangd’s legend to SourceKit-LSP’s legend.

rdar://129895062
2024-06-26 09:30:16 +02:00
Alex Hoppen
fec5dd17f3 Merge pull request #1507 from ahoppen/re-index
Add a request to re-index all files in SourceKit-LSP
2024-06-26 00:07:46 -07:00
Alex Hoppen
46456107f7 Merge pull request #1502 from ahoppen/log-toolchain-path
Log path of the toolchain used to opening a document
2024-06-25 21:35:31 -07:00
Alex Hoppen
e23e300f7c Add a request to re-index all files in SourceKit-LSP
Users should not need to rely on this request. The index should always be updated automatically in the background. Having to invoke this request manes there is a bug in SourceKit-LSP's automatic re-indexing. It does, however, offer a workaround to re-index files when such a bug occurs where otherwise there would be no workaround.

rdar://127476221
Resolves #1263
2024-06-26 06:33:32 +02:00
Alex Hoppen
48223851ae Merge pull request #1518 from ahoppen/sort-handle-impl
Sort cases in `handleImpl`
2024-06-25 21:05:37 -07:00
Alex Hoppen
9618df80a0 Add documentation about each module's purpose and move some files between modules
The purpose of the different modules wasn’t clearly defined, which lead to inconsistent responsibilities between the different modules. Define each module’s purpose and move a few files between modules to satisfy these definitions.

There are a few more larger changes that will need to be made for a fully consistent module structure. These are FIXMEs in the new Modules.md document and I’ll address them in follow-up PRs.
2024-06-25 07:47:45 -07:00
Alex Hoppen
66ec0014d3 Sort cases in handleImpl 2024-06-25 03:32:48 -07:00
Alex Hoppen
89bd9b0372 Add test case that we don't reload the package if a .swift file get added in a folder that doesn't affect compilation
rdar://128573306
2024-06-22 09:06:40 -07:00
Alex Hoppen
652cd00b91 Log path of the toolchain used to opening a document
I don’t know why we logged the toolchain’s identifier twice. That didn’t make much sense.
2024-06-22 06:20:52 -07:00
Alex Hoppen
6aba969da7 Merge pull request #1501 from ahoppen/watch-package-resolved
Watch for changes to `Package.resolved`
2024-06-21 12:46:12 -07:00
Alex Hoppen
4d90f40f72 Watch for changes to Package.resolved
We need to watch for changes to `Package.resolved` so that we can update the dependency checkouts in `.index-build` when the user runs `swift package update`.
2024-06-21 07:19:57 -07:00
Alex Hoppen
e75fac59a6 Merge pull request #1493 from ahoppen/work-done-progress-token-prefix
Allow prefixing of the token for a `WorkDoneProgress` with a custom string
2024-06-20 17:11:46 -07:00
Alex Hoppen
9e6c7e0419 Merge pull request #1436 from lokesh-tr/gsoc24-expansion-of-macros-in-vscode
Add LSP support for showing `@freestanding` Macro Expansions
2024-06-20 14:07:39 -07:00
Lokesh T R
fd50560998 Add LSP support for @freestanding Macro Expansions.
------
Simplify `SemanticRefactoring` with new `Refactoring` protocol to handle sourcekitd requests

Create and implement `ExpandMacroCommand` while temporarily storing generated expansions.

Create test case `testFreestandingMacroExpansion`

Manually inject `ExpandMacroCommand` into `retrieveRefactorCodeActions` upon an "Inline Macro" from sourcekitd

Address Review Comments

Mark `@_spi(Testing) public` for `MacroExpansionEdit`

Address Review Comments

Create separate directory for each buffer with its name, containing a generated file named as the source file along with position range

Fixed generated macro expansion file extension not recognised, by switching to file names which don't contain fragments

Address Review Comments

Wrap the entire feature under `ExperimentalFeatures`

Address Review Comments

Make Swift Lint Pass

Fix Windows Build not passing
2024-06-20 18:14:45 +00:00
Alex Hoppen
3003fe19e5 Allow prefixing of the token for a WorkDoneProgress with a custom string
This allows VS Code to detect when sourcekitd has crashed and prompt the user to gather a diagnostic report + file an issue about the crash.

rdar://129678779
Fixes #1476
2024-06-20 09:05:18 -07:00
Alex Hoppen
e62473b8d6 Merge pull request #1492 from ahoppen/fix-concurrency-warnings
Fix a few Swift concurrency warnings
2024-06-20 08:59:31 -07:00
Alex Hoppen
8642768902 Fix a few Swift concurrency warnings 2024-06-18 18:07:22 -07:00
Alex Hoppen
30f1fd1997 Remove warning message about missing compiler arguments
It turns out that this message was more noise than help. For example, it would often show up when adding a new file to a SwiftPM project: The file gets added before we reload the package and thus we don’t have build settings for the new file for a short while. Since we can’t dismiss the notification we sent to the client, the notification will stick around.

Let’s just remove the message.
2024-06-18 12:26:05 -07:00
Alex Hoppen
60d2876fbc Add workaround for rdar://116221716 2024-06-14 17:43:59 -07:00
Alex Hoppen
55ef104079 Merge pull request #1464 from ahoppen/protocol-requirement-satisfied-in-extension
Show protocol requirements satisfied in extensions in jump-to-definition
2024-06-12 14:47:02 -07:00
Alex Hoppen
2d2bac88c9 Merge pull request #1471 from ahoppen/enum-case-rename
Adjust test cases for fixed enum case rename
2024-06-12 14:46:49 -07:00
Alex Hoppen
0c42c01d44 Show protocol requirements satisfied in extensions in jump-to-definition
The key issue here was that we were looking at the symbol occurrence that had the `overrideOf` role and were using this symbol occurrence to also check that it’s a child of one of the receiver types. But if the protocol requirement is satisfied in an extension, we have an implicit symbol occurrence at the location where the protocol requirement is stated but the real declaration’s occurrence is inside the extension. The fix here is to just extract the USR from the `overrideOf` relation and then do another index lookup to find the symbol’s definition.

rdar://129412428
2024-06-12 09:30:36 -07:00
Alex Hoppen
518aac47d5 Merge pull request #1459 from ahoppen/testable-methods
Change methods that were only public for testing purposes to be `@_spi(Testing)`
2024-06-12 09:26:45 -07:00