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
Introduce a `BuildSystemDelegate` to handle notifications from the build system
* `SourceKitServer` is the main delegate to process these notifications
* Currently limited to changes in `FileBuildSettings`
* Delegate informs the `BuildSystem` of files to watch via `registerChangeWatching(for: URL)` and `unregisterChangeWatching(for: URL)`
* In the future we could have more integration for handling changes in dependencies
Handling changes in `FileBuildSettings`
* `SourceKitServer` sends notifications to the internal LSPs informing them of any opened documents that have changes in their compiler flags
* For clangd, we send a notification to update the compilation database
* For SourceKit/sourcekitd we must close and reopen the file to force a new AST with the new compiler flags
While we generally want to be type-safe, initialization options is
LSP-server specific, so just use LSPAny so we can pass arbitrary data
through as needed.
Clang looks for the C++ standard headers relative to the clang binary
that we provide in the compilation database. So pass through a real path
so that we get the correct headers.
This builds on the indexer changes to support test projects using the
tibs build system. See the commit message from IndexStoreDB for more
information.
This commit adds a couple of simple tests using test fixtures in the
INPUTS directory. It is a fairly minimal change for using the indexer's
test support code to prove the model works. One missing piece here is
support for mutable sources and updating the index, which is supported
on the IndexStoreDB side, but needs a bit more work here. This also
doesn't include any tests using swiftpm's build system.
1) Toolchain ID is no longer unique; XcodeDefault toolchains may be
registered multiple times as long as their path is different
(e.g. different Xcode versions). At the moment no other toolchain
may be duplicated.
2) `BuildSystem` specifies a `Toolchain` directly instead of a
Toolchain identifier.
3) New methods to access Toolchains in the registry:
- All toolchain(s) with the given identifier
- Toolchain (if any) for the given path