Commit Graph

80 Commits

Author SHA1 Message Date
Ben Langmuir
d8b5a980ee [gardening] Fix copyright headers and formating in modified files
Conflicts:
	Sources/SourceKit/SourceKitServer.swift
	Sources/SourceKit/sourcekitd/SwiftLanguageServer.swift
2020-10-16 13:11:50 -07:00
Ben Langmuir
9d5f54715c [completion] Fix tests when using server-side filtering
With this change, tests pass whether we default to server-side or
client-side filtering. Also duplicate a few interesting tests to run
both ways. A future commit will beef up the test coverage for
server-side filtering specifically.

Conflicts:
	Sources/SourceKit/sourcekitd/SwiftLanguageServer.swift
2020-10-16 12:02:43 -07:00
Ben Langmuir
f8f98dd5a9 [completion] Pass through new code-completion options
Conflicts:
	Sources/SourceKit/CodeCompletionOptions.swift
	Sources/SourceKit/SourceKitServer.swift
	Sources/SourceKit/sourcekitd/SwiftLanguageServer.swift
2020-10-16 10:54:02 -07:00
David Goldman
81e2688c5d Support for clangd's go-to-definition for #include/#import (#247)
* Support for clangd's go-to-definition for header files

- By forwarding the request to clangd when it fails to give
  symbol information, we are able to use its built in
  go-to-definition support for headers (jump to header file)

* Add static tibs test for clangd go-to-#include

* Move #include test to SourceKitTests and regenerate linux main

* Fix improper escaping of %40 in file URLs

* Add URL escaping test

* Another attempt to fix broken BuildServerBuildSystemTests test on Linux

- URL's `standardizedFileURL` removes trailing slashes from file URLs,
  but only on Linux
2020-03-13 19:20:25 -04:00
Ben Langmuir
44f535fb91 [buildsystem] Wire up BuildSystemManager to SourceKitServer
Wires up the build system manager in the server, and all existing tests.
2020-02-05 21:53:52 -08:00
Ben Langmuir
a679d4553d [buildsystem] Standardize call between register and settings query NFC
In preparation for injecting doing more during registration, pass
through the same parameters (add language) so that we can call settings
as necessary.
2020-02-05 21:53:52 -08:00
Ben Langmuir
47d92d89f9 Remove unused toolchain lookup function NFC
We want to be able to lookup the toolchain by file eventually, but it's
currently dead code.
2020-02-05 21:53:52 -08:00
Ben Langmuir
a22004dd90 [buildsystem] Fix race when settings are updated
Jump onto `queue` when receiving notifications from the build system,
which could be on any queue.
2020-02-05 20:44:25 -08:00
Ben Langmuir
ddb9a8d964 Make initial workspace load asynchronous
Some editors treat the initialize request as blocking, or otherwise time
out if it takes too long. We have been scraping that edge for swiftpm
projects (time taken to load the manifest and construct a build graph),
and large compilation databases (time taken to parse the json and then
split commands into separate arguments). In practice, a *debug build* of
sourcekit-lsp was failing to open a large compilation database fast
enough for sublime text's lsp plugin (3 second limit).

