Commit Graph

55 Commits

Author SHA1 Message Date
Alex Hoppen
ac3eb32e65 Format sources with swift-format 2023-10-31 19:30:31 -07:00
Alex Hoppen
1a23153fd5 When sourcekitd crashes, log the file contents with which it crashed and the request
This should make it a lot easier to reproduce sourcekitd crashes.
2023-10-31 08:30:54 -07:00
Alex Hoppen
47e7a13ce6 Emit signposts for request handling
This allows you to trace sourcekit-lsp in Instruments to get a feeling for how long requests take to be handled.
2023-10-30 13:53:59 -07:00
Alex Hoppen
5bdd6f253b Refactor SwiftLanguageServer to be able to call the async version of SourceKitD.send
Resolves #869
rdar://116703689
2023-10-26 21:38:25 -07:00
Alex Hoppen
f7572c4035 Factor withCancellableCheckedThrowingContinuation into a separate function 2023-10-26 11:03:15 -07:00
Alex Hoppen
b41f6af59d Avoid a potential race condition in which a sourcekitd/clangd request wouldn't get cancelled 2023-10-26 11:03:15 -07:00
Alex Hoppen
3d17caded6 Implement request cancellation
When receiving a `CancellationNotification`, we cancel the task that handles the request with that ID.

This will cause `cancel_notification` to be sent to sourcekitd or a `CancellationNotification` to be sent to `clangd`, which ultimately cancels the request.

rdar://117492860
2023-10-26 11:03:15 -07:00
Alex Hoppen
ffbf025896 Open and edit documents in syntactic-only mode in sourcekitd
With this change, opening and editing a document no longer causes a non-cancellable AST build. Instead, all semantic information is retrieved via requests that can be cancelled (after we implement cancellation).
2023-10-20 09:38:35 -07:00
Alex Hoppen
080e664363 Load semantic tokens from a document using a sourcekitd request instead of the 0,0 edit
This allows us to cancel the semantic tokens request. It is also the last step to allow us to open and edit documents in syntactic-only mode.

It also means that we no longer need to send a `WorkspaceSemanticTokensRefreshRequest` to the client after sourcekitd has updated its semantic tokens since with the new design the `DocumentSemanticTokensRangeRequest` will simply return the results once it has the updated semantic token.
2023-10-19 17:46:58 -07:00
Alex Hoppen
0a18628f04 Simplify sending of sourcekitd requests
Hoist some of the logic out of `withCheckedContinuation` to make the code easier to read.
2023-10-18 21:46:55 -07:00
Alex Hoppen
f960d7ed9b Change logging to use OSLog
OSLog is the suggesting logging solution on Apple platforms and we should be using it there, taking advantage of the different log levels and privacy masking.

Switch sourcekit-lsp to use OSLog on Apple platforms and implement a logger that is API-compatible with OSLog for all uses in sourcekit-lsp and which can be used on non-Darwin platforms.

The goal of this commit is to introduce the new logging API. There are still improvements about what we log and we can display more privacy-insensitive information after masking. Those changes will be in follow-up commits.
2023-10-13 13:46:32 -07:00
Alex Hoppen
d0fc00ce98 Format using swift-format
Add `.swift-format` to the repo and format the repo with `swift-format`.

