Commit Graph

79 Commits

Author SHA1 Message Date
Alex Hoppen
772485def3 [SourceKit] Add a request tracker that manages cancellaiton
Previously, `SwiftASTManager` and `SlowRequestSimulator` maintained their own list of in-progress cancellation tokens. With code completion cancellation coming up, there would need to be yet another place to track in-progress requests, so let’s centralize it.

While at it, also support cancelling requests before they are scheduled, eliminating the need for a `sleep` in a test case.

The current implementaiton leaks tiny amounts of memory if a request is cancelled after if finishes. I think this is fine because it is a pretty nieche case and the leaked memory is pretty small (a `std::map` entry pointing to a `std::function` + `bool`). Alternatively, we could require the client to always dispose of the cancellation token manually.
2021-11-10 22:11:02 +01:00
Alex Hoppen
7d5ee83a61 [SourceKit] Allow explicit cancellation of requests with a cancellation token
The key changes here are
- To keep track of cancellation tokens for all `ScheduledConsumer`s in `SwiftASTManager`
- Generate unique request handles for all incoming requests (`create_request_handle `), use these request handles as cancellation tokens and return them from the `sourcekitd_send_request` methods
- Implement cancellation with `sourcekitd_cancel_request` as the entry point and `SwiftASTManager::cancelASTConsumer` as the termination point

Everything else is just plumbing the cancellation token through the various abstraction layers.

rdar://83391505
2021-09-30 11:45:24 +02:00
Alex Hoppen
7a80034e35 [SourceKit] Support cancellation of requests while an AST is being built
This commit refactors the way ASTs are being built in SourceKit and how `SwiftASTConsumer`s are served by the built ASTs. `SwiftASTManager.h` should give an overview of the new design.

This commit does not change the cancellation paradigm in SourceKit (yet). That is, subsequent requests with the same `OncePerASTToken` still cancel previous requests with the same token. But while previously, we were only able to cancel requests that haven’t started an AST build yet, we can now also cancel the AST build of the to-be-cancelled requests.

With this change in place, we can start looking into explicit cancellation of requests or other cancellation paradigms.
2021-09-23 11:53:45 +02:00
Ben Langmuir
f6b251816c [test] Disable CursorInfoTest.CursorInfoMustWaitDueTokenRace
Until we figure out why this is (rarely) failing in CI, disable the
test.

rdar://55314062
2021-05-17 10:29:19 -07:00
Ben Barham
f773e980ce [SourceKit/CursorInfo] Include line and column in result
Add line/column in addition to offset so clients need not map it
themselves.
2021-05-01 09:39:15 +10:00
Alex Hoppen
294977534c [libSyntax] Remove incremental JSON transfer option
We were only keeping track of `RawSyntax` node IDs to incrementally transfer a syntax tree via JSON. However, AFAICT the incremental JSON transfer option has been superceeded by `SyntaxParseActions`, which are more efficient.

So, let’s clean up and remove the `RawSyntax` node ID and JSON incremental transfer option.

In places that still need a notion of `RawSyntax` identity (like determining the reused syntax regions), use the `RawSyntax`’s pointer instead of the manually created ID.

In `incr_transfer_round_trip.py` always use the code path that uses the `SyntaxParseActions` and remove the transitional code that was still using the incremental JSON transfer but was never called.
2021-04-07 10:01:34 +02:00
Ben Barham
3ea9bed415 [SourceKit/CursorInfo] Add constructor to call results
Cursor info for a constructor would previously give the cursor info for
the containing type only. It now also adds cursor info for the
constructor itself in a "secondary_symbols" field.

Refactor `passCursorInfoForDecl` to use a single allocator rather than
keeping track of positions in a buffer and assigning everything at the
end of the function.

Refactor the various available refactoring gathering functions to take a
SmallVectorImpl and to not copy strings where they don't need to.

