Commit Graph

59 Commits

Author SHA1 Message Date
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
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
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
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
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
Ben Langmuir
7788bff20d Fix lifetime issues in tests
A number of tests were failing with the -Onone lifetime changes.
Regardless of what happens with that change, I'd like to keep our tests
passing with the stricter rules since we also test in release builds.
2021-04-05 15:54:29 -07:00