Commit Graph

195 Commits

Author SHA1 Message Date
Tristan Labelle
c076bd5282 Implement pull-model documentDiagnostics 2023-06-02 13:36:07 -04:00
Tristan Labelle
ea9f173339 Add boilerplate for pull-model diagnostics 2023-06-02 13:35:00 -04:00
Adam Fowler
9ca89669b2 Swiftinterface symbol lookup
Generate swiftinterface for symbol lookup

When a symbol definition returns it is in a swiftinterface file, create textual version of swiftinterface and return that in response.

Extend OpenInterface to also seatch for a symbol

Fix warning

Syntax changes after review

Move module name split into OpenInterfaceRequest

Use group names when running open interface request

Requested changes from PR

rename symbol to symbolUSR
Cleanup OpenInterfaceRequest.init

Fix tests

Added testDefinitionInSystemModuleInterface

Use SwiftPMPackage test module
Added version of buildAndIndex that includes system symbols

Merge buildAndIndexWithSystemSymbols with buildAndIndex

Added specific test project for system swiftinterface tests

Add multiple tests for various system modules
2023-05-24 18:53:37 +01:00
Ben Barham
f75d20f46b Merge pull request #680 from bnbarham/update-inlay-provider-registration
Update `inlayHintProvider` registration
2022-12-15 14:57:48 -08:00
Ben Barham
73af860ac2 Update inlayHintProvider registration
The LSP API allows a boolean here:
```
	/**
	 * The server provides inlay hints.
	 *
	 * @since 3.17.0
	 */
	inlayHintProvider?: boolean | InlayHintOptions
		 | InlayHintRegistrationOptions;
```

Update our server capabilities to allow this.

