Commit Graph

100 Commits

Author SHA1 Message Date
Ian Hanken
a83a53c724 Empty TextEdits now return nil
This adds a check when creating a `TextEdit` to return `nil` if both the fixit and the replacement being used to create a `TextEdit` are empty. A `TextEdit` being created like this can cause a crash.
2022-10-07 16:26:11 +02:00
Alex Hoppen
eb71033271 Merge pull request #572 from DavidGoldman/release/5.7
[5.7] Support index store path remappings
2022-06-28 23:20:00 +02:00
Alex Hoppen
c1e5720c50 Merge pull request #560 from ahoppen/pr-5.7/reopen-documents-after-workspace-change
[5.7] When receiving a didChangeWorkspaceFolders notification, reopen documents that moved to a different workspace
2022-06-22 17:44:04 +02:00
Alex Hoppen
4e05e5638f Merge pull request #570 from fwcd/5.7-upstream-inlay-hints
[5.7] Migrate to upstream inlay hints
2022-06-22 17:43:09 +02:00
David Goldman
c94b0d058c Support index store path remappings (#562)
This allows sourcekit-lsp to make use of the path remappings recently added to
the index store and IndexStoreDB to remap remote paths into local paths
when loading index data locally.

These remappings can be provided via the `-index-prefix-map` command line flag to sourcekit-lsp or via the `BuildSystem` integration point.

(cherry picked from commit 472a06c88a)
2022-06-16 15:25:44 -04:00
fwcd
550ce9b995 Migrate to upstream LSP inlay hints
- Use official textDocument/inlayHint request
- Rename InlayHintCategory to InlayHintKind
- Additionally, represent it using an Int, as in the proposed LSP API.
- Add inlay hint client capabilities
- Add inlay hint server capabilities
- Add dynamic registration of inlay hint request
- Rename InlayHintsRequest -> InlayHintRequest
  This is to be consistent with the request itself being named in singular
  in LSP and the other requests (e.g. DocumentSymbolRequest).
- Forward inlay hint requests to clangd
- Add colon before inlay hints
- Add other properties to InlayHint
- Add InlayHintLabel structures
- Conform InlayHintLabel to ExpressibleByStringX protocols
- Attach TextEdit to inlay hints for committing them
- Add InlayHint.data
- Fix InlayHintTests
  We need to include text edits in the expected inlay hints.
2022-06-14 15:18:55 +02:00
Alex Hoppen
d5d045923e Close temporarily opened documents
We only open a document e.g. with the `FoldingRanges:` prefix to get the document structure as a one-off task, so we should be closing it afterwards.

Fixes #553 (rdar://93154201)
2022-06-09 10:09:23 +02:00
Alex Hoppen
e7ac20e729 When receiving a didChangeWorkspaceFolders notificaiton, reopen documents that moved to a different workspace
A didChangeWorkspaceFolders notification might cause documents that are already open to now be considered part of a different workspace. To reflect this, close documents whose workspace has changed in the old workspace and re-open them in the new workspace.

rdar://94026341 [#557]
2022-06-01 09:35:29 +02:00
Alex Hoppen
04e7606fdd Keep track of existing language servers separately by language server type
Otherwise we can run into situations where a Swift toolchain language server is asked to handle C files.

rdar://92690379
2022-05-04 14:50:52 +02:00
Alex Hoppen
7ca1603444 Listen to DidChangeWorkspaceFolders notification 2022-05-03 17:28:25 +02:00
Alex Hoppen
91370aa797 Cache which workspace a document with a given URI should be opened in
Determining which workspace a document belongs to is potentially non-trivial (although it shouldn’t be too expensive either). But since it’s executed for every request, cache it.
2022-05-03 17:28:25 +02:00
Alex Hoppen
76133f6e77 Add capability to open multiple workspaces during the initialize request 2022-05-03 17:28:25 +02:00
Alex Hoppen
ef8c83fda3 Query build system of workspaces to determine best workspace to open a file in
This sets the stage for multi-workspace support. Everything should be handled internally, we are just missing the API to actually open multiple workspaces at this point.
2022-05-03 17:28:25 +02:00
Alex Hoppen
22f6b291e1 Make each toolchain language server keep track which workspaces it can open documents for
This will allow us to start multiple `clangd` instances for each workspaces root once we start supporting multiple workspace roots.
2022-05-03 17:28:25 +02:00
Alex Hoppen
45fd05ce75 Prepare SourceKitServer for multiple workspaces
This makes SourceKitServer keep track of multiple workspaces and their handling. It does not include the functionality to determine which workspace a file belongs to.
2022-05-03 17:28:25 +02:00
Alex Hoppen
1d1a2ce2c0 Prepare SourceKitServer for multiple workspaces
This makes SourceKitServer keep track of multiple workspaces and their handling. It does not include the functionality to determine which workspace a file belongs to.
2022-05-03 17:28:25 +02:00
Alex Hoppen
865fa839d8 Make SourceKitServer own the DocumentManager
When we introduce multiple workspaces, they need to share the same DocumentManager so we don’t accidentally open a Swift file twice in two workspaces that share the same `SwiftLanguageService`. Thus, `SourceKitServer` needs to start owning the document manager.
2022-05-03 17:28:25 +02:00
Alex Hoppen
5271f8e5fc Remove regiseterWorkspaceNotification/Request methods
When we support multiple workspaces on one SourceKit-LSP instance, there won’t be a unique workspace anymore. Each request handler should determine the workspace it wants to use on its own.
2022-05-03 17:28:25 +02:00
Alex Hoppen
8576617c92 Refactor the way toolchain language servers are created
Mostly cleanup
2022-05-03 17:28:25 +02:00
Alex Hoppen
4b3bd2e441 Merge pull request #491 from ahoppen/pr-5.7/watch-compile-commands
[5.7] Watch for changes to `compile_commands.json` and `compile_flags.txt`
2022-04-29 12:59:13 +02:00
Alex Hoppen
a9a4ea670f Merge pull request #483 from ahoppen/pr-5.7/snippets-for-fixits
[5.7] Translate placeholders to LSP snippets in CodeActions
2022-04-29 12:58:46 +02:00
Alex Hoppen
e831f5781b Watch for changes to compile_commands.json and compile_flags.txt
Similar to how we reload the package if Package.swift is changed, we also watch `compilation_database.json` and `compile_flags.txt` and notify the build system delegate that build settings changed if these files are modified.

rdar://92388223  [#486]
2022-04-29 08:56:56 +02:00
Alex Hoppen
749dd6294e Remove placeholders from code actions instead of replacinng them by snippets
#481 replaced SourceKit placeholders (like `<#code#>`) by LSP snippets for code actions, which are used to represent SourceKit refactoring and diagnostic Fix-Its. But LSP snippets are only supported for code completion, not for code actions. This results in LSP snippets like ${1:code} being inserted into the editor.

Instead of replacing SourceKit placeholders by LSP placeholders, we should just remove them altogether from the code action response.

rdar://92447079 [#488]
2022-04-28 17:50:33 +02:00
Alex Hoppen
6315fd3303 Reload the package if Package.swift changes
rdar://88064286 [SR-15633]
2022-04-27 11:54:55 +02:00
Alex Hoppen
8ce0bc7112 Translate placeholders to LSP snippets in CodeActions
Previously, we would insert `<#code#>` placeholders when inserting missing protocol requirements (both via the Fix-It and the refactor command). Translate them to LSP placeholders before inserting them.

rdar://92161144
2022-04-27 11:36:59 +02:00
Saleem Abdulrasool
fca0cd3913 build: build SourceKit-LSP with static linking
This adjusts the sourcekit-lsp build to use static linking for the
internal libraries.  It is not currently possible to build
SourceKitLSP.dll as that requires re-exporting the interfaces from the
consumed modules.  However, this allows us to reduce the overall size of
the distribution of SourceKit-LSP by ~1 MiB and reduces the
distributed file set.  The values here assume partial static linking of
swift-package-manager, which helps reduce the total size.

Before:

   228,352 BuildServerProtocol.dll
 1,773,056 LanguageServerProtocol.dll
   114,688 LanguageServerProtocolJSONRPC.dll
    49,152 LSPLogging.dll
   262,656 SKCore.dll
    54,784 SKSupport.dll
    80,896 SKSwiftPMWorkspace.dll
   150,528 SourceKitD.dll
   645,632 SourceKitLSP.dll

    70,144 sourcekit-lsp.exe

 3,429,888 bytes

After:

 2,416,640 sourcekit-lsp.exe

 2,416,640 bytes
2022-03-02 08:43:06 -08:00
Alex Hoppen
46b31fb0c3 Merge pull request #461 from compnerd/foundational
build: force link against dependencies
2022-03-02 15:04:33 +01:00
Alex Hoppen
cb3012e618 Merge pull request #460 from compnerd/minimum-required
build: bump CMake requirement, remove workarounds
2022-03-02 15:04:20 +01:00
Saleem Abdulrasool
d888252350 build: force link against dependencies
This will add an additional link request for dispatch and Foundation
libraries.  These are really required on non-Darwin targets, and should
be satisfied either by the library search path or by explicitly
indicating where the dependencies can be found.
2022-02-27 12:10:30 -08:00
Saleem Abdulrasool
4988260e5b build: bump CMake requirement, remove workarounds
The swift project uses a minimum of CMake 3.19.6, and the current CMake
release is 3.22.  Update the CMake requirement to a newer version and
remove the workaround for older releases of CMake.
2022-02-26 12:17:58 -08:00
Alex Hoppen
34abbdf2b5 Only send response to ShutdownRequest when all toolchain servers have shut down
Especially in test we would sometimes end up in situations where the SourceKitServer (i.e. the main sourcekit-lsp handler) is being deallocated before clangd has finished shutting down. This can result in clangd sending us notifications while SourceKitServer is halfway deallocated and thus cause crashes due to memory corruption.

To fix the issue, wait until all toolchain servers have shut down before sending a response to the ShutdownRequest.
2022-02-24 17:34:50 +01:00
Saleem Abdulrasool
b6ca84ec10 explicitly indicate the TSCUtility interfaces used
This explicitly identifies the TSCUtility interfaces that SourceKit
depends on.  This helps identify a "burn down list" of interfaces that
remain in TSC(Utility) which are in use.  As these interfaces are
replaced, we can easily monitor the remaining interfaces that are in
use.
2022-02-02 13:29:03 -08:00
Saleem Abdulrasool
be6e13b5c4 remove unnecessary dependency on TSCLibc
This reduces the dependency on the `TSCLibc` module which was not
actually used for anything but for importing the C library in
`SKSupport`.  Although on Apple platforms and Linux this could largely
be dealt with by statically linking, Windows does not support static
linking of Swift content properly yet.  This avoids the dependency on
the library instead.
2022-01-31 09:51:35 -08:00
Adam Fowler
d6eca2841e Set didChangedWatchedFiles glob to **/*.ext
**.ext will only look in the base folder
2022-01-27 11:15:36 +01:00
Saleem Abdulrasool
42dc29aad2 Repair the build after #447
Add missing source file from #447
2022-01-25 20:37:51 -08:00
Alex Hoppen
9104fdd7ba Merge pull request #447 from ahoppen/pr/adjust-diag-ranges
Adjust diagnostic ranges on edits
2022-01-25 11:21:35 +01:00
Alex Hoppen
1d1037f60d Merge pull request #446 from ahoppen/pr/semantic-tokens-update
Only referesh semantic tokens if SourceKit returned semantic information
2022-01-25 11:21:02 +01:00
Alex Hoppen
0f51262c40 Merge pull request #443 from ahoppen/pr/didchangewatchedfilesnotification
Reload Swift Package when new file creation is indicated by `DidChangeWatchedFileNotification`
2022-01-24 19:58:34 +01:00
Alex Hoppen
251312b218 Adjust diagnostic ranges on edit 2022-01-24 19:34:59 +01:00
Alex Hoppen
fb97fc7350 Extract range adjustments after edit into standalone type
This allows us to re-use the adjuster to adjust ranges of diagnostics as well later on.
2022-01-24 19:34:59 +01:00
Alex Hoppen
2206a5f840 Try determining diagnostic ranges
If the diagnostic has a range associated with it that starts at the same location as the diagnostics position, we can use it to retrieve a proper range for the diagnostic, instead of just reporting a zero-length range.
2022-01-21 15:23:28 +01:00
Alex Hoppen
26a07d46a4 Only referesh semantic tokens if SourceKit returned semantic information
In certain race condition scenarios, we might receive a document update to which the 0,0 replacetext request returned only syntactic information. In that case we shouldn’t update the sematnic syntax highlighting tokens.

The race condition rarely surfaced as a test failure of `testSemanticMultiEdit`.
2022-01-21 15:05:43 +01:00
Alex Hoppen
fda6326e3b Only reload SwiftPM package if a file that is relevant to SwiftPM changes 2022-01-19 11:20:10 +01:00
Alex Hoppen
9a5b1e81ef Reload Swift Package when new file creation is indicated by DidChangeWatchedFileNotification
Implement rudementary support for `DidChangeWatchedFileNotification` for SwiftPM projects: When a file is added, reload the Swift package to compute build settings for it.

This enables proper semantic functionality added to the project after the LSP server was started.

Resolves SR-15633
2022-01-19 11:20:10 +01:00
Alex Hoppen
2edcc0d6ee Don't report duplicate folding ranges
I’m not entirely sure when this started occurring but when retrieving folding ranges e.g. for
```
func foo() {
    print("someText")
}
```
We report the folding range of `"someText"` twice: Once as the body of the call to `print` and once as the body of the first argument. Each folding range on its own makes sense because you might want to collapse either all arguments or only a single argument. But it doesn’t make sense to report the same range twice.
2022-01-07 10:21:01 +01:00
Kyle
6d1b09ad5b Remove available check below macOS 10.15.4
Since the Package.swift declare the minimal target for macOS is 10.15.4,
we can remove the uncessary available check code
2021-12-05 17:07:34 +08:00
David Goldman
d29d1254a4 Add support for clangd commands + code actions (#429)
This adds support for clangd commands for clients which support
dynamic registration (including VS Code), as well as fixes an
issue which prevented clangd's code actions from working.

Also added a test to ensure the clangd code actions work, as well as regenerated the Linux test main (which was missing some other newly added tests).
2021-09-29 09:38:49 -04:00
Fredrik Wieczerkowski
17f656865d Implement lexical and semantic highlighting for Swift
This is an implementation of LSP's semantic tokens for Swift. Both
lexical and semantic tokens are provided by using the syntaxmap and the
semantic annotations provided as part of SourceKit's open responses and
document update notifications.

While lexical tokens are parsed and stored in the DocumentManager
synchronously, semantic tokens are provided asynchronously. If an edit
occurs, tokens are automatically shifted by the DocumentManager. This is
especially relevant for lexical tokens, which are updated in deltas.

In addition, unit tests are added that assert that both lexical and
semantic tokens are provided and shifted correctly upon edits.
2021-08-24 16:49:52 +02:00
LebJe
a9a840c900 Provide Data Types in Document Outline; Provide Code Documentation in CompletionItem 2021-08-05 19:55:16 -04:00
LebJe
c90813a8f4 Format links in the documentation markdown from SourceKit 2021-07-14 16:18:26 -04:00