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