Resolves rdar://102913088.
2022-12-15 11:26:29 -08:00
Artem Chikin
05b03c124e Fix CMake build by adding missed new files to CMakeLists 2022-12-14 09:50:38 -08:00
Bart Whiteley
d2f7f2f3c6 Generate textual Swift interfaces for module references 2022-12-12 12:45:21 -07:00
Max Desiatov
5b16c3e19d LanguageServerProtocol: handle new files with CMake (#677)
New files not available to CMake causes build failures on Windows.
2022-12-07 17:22:42 +00:00
Alex Hoppen
ca45a7a62b Return a .serverCancelled error code if the server cancels a request
`.cancelled` should only be returned if the client requested cancellation.
2022-12-05 08:45:36 +01:00
Alex Hoppen
975286d353 Update capability definitions to LSP 3.17 2022-12-04 19:56:51 +01:00
Alex Hoppen
93a8f91436 Update request and notification definitions to LSP 3.17 2022-12-01 10:44:40 +01:00
Boris Buegling
43c072dc84 Adopt to path API changes
We are moving to a better model for TSC's path APIs in apple/swift-tools-support-core#353. The previous API is still available (but deprecated) as much as possible, but since SourceKit-LSP was using `resolveSymlinks` (which is now throwing) quite a bit, there are some changes necessary.
2022-10-18 15:28:54 -07:00
Robert Widmann
0b89da4920 Implement textDocument/declaration
A declaration request is similar to a definition request, except that it is expected to return (potentially) many results across the workspace for a given reference. For example, an inline function or macro may have many declarations in the workspace, but only one "good" or canonical definition. For now, this is only implemented by forwarding the request on to clangd since I'm unfamiliar with a SourceKit query for this.

For languages like Swift that lack such a sharp declaration/definition split, we could potentially use this request to provide navigable metadata on linked definitions. For example, the declaration for a type reference would include all extensions of that type in the workspace.
2022-10-10 11:29:07 -07:00
Saleem Abdulrasool
7dafade906 Update CMakeLists.txt
Add a dependency on TSCBasic for LanguageServerProtocol.  This dependency was added recently via an `import` and was updated in Package.swift but was missed in the CMake build.
2022-09-27 10:08:33 -07:00
Saleem Abdulrasool
89c591c16a SourceKitLSPTests: convert to native path spellings
Explicitly convert paths from POSIX spelling to native spelling in a
number of cases.  These changes help improve the test coverage on
Windows.
2022-09-24 16:09:08 -07:00
Saleem Abdulrasool
d4b56e334a LSP: always use FSR for URI
When converting the URI to a path string, ensure that we convert to the
file system representation.  This is important as this ensures that we
are always passing SourceKit the native path string.  With this change,
the code completion behaviour for the LSP test suite on Windows is
repaired.
2022-08-19 08:04:12 -07:00
Ian Hanken
1cf8ce7343 Add type definition request and types
This request is currently just a skeleton and no-ops when used.
2022-07-14 09:54:11 -07:00
fwcd
25f4bd6ea3 Implement type hierarchy
- Add typeHierarchyProvider
- Implement prepareTypeHierarchy request
- Add supertype and subtype request handlers
- Implement supertypes and subtypes request
- Display location and conformance of extensions in type hierarchy
- Include extensions in the type hierarchy
- Include module names in type hierarchy
2022-07-06 05:05:25 +02:00
fwcd
954d96163f Add type hierarchy structures
- Add TypeHierarchyItem
- Add type hierarchy requests
- Update CMakeLists with new type hierarchy types
- Add type hierarchy requests to Messages
2022-07-05 13:55:36 +02:00
fwcd
818c44d990 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-05-24 16:50:17 +02:00
Alex Hoppen
d917e40410 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-04 14:48:31 +02:00
Ben Langmuir
3927e639be Revert "Support opening multiple workspaces in a single sourcekit-lsp instance" 2022-05-03 13:47:19 -07:00
Alex Hoppen
6425b0d212 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-04-29 14:33:01 +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
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
Emil
b70615c375 Add missing space in doc comment
Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2021-10-04 15:48:13 +02:00
Snowy
c56e5fb728 Register rename requests 2021-10-02 15:35:00 +02:00
Snowy
56dafdeade Add RenameRequest and PrepareRenameRequest 2021-10-02 15:07:36 +02: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
David Goldman
9fbaebb40f Fix document symbols regression
This appears to have been accidentally removed in
17f656865d, the `children` field is
optional in the LSP spec.

Change-Id: I1055658c8f09873279d676fee0daff02fa59e3f8
2021-09-20 12:24:58 -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
David Goldman
9cda11628b Use dynamic registration for folding range options
Dynamically register because clangd doesn't currently support it, but
may in the future.

Change-Id: I2bf139ea8aad09b58232ba9d09dfddcd89b977cd
2021-07-01 16:35:46 -04: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
Saleem Abdulrasool
b8392f6a3d LanguageServerProtocol: add missing space (NFC)
Add a missing space in the doc-comment that I noticed while testing other issues.  NFC.
2021-05-25 13:00:42 -07:00
fwcd
ac0f2b5f85 Use a RawRepresentable struct for DiagnosticTag 2021-05-06 19:35:27 +02:00
fwcd
bcbfd0a273 Add DiagnosticTag
Diagnostic tags represent additional metadata about a diagnostic, e.g.
for unused variables or deprecations. This lets editors e.g. style such
diagnostics in a special way, e.g. by striking through deprecated
methods or dimming unused values.
2021-05-01 04:56:23 +02:00
David Goldman
ad9b09e335 Add support for clangd's semantic highlighting (#388)
- Add LSP types for semantic highlighting
- Limited to clients which support dynamic registration for semantic highlighting
- Requires clangd 11 or later
2021-04-12 16:44:30 -04:00
David Goldman
3635d2531c Dynamically register completion options for supporting clients (#380)
Using dynamic registration (when supported by the client) allows
us to provide different completion options for ObjC and Swift
files.

We should be able to expand this to other capabilities in the future
(e.g. semantic highlighting, execute command support).
2021-04-06 16:33:05 -04:00
David Goldman
01f4b0ff00 Add LSP types and server stubs for call hierarchy support (#377)
* Add LSP types and server stubs for call hierarchy support

* Update CMakeLists.txt for new LSP types

* Call hierarchy misc fixes

* Minor PositionRangeArray fixes to simplify codable conformance

* Add CodingTests for PositionRangeArray and CallHierarchy encoding
2021-03-22 17:35:37 -04:00
Saleem Abdulrasool
fc34ed8e84 build: update the CMakeLists.txt after #376
Update the source file list for the new files.  This repairs the
bootstrap build on Windows.
2021-03-17 19:25:29 -07:00
David Goldman
e6b0796cff Additions to the LSP module for workspace/didChangeWatchedFiles (#376)
* Additions to the LSP module for `workspace/didChangeWatchedFiles`

We can then use this functionality to allow a `BuildSystem` to watch
files (e.g. via the client or even in-process file watching),
which would allow us to do things like detect new files and provide
accurate build settings for them.

* Improve #file and #line for LSP test errors

Also regenerate Linux main

* Add `LSPAnyCodable` protocol requirement to RegistrationOptions

* Don't encode an optional documentSelector to null

* Skip running `testSourcekitdCrashRecovery` when not on macOS
2021-03-17 15:11:26 -04:00
Owen Voorhees
77a81ad9c1 Expose diagnostic educational notes as diagnostic codes 2020-11-09 18:30:02 -08:00
Saleem Abdulrasool
67aaa09d70 build: allow building with dispatch and Foundation from the toolchain
This allows building without dispatch and Foundation build roots, which
allows for a multi-phase build.  This is intended to support the Windows
staged build where dispatch and Foundation are part of the SDK and
SourceKit-LSP is part of the devtools.
2020-10-07 19:08:02 -07:00
Saleem Abdulrasool
c55c71d111 build: update CMakeLists.txt
This updates the CMakeLists.txt to allow building SourceKit-LSP with
CMake.
2020-09-06 18:44:34 -07:00
Ben Langmuir
16dc2fb0c9 [completion] Enable server-side filtering by default 2020-07-29 11:06:55 -07:00
Ben Langmuir
bf9053c671 [gardening] Rename CodeCompletionOptions -> SKCompletionOptions
Since it is being used in the LSP protocol layer, give it a name that
clarifies that it is SourceKit-specific.
2020-07-29 10:01:24 -07:00
Ben Langmuir
a5832e978b [gardening] Fix copyright headers and formating in modified files 2020-07-29 09:55:02 -07:00
Ben Langmuir
fe283fa2c2 [completion] Add an extension to pass completion options per-request 2020-07-29 09:42:47 -07:00
Ben Langmuir
c45de61a72 [log] Improve description of Position
By default, print 1-based line/column numbers using the defacto standard
line:column format. In debug print, continue to use the 0-based values
to match the constructor.
2020-07-29 09:42:47 -07:00