This commit does not add any automation to enforce formatting of sourcekit-lsp in CI. The goal of this commit is to get the majority of source changes out of the way so that the diff of actually enforcing formatting will have fewer changes or conflicts.
2023-10-10 13:44:47 -07:00
Alex Hoppen
9e07784fb8 Remove the version of SourceKitD.send that took a completion handler 2023-10-06 18:07:19 -07:00
Alex Hoppen
97a6e1c617 Handle notifications from sourcekitd on a serial queue 2023-10-06 10:49:03 -07:00
Alex Hoppen
6e7b5db9a2 Make hover return the request result as a return value 2023-10-03 08:09:00 -07:00
Max Desiatov
66f1c0dbf2 Add support for Musl libc with canImport(Musl) checks (#772)
Since Musl is sufficiently different from Glibc (see https://wiki.musl-libc.org/functional-differences-from-glibc.html), it requires a different import, which now should be applied to files that have `import Glibc` in them.

Musl is a low footprint libc that's used in Linux distributions such as Alpine Linux, which allows producing fairly small container images. Additionally, unlike Glibc, musl allows full static linking, meaning apps can be easily distributed to an arbitrary Linux distribution that may have a version of Glibc incompatible with the one that Swift is usually built with or no Glibc installed at all.
2023-07-18 22:51:26 +01:00
Alex Hoppen
7c15ba8731 Highlight references to actors like references to classes
We weren’t semantically highlighting references to actors because we missed the `ref_actor` case from the sourcekitd `annotations` response.

Fixes #694
rdar://104573568
2023-06-27 20:57:04 +02:00
Tristan Labelle
542a29db2b Implement pull-model documentDiagnostics 2023-05-26 10:35:26 -04:00
Adam Fowler
0da1d40a28 Move module name split into OpenInterfaceRequest
Use group names when running open interface request
2023-05-21 10:26:00 +01:00
Adam Fowler
45adabb3e5 Extend OpenInterface to also seatch for a symbol 2023-05-16 19:32:29 +01:00
Saleem Abdulrasool
b55057a1a1 build: repair the build after the TSCUtility changes
SKSupport now requires a link against Foundation, update the build
system to track that dependency.

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
2023-01-04 21:28:10 -08:00
Saleem Abdulrasool
4bbd74f105 SourceKit: sever dependency on TSCUtility
The dependency on `TSCUtility` was strictly for identifying the platform
of execution. This logic is relatively self-contained and effectively an
extension over an enumeration. Replicate this logic with updates for new
syntactic improvements. This allows us to partially reduce dependency on
swift-tools-support-core. The dependency on TSCBasic is more complicated
to remove due to the extensive use of `AbsolutePath`.

Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2023-01-02 12:30:28 -08:00
Bart Whiteley
d2f7f2f3c6 Generate textual Swift interfaces for module references 2022-12-12 12:45:21 -07:00
Saleem Abdulrasool
7d1bcee1b0 explicitly import TSCBasic types
Explicitly import interfaces from TSCBasic which now allows us to
identify all the swift-tools-support-core interfaces which are in
use in SourceKit-LSP.
2022-09-10 12:53:30 -07:00
Saleem Abdulrasool
169a257ad8 SourceKitD,SourceKitLSP: replace use of Lock with NSLock
Replace the use of the deprecated `Lock` from swift-tools-support-core
with `NSLock`.  The benefit of the deprecated interface was the
`withLock` function which is easily replicated and very unlikely to
change.  By doing so we avoid the warnings about `Lock` being deprecated
when building SourceKit-LSP.
2022-08-23 11:38:50 -07:00
Alex Hoppen
0d83557f87 Provide semantic highlighting for operators in declarations
Adopts https://github.com/apple/swift/pull/60210

Resolves #595
rdar://97961816
2022-08-12 14:21:57 +02:00
YR Chen
031a0913e0 Import CRT to resolve free on Windows 2022-03-14 05:18:28 +08: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
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
Fredrik Wieczerkowski
eaa8c66b25 Update SKDResponseDictionary subscript to actually return optionals 2021-08-24 16:59:18 +02: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
Fredrik Wieczerkowski
7e376e0f8c Reimplement inlay hints using CollectVariableType
Query VariableTypeInfos from sourcekitd and return inlay hints for all
variable declarations without an explicit type annotation.
2021-06-24 18:51:53 +02:00
Fredrik Wieczerkowski
134073deba Implement sourcekitd to VariableTypeInfo deserialization 2021-06-24 18:51:53 +02:00
Fredrik Wieczerkowski
5eaee0f235 Add UIDs for sourcekitd's new CollectVariableType request 2021-06-24 18:51:53 +02:00
Fredrik Wieczerkowski
3fef5145ea Add support for inlay hints using CollectExpressionType
- Add UID for CollectExpressionType request
- Add ExpressionTypeInfo structure
- Add keys to support sourcekitd's CollectExpressionType
- Implement CollectExpressionType request
- Add SwiftLanguageServer.expressionTypeInfos
- Add InlayHint and supporting types
- Add InlayHintsRequest
- Add inlayHints handler stub
- Implement inlay hints request
- Update InlayHint to follow the current proposal
- # This is the commit message #11:
- ...as described in the LSP proposal
- Update doc comment on InlayHintsRequest
- Map inlay hints lazily
- Fix minor style issue
- Add new files to CMakeLists.txt
- Specify commit of the current inlay hints proposal state
- Add public, memberwise initializer for InlayHintsRequest
- assert(false) if deserializing ExpressionTypeInfos fails
- Add dispatch precondition to _expressionTypeInfos
- Add InlayHintsRequest to the builtinRequests
- Factor out function for querying document symbols for URI
- Only render inlay hints after variable bindings
- Test inlay hints on empty document
- Test inlay hints for some simple bindings
- Test ranged inlay hint requests
- Make sure that inlay hints are unique per position
- Test inlay hints for fields
- Apply various PR suggestions regarding inlay hints
- Update inlay hint tests and add case with explicit type annotations
- Continue iterating if an ExpressionTypeInfo fails to deserialize
2021-06-10 16:41:54 +02:00
fwcd
9b81cb25d1 Add SKDResponseArray.forEachUID 2021-05-18 13:13:49 +02:00
fwcd
d49b833bb6 Add new sourcekitd diagnostic uids 2021-05-18 13:04:42 +02:00
Ben Langmuir
d9b2d65d03 Merge pull request #353 from ahoppen/crash-recovery-again
Restart sourcekitd and clangd after they have crashed
2021-01-19 09:28:29 -08:00
Alex Hoppen
a0c9b30a2a Restart sourcekitd and clangd after they have crashed 2021-01-18 13:30:35 +01:00
Ben Langmuir
6eb17c9a7b Merge pull request #358 from hlopko/glibc_fix2
Import Glibc in SKDResponse
2020-12-16 09:05:57 -08:00
Ben Langmuir
ee7ef54e9d Merge pull request #345 from owenv/edu-notes-take-2
Expose diagnostic educational notes as diagnostic codes
2020-12-16 07:46:29 -08:00
Marcel Hlopko
35d44e6339 import Glibc in SKDResponse 2020-12-16 13:43:38 +01:00
Marcel Hlopko
3f506c5725 Import glibc 2020-12-15 17:24:37 +01:00
Owen Voorhees
77a81ad9c1 Expose diagnostic educational notes as diagnostic codes 2020-11-09 18:30:02 -08:00
David Goldman
79795bf4d9 Decrease verbosity of info-level logging (#331)
- Don't log entire LSP notifications/requests for the `info` level, instead log of the form:
  - `Notification<method>` e.g. Notification<textDocument/publishDiagnostics>
  - `Request<method(id)>` e.g. Request<textDocument/hover(6)>
  - `Response<method(id)` e.g. Response<textDocument/hover(6)>

- Only log sourcekitd requests/responses at the debug level
2020-10-08 18:20:56 -04:00
Ben Langmuir
d82c52c003 [logging] Avoid logging cancellation as warnings/errors
Cancellation shows up as an error code, but it is not a real error, so
don't log it like one.

https://bugs.swift.org/browse/SR-13344
2020-08-04 10:04:21 -07:00
Ben Langmuir
b7ca21f433 [completion] Add server-side filtering UIDs 2020-07-29 09:42:18 -07:00
Ben Langmuir
8bb7086630 [gardening] Sort and organize sourcekitd keys
* The interesting keys to split out are "code-completion options", not
  any key that is used by completion.
* Sort the main key list
* Fix the name of the doc_brief key
2020-07-29 09:42:18 -07:00
Ben Langmuir
4a86e81984 [sourcekitd] Fix registry assertion 2020-06-08 17:58:25 -07:00
Ben Langmuir
8520c8de10 [cmake] Attempt to update the build files for recent changes
Update for files added/removed and the new sourcekitd target.
2020-06-04 09:48:22 -07:00