This set of changes is the last set of changes required to build the
entire test suite on Windows. Although the tests do not yet fully pass,
this is a prerequisite for getting the test suite passing.
This actually addresses the real issue that was ignored earlier about
pipes on Windows. The FileHandle cannot provide a non-owning file
descriptor (the returned file descriptor would need to be explicitly
`_close`'d by the receiver). Foundation now vends a `_handle` accessor
to the OS primitive handle. Use this to create the dispatch loop for
messaging. We now create the JSONRPCConnection from handles on Windows
which actually should help enable running some of the tests on Windows
as well.
* Replaces two logs since those don't result in response messages anymore
* Adds a func for sending messages synchronously, to get the two messages out before fatalError
* Send `didSave` notifications to clangd if it supports it
- Minor update to the LSP protocol for `didSave` and `colorProvider` to be more in line with the spec
- Only send color requests over to clangd if it supports it
Rationale for this change: clangd recently implemented didSave support,
it is used to rebuild preambles when the user edits a header file
referenced by an open file.
Change-Id: Ie6e2198bdeccb9d1b4083806c254475baadc2d2b
Close the fd via the FileHandle rather than directly on the file
descriptor so that it does not get closed again when the pipe is
released. Fixes running test in parallel on Linux.
Specifically, we care that all outstanding **writes** are finished
before we call the close handler, because otherwise we may (a) send
corrupted output during shutdown, or (b) drop notifications and replies
sent during the shutdown process. The former is a potential issue for
clients that are not robust about parse failures, and the latter is an
issue for reproducibility and robustness during testing/debugging - in
particular, we have some integration tests that send data without
waiting for individual replies and they need to finish outstanding
replies before exiting.
rdar://60159448
Request types should always have the suffix Request and notifications
should end with Notification.
Also moved all request and notification types into separate folders to
reduce the number of files in the LanguageServerProtocol folder.
Since the connection and message handler have a reciprocal need to know
about each other, move the closeHandler so that it has the opportunity
to call a method on the message handler if desired.
According to the LSP specification, arbitrary URIs can be used as
document identifiers. Instead of internally assuming that all URIs are
URLs, use a DocumentURI enum to represent URIs. These can either be file
URLs or other URIs whose value as treated as an opaque string.
We will be able to split the LSP modules off later. These LSP modules
will provide the ability to write custom LSP servers and clients in
Swift. The sourcekit-lsp repository will build on top of this new
package to provide an LSP implementation that creates a language server
for Swift and C-based-languages.
We don't need to check the message buffer in the middle of the test; it
suffices that we got the expectation fulfilled at the right times. The
check at the end of the test can be done by synchronizing via close()
before reading.
These tests don't really need to check the message buffer anyway, it was
mostly a sanity check. There is still a race in testMessageBuffer, which
actually has a reason to look at the buffer and will need to be handled
separately.
We implicitly close the connection when the input file descriptor is
closed, or if it has an error. But we also close things down explicitly
when we see the exit notification. We need to protect against a race
triggering us to call the close handler multiple times. This was
resulting in `sourcekit-lsp` racing to call `exit(0)`, which triggered a
double-free and abort on Linux.
When running in debug, or in continuous integration that is not setup
for performance testing, default to not collecting performance metrics
to avoid failures due to slow or high-variability tests (default
max_stddev = 10% in xctest). Instead, run the measured block once and
skip the timing code. This has the nice side effect of speeding up test
runs in debug builds.
Add remaining foldingRange protocol capabilities
Sending offset data to folding requests
FoldingRange test
Support folding comments
Add test for folded comments