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.
Not all editors send shutdown/exit messages, particularly when you quit
the application (as opposed to a single editor window), so we sprinkle
`prepareForShutdown()` into the connection closed handler as well. I
verified manually in such an editor that this lets us save the index on
quit.
If the client is well-behaved and sends a shutdown request, we close the
index in order to flush it to disk. This should speed up reopening the
same project when it is already indexed.
URL can in fact store URIs, it just doesn't have a very nice API to
interact with them. As long as we only operate on absoluteString, we
should be fine though. So instead of implementing the logic for
detecting file URLs ourselves, we can just use a URL as storage for
DocumentURI.
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.
`SourceKitServer` now talks to the `SwiftLanguageServer` and
`ClangLanguageServerShim` directly through the `ToolchainLanguageServer`
protocol.
Each individual `ToolchainLanguageServer` manages its own threading.
Change-Id: I77aa5468f1486bd4e6e6fdb732c6a051ee05c6d1
While we ideally could maintain diagnostics state for closed documents
as the LSP specification encourages, since we have no way to do that
today, it's better to throw out diagnostics for closed documents so that
they do not sit around stale. We do not send a publishDiagnostics
though, so the editor can maintain the list of diagnostics if desired,
but when we reopen the document we can provide completely fresh data.
This lets us use the `Range<Position>` without manually converting back
and forth in the majority of cases. See the note on HoverResponse for
the behaviour with Optional that makes us have to provide a custom
Codable implementation in two places that used to be synthesized.