Resolves rdar://75385556
2021-03-30 13:23:59 +10:00
Rintaro Ishizaki
40dc8e1bd4 [sourcekit] Response "edit" immediately if client needs nothing
If the client doesn't want anything as the response of
'editor.replacetext' requests, we don't even need parsing.

rdar://problem/74984613
2021-03-05 13:18:11 -08:00
Nathan Hawes
388052b6ab [SymbolGraph][CursorInfo] Add option to SourceKit's CursorInfo request to include the SymbolGraph JSON
Adds a new 'key.retrieve_symbol_graph' option to the request. When set to 1 it
includes the JSON for a SymbolGraph containing a single node for the symbol at
the requested position.

This also extends the SymbolGraph library with a new entry point to get a graph
for a single symbol, and to additionally support type substitution to match the
existing CursorInfo behavior (e.g. so that when invoked on `first` in
`Array<Int>().first`, the type is given as `Int?` rather than `Element?`).

Resolves rdar://problem/70551509
2020-12-12 14:38:41 +10:00
Ben Langmuir
c5b42aca11 Move FuzzyStringMatcherTest to IDE unittests 2020-08-25 13:00:35 -07:00
Ben Langmuir
6480bfaad2 [gardening] Move FuzzyStringMatcher to libIDE 2020-08-25 10:39:08 -07:00
Ben Langmuir
756ef4063c [sourcekitd] Fix potential race in semantic highlighting tests
In order to make range-shifting for semantic highlighting testable,
disable returning semantic information during an "open" request. This
has no real value anyway, since it only happens very rarely, and it
makes testing range shifting impossible to do deterministically.

rdar://problem/66386179
2020-07-31 13:51:08 -07:00
Ben Langmuir
8e352b8006 [sourcekitd] Fix range shifting "race" with a fast semantic update
If a semantic update finishes fast enough, the token snapshot may be
identical to the edit snapshot, but because of getBufferForSnapshot
consolidating edits into a new buffer, we were not detecting that case
properly, and it could cause an assertion failure (or potentially
incorrect range shifting in a release build). This would have reproduced
very rarely in practice, but I can reproduce it by putting `sleep(2)`
calls right before we read the semantic info in open and edit requests.

Incidentally, fix sourcekit-test and unit tests for the (rare) case
where an open or edit already has updated semantic info.
2020-07-22 17:50:08 -07:00
Ben Langmuir
9c08fc0ddd [test] Fix annotation test to have same behaviour before and after update
The goal of the test is to test the behaviour when the edit is
range-shifted, but in the (rare) case where the document update happens
before the edit finishes, we need the ranges to be the same. In
particular, using separate statements ensures that the tokens not
touched by the edit are not affected by the edit.

Re-enable the test disabled on ASan, since this seems to be the
underlying issue.

rdar://65934938
2020-07-22 17:39:26 -07:00
Ben Langmuir
53b87714d7 [asan] Temporarily disable EditTest.AnnotationsRangeShiftingAfterEditReplaceEnd
This started failing in one CI job that has asan, but it's unclear
whether there is a sanitizer issue or if it's a timing issue, etc.
Disabling while we investigate the root cause.

rdar://65934938
2020-07-22 11:09:31 -07:00
Ben Langmuir
01b5cf7c6f [sourcekitd] Fix annotation range-shifting after edit
When performing an insertion (replacement length = 0) inside an existing
annotation, we were forming a closed range instead of a half-open range,
causing us to shift the effected token instead of throwing it out. There
were also no tests for this functionality, so add a bunch of annotations
tests.

One area thing that is not tested is what if there have been multiple
edits since the tokens were created. This is difficult to engineer,
because right now making an edit immediately removes the semantic tokens
and returns them. It could happen if the AST build takes longer than the
edits, but there is no way to guarantee that in the current API.