This change hides the latency for loading the build system and creating
the index by letting it continue beyond the initialize request, blocking
instead the next request. This is not a complete solution. In addition
to hiding latency in between requests, this also is based on editors
being more forgiving about slow requests beyond the first initialize.`

We should also continue to improve the performance of the initial load
of the build system and index. And we should also consider more
prinicipled ways to use asynchronicity, for example by not doing the
initial load on the server's message queue. The main challenge for that
is that we have some assumptions, particularly in tests, that the index
will be created already, and for the index to load we currently block on
the build system load in order to get the index directory.
2020-02-04 09:20:50 -08:00
Ben Langmuir
b917ebe5d9 Infer index store path from compilation database
Find the index store path by searching through the command-line
arguments, and if found, also provide a default database path next to
the index store. Also add command-line arguments so that either of these
can be overridden. We could also easily add these as initialization
options if an LSP client wanted to provide them in the future.
2020-02-03 09:07:01 -08:00
Ben Langmuir
bda0cc48a0 Merge pull request #212 from DavidGoldman/dependencyhandling
Work on implementing dependenciesUpdated part of Build System integration
2020-01-27 15:32:55 -08:00
Alex Hoppen
ce5f4774c6 Rename Shutdown to ShutdownRequest 2020-01-23 14:21:45 -08:00
David Goldman
8331bb5146 Work on implementing dependenciesUpdated part of Build System integration
Change-Id: Ieed32d625afb570ced559206f1867bd2d4d2bacf
2020-01-07 15:58:50 -05:00
Alex Hoppen
e2d7eedef8 Unify the naming of request and notification types
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.
2019-12-13 13:56:10 -08:00
Alex Hoppen
c3e70b5933 Update ServerCapabilities to match version 3.14 of the LSP spec 2019-12-12 17:17:35 -08:00
Alex Hoppen
82be88f696 Update ReferencesRequest to match version 3.14 of the LSP spec 2019-12-06 08:31:44 -08:00
Alex Hoppen
7ebf103645 Update ImplementationRequest to match version 3.14 of the LSP spec 2019-12-06 08:31:44 -08:00
Alex Hoppen
711d7827dd Update DefinitionRequest to match version 3.14 of the spec 2019-12-06 08:31:19 -08:00
Ben Langmuir
d78d6fb405 Fix deadlock in exit -> onExit -> close -> closeHandler -> sync 2019-11-21 11:56:38 -08:00
Ben Langmuir
ac630e4617 Be more resilient about trying to flush the index on shutdown
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.
2019-11-21 11:56:38 -08:00
Ben Langmuir
6c66f8021c [index] Attempt to save index on shutdown
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.
2019-11-21 11:56:37 -08:00
Alex Hoppen
558d7fc664 Change backing storage of DocumentURI to URL
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.
2019-11-20 09:41:48 -08:00
Alex Hoppen
5c839f8640 Add support for non-URL URIs
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.
2019-11-20 09:41:48 -08:00
Ben Langmuir
775e198f77 Rename LSPSupport -> LSPLogging to reflect reduced scope
Ideally we can someday migrate this to something more standard such as
swift-log, and make it explicit how to control logging for the JSONRPC
module.
2019-11-19 11:08:31 -08:00
Alex Hoppen
05ecd26d08 Reorganize the repository into a set of bare LSP modules and SourceKit modules
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.
2019-11-14 10:35:06 -08:00
Richard Howell
1d7858e023 call delegate on build targets change 2019-10-21 10:39:22 -07:00
David Goldman
043d27860d Remove the need to use Connection to talk to internal LSPs
`SourceKitServer` now talks to the `SwiftLanguageServer` and
`ClangLanguageServerShim` directly through the `ToolchainLanguageServer`
protocol.

Each individual `ToolchainLanguageServer` manages its own threading.

Change-Id: I77aa5468f1486bd4e6e6fdb732c6a051ee05c6d1
2019-10-09 13:49:11 -04:00
Bruno Rocha
8861ac06c1 Add Local Refactoring 2019-10-03 11:20:41 -03:00
Ben Langmuir
71a94b0717 Add -Xclangd to allow forwarding options to clangd command-line
And factor the configuration that we thread through to the sourcekit
server.
2019-09-30 14:29:18 -07:00
Bruno Rocha
20c026c8e2 Cleaning Code 2019-09-24 17:59:38 -03:00
Bruno Rocha
c20fe44c42 Convert CommandArgumentType -> LSPAny references 2019-09-24 17:21:32 -03:00
Bruno Rocha
7180d66e60 Avoid using decoders for retrieving dictionary data 2019-09-24 17:21:32 -03:00
Bruno Rocha
e71965fc7d Inject metadata at commands 2019-09-24 17:21:32 -03:00
Bruno Rocha
cef91670f5 Add ExecuteCommand/ApplyEdit 2019-09-24 17:21:32 -03:00
David Goldman
e5caf44fda Add a BuildSystemDelegate which supports notifications for build settings changes
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
2019-09-06 17:44:36 -04:00
Ben Langmuir
e1fa70d086 Update SPM -> TSC module name prefixes 2019-09-03 08:29:19 -07:00
Ben Langmuir
d15071bbd9 [test] Add workspace/_pollIndex extension for testing
Expose the index polling mechanism so it can be used in out-of-process
tests.
2019-08-22 15:57:25 -07:00
Ben Langmuir
ff7d8c1930 [test] Add listenToUnitEvents to initialization options
This should be used along with polling to explicitly control when index
data is read in tests that are outside the sourcekit-lsp process.
2019-08-22 14:53:53 -07:00
Ben Langmuir
9ed80c545e [lsp] Remove InitializationOptions type in favour of LSPAny
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.
2019-08-22 14:27:44 -07:00
Richard Howell
1f57193cf4 add toolchain interface to BuildServer 2019-08-15 11:04:54 -07:00
Ben Langmuir
c0d2ad0eb8 Merge pull request #126 from Trzyipolkostkicukru/implementation
Implement "textDocument/implementation" request
2019-08-08 17:47:04 -07:00
cukr
719bed2be0 Response to code review 2019-08-08 23:00:03 +02:00
Ben Langmuir
57e340488b [clangd] Set correct argv[0] for clangd to fix c++ header search
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.
2019-08-07 18:13:22 -07:00
cukr
7b6197394f Merge remote-tracking branch 'upstream/master' into implementation
# Conflicts:
#	Sources/LanguageServerProtocol/ServerCapabilities.swift
#	Sources/SourceKit/SourceKitServer.swift
#	Tests/LanguageServerProtocolJSONRPCTests/CodingTests.swift
2019-08-07 10:48:30 +02:00
Ben Langmuir
b8e79ccb4b Merge pull request #123 from literalpie/workspace-symbols
Add workspace/symbols support
2019-08-01 14:44:36 -07:00
Ben Langmuir
806e8efae7 Update for latest indexstore-db API 2019-08-01 11:53:23 -07:00
cukr
7667608eef Implement "textDocument/implementation" request 2019-07-24 14:42:10 +02:00
Ben Langmuir
3044f7394b Add infrastructure for test projects using Tibs
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.
2019-07-22 13:57:04 -07:00
Benjamin Kindle
223d11df92 Add workspace/symbols support
https://bugs.swift.org/browse/SR-10806
2019-07-20 08:36:32 -04:00
Bruno Rocha
a60c50d1db Make CodeAction wrapper types an enum 2019-06-19 22:57:40 -03:00