Commit Graph

643 Commits

Author SHA1 Message Date
Saleem Abdulrasool
79105208d5 SKCore,SKTestSupport: adjust test server handling
The test system depended on the shebang to locate the python
interpreter.  However, this is not a portable system.  Instead, prefer
to explicitly search for the interpreter prior to the execution.  This
enables supporting execution of the script support on all platforms. A
secondary change of the printed string is required for Windows. Python
will replace `\n` with `\r\n` resulting in `\r\n` being emitted as
`\r\r\n` on Windows breaking the expectations on the receiver.  Adjust
this by explicitly writing out a binary string to the raw underlying
buffer to avoid the translation.
2022-09-06 09:19:37 -07:00
Saleem Abdulrasool
b668f992cb SourceKitLSP: normalise paths for clangd
Ensure that we use the native path representation for clangd rather than
the POSIX spelling.  This is required to map the command for the source
file.
2022-09-01 08:47:02 -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
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
Saleem Abdulrasool
a329a3efd1 SKTestSupport: adjust imports for warnings/Swift 6 support
This adjusts the imports in this particular source file to explicitly import Foundation to allow the use of `URL`.  This is a future error and currently a warning.  This cleans up a warning.
2022-08-17 09:34:51 -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
Ian Hanken
e36eb50b41 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-08-02 10:09:28 -07:00
Alex Hoppen
319e83f6bd Merge pull request #590 from ahoppen/pr/build-args-to-fallback-build-system 2022-07-28 07:18:48 +02:00
Alex Hoppen
c69c643cdc Merge pull request #587 from keith/ks/lightly-validate-discovered-package.swift-files 2022-07-27 07:07:18 +02:00
Saleem Abdulrasool
c3bec3c8e3 Merge pull request #594 from compnerd/optionality
SKSwiftPMWorkspace: remove unnecessary optionality
2022-07-23 08:47:30 -07:00
Saleem Abdulrasool
78570d9fe9 SKSwiftPMWorkspace: remove unnecessary optionality
These functions will return a value and never nil, so remove the
optional return type.  This helps make it easier to reason about
the code paths.
2022-07-22 08:46:28 -07:00
Alex Hoppen
5af65fb184 Increase default timeout to 60 seconds
The reduced timeout of 15 seconds was causing issues in CI.
2022-07-21 20:20:37 +02:00
Alex Hoppen
711c22544f Pass manual build arguments that specified using -Xswiftc when starting sourcekit-lsp, to the fallback build system
Previously, we weren’t respecting these arguments in the fallback build system.

rdar://97044457
2022-07-20 00:51:27 +02:00
Keith Smiley
fef12334b3 Lightly validate discovered Package.swift files
Previously if you had a normal source file named Package.swift
sourcekit-lsp would pick it up and fail. Now there is some very light
validation that the file looks valid, checking that it has a
PackageDescription import, before accepting it, otherwise it keeps
looking.
2022-07-19 09:39:09 -07:00
Alex Hoppen
8c9e3843ce Merge pull request #588 from ianhanken/typedefinition
Add type definition request and types
2022-07-19 00:32:17 +02:00
Saleem Abdulrasool
d1b1b48908 SourceKitLSPTests: replace some fatalError with XCTFail
This replaces many instances of `fatalError` with `XCTFail`.  Although
these code paths should not come to pass, there are currently failures
in the test suite on Windows where these trigger.  By using `XCTFail`
instead, we allow the tests to continue execution which is helpful for
investigating the current state and make progress towards fixing the
issues.
2022-07-17 17:30:18 -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
Saleem Abdulrasool
b2459099cd Merge pull request #585 from compnerd/assert
SourceKitLSP: change an assert to a check
2022-07-14 08:28:14 -07:00
Keith Smiley
92b3147980 Add Package.swift root path to error message
Previously in the case you have an invalid Package.swift file the LSP
log would just show:

```
[2022-07-12 14:57:23.940] failed to create SwiftPMWorkspace: the package does not contain a buildable target
```

With this change it at least hints you towards where the invalid file
is:

```
[2022-07-12 15:00:45.106] failed to create SwiftPMWorkspace /Users/ksmiley/dev/oss-swift/swiftpm/Sources/PackageModel: the package does not contain a buildable target
```
2022-07-12 15:02:54 -07:00
Saleem Abdulrasool
586218448a SourceKitLSP: change an assert to a check
Rather than asserting, raise an error for the user and abort the
operation.  This is motivated by the desire to get the test suite mostly
working on Windows so that the underlying issues can be worked through
more easily.
2022-07-12 12:47:59 -07:00
fwcd
9cdd025fc4 Include module names in call hierarchy items 2022-07-11 14:18:02 +02:00
FW
2bbc8ba455 Merge pull request #582 from fwcd/type-hierarchy
Implement type hierarchy
2022-07-11 12:40:33 +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
6f69af9afa Test type hierarchy 2022-07-06 05:05:30 +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
Saleem Abdulrasool
a96b17178b Merge pull request #580 from compnerd/path
SKCore: add an additional spelling for `PATH`
2022-07-05 09:25:38 -07:00
FW
f3b993e898 Merge pull request #581 from fwcd/type-hierarchy-structures
Add request structures for type hierarchy
2022-07-05 16:39:46 +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
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
Saleem Abdulrasool
e983915f6f SKCore: add an additional spelling for PATH
Windows uses `Path` for the environment variable spelling, but expects
that environment variables are case-insensitive.  Foundation's
implementation treats the environment variables as being case sensitive
and will not properly look up the value  Add a case corrected spelling
for that support.
2022-07-04 08:41:24 -07:00
fwcd
34547b490d Add call hierarchy tests
- Set up infrastructure for call hierarchy tests
- Add test case for call hierarchy
- Fix call hierarchy test by querying usr
- Test incoming call hierarchy too
2022-07-02 05:24:42 +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
37c6f88957 Merge pull request #573 from ahoppen/pr/log-if-unknown-os
Log error if sourcekit-lsp is unable to determine the host OS
2022-06-24 07:51:18 +02:00
Alex Hoppen
f1062b9fbf Log error if sourcekit-lsp is unable to determine the host OS
This should have allowed us to catch the issue discussed in https://forums.swift.org/t/making-a-sourcekit-lsp-client-find-references-fails/57426/17 a lot more easily.

rdar://93897062
2022-06-23 15:18:40 +02:00
Alex Hoppen
993a906645 Merge pull request #571 from ahoppen/pr/single-timeout-duration
Set a default timeout duration
2022-06-23 12:53:23 +02:00
Alex Hoppen
df594e332c Set a default timeout duration
Instead of having ad-hoc timeout durations in all the test cases, specify a default timeout duration that can be used by tests.

This allows us increase the timeout duration for all tests if we discover that e.g. sourcekitd is slower in CI setups.

rdar://91615376
2022-06-14 17:26:06 +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
David Goldman
472a06c88a 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.
2022-06-09 10:45:52 -04:00
Alex Hoppen
1ad7e30416 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-07 18:03:00 +02:00
Alex Hoppen
f4efc580b5 Merge pull request #558 from ahoppen/pr/reopen-documents-after-workspace-change
When receiving a didChangeWorkspaceFolders notification, reopen documents that moved to a different workspace
2022-06-01 09:33:45 +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
Alex Hoppen
59c5b63238 Update python scripts to Python3 2022-05-31 22:58:25 +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