rdar://65748892
2020-07-20 16:56:49 -07:00
Owen Voorhees
70140a0170 Merge pull request #31521 from owenv/sourcekit-find-edu-notes
[SourceKit] Discover diagnostic documentation relative to sourcekitd
2020-05-06 19:54:02 -05:00
Owen Voorhees
eb8aeba2b8 [SourceKit] Discover diagnostic documentation relative to sourcekitd 2020-05-04 11:59:48 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Michael Forster
32d2b1486c Fix build breaks for master-next against llvm.org.
StringRef conversion to std::string needs to be explicit now.
2020-03-13 19:08:22 +01:00
Daniel Rodríguez Troitiño
a1a891e47a [windows] Use the temporal directory for root of VFS tests.
The VFS tests were using Unix absolute paths, which does not play well
when Windows see them as relative to the current drive letter.

By using the temporal directory, both Windows and Unix can use the same
paths and avoid the problem.

Additionally, a couple of inputs have to be transformed into the native
path format, because sourcekitd-test compares the inputs as strings, and
they need to match exactly. So the source file and the name of the VFS
entries are transformed into native using the helper from LLVM support.
2019-11-15 15:20:01 -08:00
Ben Langmuir
582269b751 Fix the sourcekit unittests 2019-07-16 10:19:25 -07:00
Ben Langmuir
f6e7978779 Fix compilation of sourcekit unit tests after VFS changes 2019-07-16 10:19:24 -07:00
Ben Langmuir
e5e4d805c3 [test] Fix race in EditTest.DiagsAfterReopen
We weren't accounting for the possibility that the AST would build
faster than we could return editorOpen. While that is very unlikely, we
hit a CI failure at least once.

rdar://52211324
2019-06-26 16:33:44 -07:00
David Goldman
cb14b8b535 RequestResult class and Pass*InfoForDecl fixes 2019-05-28 04:35:16 -04:00
David Goldman
176cd6cce1 Fail requests when an error occurs
Previously, requests would fail silently by returning an empty struct
in the response.

With this change, responses will properly report fail with the internal
error.
2019-05-28 04:24:25 -04:00
Joe Groff
7d54810b92 Revert "[SourceKit] Fail requests when an error occurs" 2019-05-22 15:18:28 -07:00
David Goldman
00d771ca6b RequestResult class and Pass*InfoForDecl fixes 2019-05-03 15:17:40 -04:00
David Goldman
10ecea6269 [SourceKit] Fail requests when an error occurs
Previously, requests would fail silently by returning an empty struct
in the response.

With this change, responses will properly report fail with the internal
error.
2019-05-03 11:01:21 -04:00
Saleem Abdulrasool
159b4ef6c8 Merge pull request #22058 from compnerd/chrono
SourceKit: use `std::chrono` in unittests
2019-01-23 16:47:02 -08:00
Saleem Abdulrasool
2bc1ec5650 SourceKit: use std::chrono in unittests
Rather than using the `usleep` function which is both deprecated and
non-portable (does not exist on Windows), prefer using the C++11 chrono library
for the sleep.  This also allows us to use the UDL to simplify the code rather
than relying on the comments.  NFCI
2019-01-23 14:00:51 -08:00
Saleem Abdulrasool
2b45eb9575 SourceKit: simplify and modernise CMake for tests
Use `target_compile_definitions` to fix the quoting.  This is particularly
important when running under a non-sh shell (e.g. Windows) where the quoting
rules are different.
2019-01-23 09:52:41 -08:00
Ben Langmuir
a87444c78a [sourcekit] Disable DiagsAfterCloseAndReopen test (again)
Looks like it still fails very rarely in CI. Disable while I
investigate.

rdar://45994090
2018-11-13 08:37:56 -08:00
Ben Langmuir
8c948880b2 Double the timeout in EditTest
These tests are occassionaly timing out in CI. I have been unable to
reproduce this even with TSan and varying the pauses between operations.
On the other hand, I can get this test to run slowly if the machine is
heavily loaded, so double the timeout to see if it resolves the CI
issues.

