Commit Graph

66 Commits

Author SHA1 Message Date
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
Bart Whiteley
d2f7f2f3c6 Generate textual Swift interfaces for module references 2022-12-12 12:45:21 -07: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
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
44414c5f1f SourceKitLSP: use AbsolutePath to compute the filename
Rather than treating the filename as an opaque string and splitting on
`/`, use `AbsolutePath` to perform the `basename` operation on the path.
This ensures that we split the path properly on platforms which do not
use the POSIX path separator `/`.
2022-09-29 13:26:37 -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
fwcd
9cdd025fc4 Include module names in call hierarchy items 2022-07-11 14:18:02 +02:00
fwcd
4ec6a49a8f Resolve retroactive conformances in supertype hierarchy 2022-07-08 17:43:19 +02:00
fwcd
7dd90ab40a Improve multi-protocol extension formatting in type hierarchy 2022-07-08 04:58:43 +02: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
3e90b82755 Use if-let for local symbol occurrence fallback
Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2022-07-04 23:32:54 +02:00
fwcd
411dae172c Implement call hierarchy
- Add prepareCallHierarchy handler
- Register callHierarchyProvider capability
- Use proper symbol kind in prepareCallHierarchy
- Stub out implementation of outgoingCalls
- Encode usr and uri in indexToLSPCallHierarchyItem
- Extract call hierarchy item data parser
- Implement incomingCalls
- Add Call Hierarchy to the list of supported features
- Resolve caller/callee definition locations for call hierarchy
2022-07-02 05:24:13 +02:00
fwcd
51f10e29f4 Factor out indexToLSPLocation 2022-06-30 20:04:32 +02:00
fwcd
33d9e4bcea Return SymbolOccurrence info in extractIndexedOccurrences 2022-06-30 19:50:30 +02:00
fwcd
143abb9a86 Add doc comment to extractIndexedOccurrences 2022-06-30 03:32:10 +02:00
fwcd
146531ca7b Clean up index lookup requests
- Add missing useLocalFallback
- Address PR suggestions regarding index request handlers
2022-06-29 15:30:20 +02:00
Alex Hoppen
44990b6e6b Merge pull request #465 from fwcd/upstream-inlay-hints
Migrate to upstream LSP inlay hints request
2022-06-14 15:10:13 +02:00
Alex Hoppen
79b07fd6bf 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-05-31 23:00:20 +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
0942e74f89 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:48:31 +02:00
Alex Hoppen
cfdb2f8bad Listen to DidChangeWorkspaceFolders notification 2022-05-04 14:48:31 +02:00
Alex Hoppen
97ccf1da0c 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-04 14:48:31 +02:00
Alex Hoppen
c04b2efbe3 Add capability to open multiple workspaces during the initialize request 2022-05-04 14:48:31 +02:00
Alex Hoppen
d02d3914c5 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-04 14:48:31 +02:00
Alex Hoppen
2f1930c8a3 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-04 14:48:31 +02:00
Alex Hoppen
daf60b1c04 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
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
Alex Hoppen
a4118a57bb 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-04 14:48:31 +02:00
Alex Hoppen
5deb742969 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-04 14:48:31 +02:00
Alex Hoppen
b2f4fe0e29 Refactor the way toolchain language servers are created
Mostly cleanup
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
798803021e Listen to DidChangeWorkspaceFolders notification 2022-05-02 09:31:07 +02:00
Alex Hoppen
09f52e9122 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-02 09:31:07 +02:00
Alex Hoppen
28e6888662 Add capability to open multiple workspaces during the initialize request 2022-05-02 09:31:07 +02:00
Alex Hoppen
f91564a75f 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-02 09:31:07 +02:00
Alex Hoppen
437275e44a 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-04-29 14:33:01 +02:00
Alex Hoppen
8b9d6860b1 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
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
Alex Hoppen
ab946dbdca 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-04-29 14:33:01 +02:00
Alex Hoppen
a26bc8dbea 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-04-29 14:33:01 +02:00
Alex Hoppen
32c1f6d88a Refactor the way toolchain language servers are created
Mostly cleanup
2022-04-29 14:33:01 +02:00
Alex Hoppen
05a9237f2c 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-28 10:28:41 +02:00
Alex Hoppen
5310332bd5 Merge pull request #471 from ahoppen/pr/watch-for-package-manifest-changes
Reload the package if Package.swift changes
2022-04-20 11:44:11 +02:00
Alex Hoppen
cc6377e607 Reload the package if Package.swift changes
rdar://88064286 [SR-15633]
2022-04-19 21:51:11 +02: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
Alex Hoppen
fda6326e3b Only reload SwiftPM package if a file that is relevant to SwiftPM changes 2022-01-19 11:20:10 +01:00