Commit Graph

1839 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
Alex Hoppen
f0e86454a5 Merge pull request #1563 from plemarquand/trigger-reindex-capability
Report workspace/triggerReindex server capability
2024-07-17 14:30:57 -07:00
Alex Hoppen
1dfda5b2b9 Merge pull request #1557 from plemarquand/fix-import-warnings
Fixup some import related warnings
2024-07-16 13:32:13 -07:00
Alex Hoppen
4460c5caf8 Merge pull request #1545 from plemarquand/multi-package-root-fix
Fix incorrect ConfiguredTargets for Package.swift w/ multiple workspaces
2024-07-16 08:09:56 -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
Paul LeMarquand
727de49070 Wrap import os in canImport 2024-07-15 08:26:48 -04:00
Alex Hoppen
007d2cfee5 Merge pull request #1561 from plemarquand/add-trigger-reindex-to-req-list
Add TriggerReindexRequest to builtinRequests
2024-07-15 14:02:22 +02:00
Paul LeMarquand
b288767675 Add TriggerReindexRequest to buildinRequests
`TriggerReindexRequest` was missing from the list of builtinRequests,
which caused the LSP to respond with a methodNotFound error when it
recieved a `workspace/triggerReindex` request.
2024-07-10 11:57:06 -04:00
Finagolfin
1cf6c76897 Import new Bionic module from Android overlay instead where possible 2024-07-08 19:08:07 +05:30
Paul LeMarquand
5ab04546e8 Fixup some import related warnings
This patch fixes up:
- 1 File 'Foo.swift' is part of module 'module'; ignoring import
  warning
- 70 "Instance method 'foo' cannot be used in an '@inlinable'
  function because 'module' was not imported by this file" warnings
- 2 "Result of call 'foo' is unused" warnings
2024-07-05 14:11:55 -04:00
Alex Hoppen
158bed8d85 Merge pull request #1550 from finagolfin/droid
Import new Android overlay
2024-07-04 14:57:16 +02:00
Alex Hoppen
8695c0ccf5 Merge pull request #1549 from plemarquand/fix-module-name-precedence
Respect module name argument order precedence
2024-07-04 14:56:53 +02: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
Finagolfin
7c20015331 Import new Android overlay 2024-07-04 02:20:23 +05:30
Paul LeMarquand
c753169434 Respect module name argument order precedence
When the same flag is specified multiple times the last one found is
used.
2024-07-03 10:06:31 -04:00
Paul LeMarquand
707b8e5860 Fix incorrect ConfiguredTargets for Package.swift w/ multiple workspaces
In a project with multiple folders each containing a Package.swift, the
`bestWorkspace` found in `workspaceForDocument(uri:)` was always the
first one encountered.

`fileHandlingCapability(for:)` checks if there are configured targets
for the Package.swift and if there are, the workspace is chosen since
the Package.swift is determined to be part of the workspace. However the
check in `configuredTargets(for:)` always returned a target for any
`Package.swift`, even if that `Package.swift` was not part of the
workspace associated with the BuildSystem.

Ultimately this manifested as code completion not working in all but one
of the Package.swift files in a multi workspace project.

Some work was done in #1210 to address swiftlang/vscode-swift#768, which
is where this issue originated from. However while verifying
swiftlang/vscode-swift#768 I found that #1210 didn't fully address code
completion of `Package.swift` files in multi workspace projects.
2024-07-03 09:24:51 -04: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
91c55f9fcb Merge pull request #1532 from AppAppWorks/remove-OpenGeneratedInterfaceRequest
removed OpenGeneratedInterfaceRequest
2024-07-02 13:31:40 +02:00
Alex Hoppen
f4ea614be6 Set prioritizeKeepingFunctionOutputTogether in .swift-format 2024-07-02 11:06:35 +02:00
Alex Hoppen
5784bf87e5 Merge pull request #1538 from ahoppen/skip-wasm-test
Skip `testWasm` if the host toolchain can’t build for WASM
2024-07-02 06:57:43 +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
ab67a7e8ca Skip testWasm if the host toolchain can’t build for WASM
This fixes a test failure when running tests using Xcode 15.4.
2024-06-28 23:25:41 +02:00
Alex Hoppen
c6b82a7556 Fix a compilation issue caused by #1533 and #1524 racing 2024-06-28 22:54:52 +02: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
Alex Hoppen
6b88cfe294 Merge pull request #1533 from ahoppen/background-indexing-configuration-option
Make background indexing a proper option in `SourceKitLSPOptions`
2024-06-28 22:14:19 +02:00
Paul LeMarquand
14b81cfe6c Fixup DocumentTestDiscoveryTests, make TestStyle an enum 2024-06-28 14:42:00 -04:00
Paul LeMarquand
bc86ff8e6a Address comments 2024-06-28 12:45:14 -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
bfe1a24110 Support using SourceKit-LSP for projects that are cross-compiled
We previously always assumed that the project was being built for the host.

Fixes #786
Fixes #1475
rdar://129662080
rdar://113099964
2024-06-28 10:28:46 +02:00
Alex Hoppen
2c21284ff8 Look for SourceKit-LSP options in $XDG_CONFIG_HOME/sourcekit-lsp
The reverse-DNS notation is macOS style and doesn’t feel at home on Linux.
2024-06-28 10:25:37 +02: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