47 Commits

Author SHA1 Message Date
Ben Barham
381684a389 [SourceKit] Remove diagnostics path calculation
The diagnostic group documentation now point to the swift.org URL rather
than the toolchain path, so it no longer needs to be passed all the way
through sourcekitd.

Resolves rdar://151500502.
2025-05-16 17:58:16 -07:00
Alex Hoppen
b6c94aecc3 [SourceKit] Add mechanism to load plugins for request handling into SourceKit
This allows us to load plugins into the sourcekitd service to handle requests (currently only used for code completion). This allows us to implement parts of sourcekitd in Swift and outside of the compiler repository, making it easier to iterated on them because the compiler doesn’t need to be rebuilt.
2025-01-03 15:24:52 +01:00
Jim M. R. Teichgräber
f2e57d8c76 [SourceKit] Add optional declarations array to interface gen request (#75802)
Introduces the new DeclarationsArrayBuilder and adds it to the
EditorConsumer. Declaration info always includes a kind, offset, and
length, and includes a USR where applicable.
As the USR is already available for editor.open.interface type requests,
this doesn't compute any new information, it just exposes more of what's
there already.
2024-08-30 18:04:12 -07:00
Hamish Knight
de9806e2fa [SourceKit] Introduce key for cancelling on close
Defaults to `true`.
2024-04-30 21:13:20 +01:00
Hamish Knight
a85be58c22 [test] Switch couple of SourceKit tests to INITIALIZE_LLVM
And move this into the constructor since it only
needs doing once.
2024-04-30 12:00:27 +01:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
62b021030f [SourceKit] Include generated macro buffers in diagnostic responses
Introduce a new key `generated_buffers`, which
stores an array of generated buffers. These
include the buffer text, as well as its original
location and any parent buffers.

While here, also fix rdar://107281079 such that
only apply the filename fallback logic to the
pretty-printed Decl case. We ought to remove this
fallback once the editor can handle it though.

rdar://107281079
rdar://107952288
2023-05-02 16:21:44 +01:00
Robert Widmann
9ff5d88847 Remove SourceKit Support for the libSyntax Tree 2022-11-16 14:52:28 -08:00
Josh Soref
436484c8c8 Gardening: Fix spelling mistakes in */SourceKit
* about
* and
* answering
* because
* before
* cancellation
* clear
* comment
* complete
* corresponding
* cursor
* custom
* dependencies
* doesn't
* expression
* extension
* immediately
* implementation
* implicit
* innovation
* intentionally
* occasionally
* oldest
* parameter
* property
* response
* reuseastcontext
* snapshot
* sourcekit_swift_runtime_link_flags
* synchronously
* target
* that
* unlabeled
* usefulness
* work

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-21 02:03:25 -04:00
Alex Hoppen
1525f6b982 [SourceKit] Pass the main swift executable path when constructing a compiler invocation
#58786 (rdar://93030932) was failing because the `swift-frontend` invocations passed a `swiftExecutablePath` to `Invocation.parseArgs`. This caused the `ClangImporter` instance to point to a `clang` binary next to the `swift-frontend` executable while SourceKit used PATH to find `clang`. The clang executable next to `swift-frontend` doesn’t actually exist because `clang` lives in `llvm-linux-aarch64/bin` and `swift-frontend` lives in `swift-linux-aarch64/bin`.
So some checks for a minimum clang verison failed for the normal build (because the executable doesn’t actually exists) while they pass during the SourceKit build (which used `clang` from `PATH`). This in turn caused the `outline-atomics` to be enabled to the SourceKit clang compiler arguments but not the clang compiler arguments for a normal build and thus resulted in two separate module cache directories (which includes the enabled features in the module directory hash).

To fix this issue, also set the swift executable path for compiler invocations created from SourceKit.

Fixes #58786 (rdar://93030932)
2022-05-13 09:05:38 +02: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
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
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
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
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
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
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
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
7a750bf024 [libSyntax] Allow syntax cache reuse info to be passed back via SourceKit 2018-07-18 13:35:10 -07:00
Alex Hoppen
c8a3957ba2 [SourceKit] Add option to force the SyntaxMap to be generated via the syntax tree 2018-07-13 17:57:00 -07:00
Alex Hoppen
6e12a634a1 [SourceKit] Move all options into a common options struct
With more options coming for incremental syntax parsing, the list of
arguments will grow way to large and unhandy, so just extract them into
one common struct.
2018-06-28 20:26:05 -07:00
Ben Langmuir
68b829a065 [sourcekit] Do not dequeue AST consumers expecting newer snapshots
When adding to the AST consumer queue, keep track of the snapshots
expected and only run such AST consumers when a new enough AST is built.
Progress is ensured because we always run the AST consumer that
triggered the build.

This prevents cases where enqueuing a consumer during an AST build has
different behaviour than enqueuing it after the AST has finished.

rdar://40340631
2018-06-18 13:01:23 -07:00
Xi Ge
4c172037e8 [libSyntax][SourceKit] Integrating libSyntax representation of a source file with several SourceKitd syntax requests (#14000)
The enhanced SourceKitd requests are EditorOpen and EdtiorReplaceText. In these two requests, the clients can specify a flag "key. enablesyntaxtree = 1" to get a serialize libSyntax tree with the response.

To help this integration, we added a function in SyntaxParsingContext to explicitly finalize the creation of a SourceFileSyntax to incorporate the fact that SourceKit needs the tree before its destroying the parser instance.

To test this integration, we diff the syntax tree serialized from the frontend action and the tree serialized from a SourceKitd response. They should be identical.
2018-01-17 21:13:22 -08:00
Marcelo Fabri
2bf49b0151 [SourceKit] Add range for attributes in a structure (SR-5587) (#11750) 2017-09-20 15:54:42 -07:00
Ben Langmuir
4eebeea1f9 [SourceKit] Attempt to make EditingTest deterministic
The previous code actually had a "semantic" error as well as a parse
error, so depending on the timing we could get 2 diagnosticsl

rdar://problem/34373697
2017-09-12 09:57:03 -07:00
Marcelo Fabri
d16cce3a94 [SourceKit] Add documentation range in structure (SR-2487) (#11264) 2017-08-02 13:39:49 -07:00
Argyrios Kyrtzidis
0cfc56ec04 [SourceKit] If diagnostics are 'stale' for a particular snapshot then ignore them and only return the syntactic parser diagnostics (#10388)
This makes sure that diagnostics returned for a particular state of source buffer are consistent and accurate.
rdar://32769873
2017-06-20 12:26:32 -07:00