rdar://44842835
2018-10-01 13:36:02 -07:00
Ben Langmuir
c6776db83d [sourcekit] Use a shared_ptr for the NotificationCenter
When the server shuts down we may still have outstanding async work that
can attempt to trigger a notification, so use a shared_ptr + weak_ptr
instead of unique_ptr + unowned references.
2018-09-25 14:57:32 -07:00
Ben Langmuir
c248bba171 [sourcekit] Re-enable DiagsAfterCloseAndReopen test
After fixing the lock inversion from the previous commit, this test
appears to be clean under TSan on Linux and macOS, so re-enable it and
hope for the best.
2018-09-24 12:01:44 -07:00
Ben Langmuir
c2fadc3271 [unittest] Fix some unintentional behaviour in EditingTest
I haven't found any cases where this changes the visible behaviour of
the test, but having the file remain open across invocations was
certainly unexpected and affects how the first part of the test works at
runtime.
2018-09-13 14:11:15 -07:00
Alex Hoppen
750e7e8f73 [SourceKit] Remove option to regions reused as part of incremental parsing 2018-08-20 11:15:50 -07:00
Alex Hoppen
b75dd68180 [SourceKit] Pass reused node IDs by reference 2018-08-02 14:33:55 -07:00
Alex Hoppen
99b1ce7ab7 Merge pull request #18416 from ahoppen/editorconsumer-return-values
[SourceKit] Change return value of functions in EditorConsumer to void
2018-08-02 09:53:44 -07:00
Rintaro Ishizaki
335e913bed Merge pull request #18439 from rintaro/sourcekit-editoffset-rdar34206143
[SourceKit] Defensive guard for invalid offset and length in edit request
2018-08-02 10:19:33 +09:00
Alex Hoppen
9bbe441160 [SourceKit] Change return value of functions in EditorConsumer to void
We were always returning true from those functions in  SKEditorConsumer
and false in the test consumers. On the client side we would then ignore
the return value. So it's clearer to have the functions not return
anything.
2018-08-01 15:17:13 -07:00
Alex Hoppen
293e8bd0bd Merge pull request #18373 from ahoppen/sourcekit-improvements
[SourceKit] Serialize the syntax tree in the EditorConsumer
2018-08-01 09:30:11 -07:00
Rintaro Ishizaki
930d4342cd [SourceKit] Defensive guard for invalid offset and length in edit request
Otherwise, hits assertion, or crashes in no-assertion build.

Added 'EditableTextBuffer::getSize()' for getting size after previous updates
without actually applying them.

rdar://problem/34206143
2018-08-01 20:02:15 +09:00
Alex Hoppen
b48f740712 [SourceKit] Serialize the syntax tree in the EditorConsumer
This will allow us to switch to a more efficient serialization format in
the future.
2018-07-31 13:51:16 -07:00
Ben Langmuir
1b19607763 [unittest] Disable EditingTest.DiagsAfterCloseAndReopen while I investigate
This test has been  failing non-deterministically and I haven't yet
tracked down the cause. Disabling for now.

rdar://42483323
2018-07-31 08:33:23 -07:00
Alex Hoppen
749a13a6fe [libSyntax] Remove the C++ SyntaxClassifier
The recommended way forward is to use the SyntaxClassifier on the Swift
side.

By removing the C++ SyntaxClassifier, we can also eliminate the
-force-libsyntax-based-processing option that was used to bootstrap
incremental parsing and would generate the syntax map from a syntax
tree.
2018-07-30 09:26:18 -07:00
Alex Hoppen
57196f8902 [libSyntax] Enable serialization of syntax trees for incremental transfer 2018-07-23 12:32:49 -07:00
Alex Hoppen
1df1dc71b7 Merge pull request #18016 from ahoppen/003-incremental-syntax-coloring
[libSyntax] Incremental syntax colouring
2018-07-18 17:08:02 -07:00
Alex Hoppen
7a750bf024 [libSyntax] Allow syntax cache reuse info to be passed back via SourceKit 2018-07-18 13:35:10 -07:00