Commit Graph

134 Commits

Author SHA1 Message Date
Alex Hoppen
22f67e89a6 [SourceKit] Explicitly specify frontend action type when creating compiler invocation
Explicitly specify the frontend action to make sure we aren’t loading thes stdlib if the performed action is syntactic only.
2021-12-13 15:32:08 +01:00
Alex Hoppen
177ab6e8e7 [SourceKit] Support cancellation of code completion like requests
Essentially, just wire up cancellation tokens and cancellation flags for `CompletionInstance` and make sure to return `CancellableResult::cancelled()` when cancellation is detected.

rdar://83391488
2021-12-02 13:05:03 +01:00
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
70e3c99edd [SourceKit] Remove performCompletionLikeOperation
All users of `performCodeCompletionLikeOperation` have been migrated to dedicated methods on `CompletionInstance`.
2021-10-28 11:10:30 +02:00
Alex Hoppen
ab257bbda3 [SourceKit] Move invocation of code completion second pass for TypeContextInfo from SoruceKit to CompletionInstance
The invocation of the code completion second pass should be implementation detail of `CompletionInstance`. Create a method on `CompletionInstance` that correctly invokes the second pass and just reutnrs the type context info results to the caller.
2021-10-28 11:10:30 +02:00
Alex Hoppen
2fcb24e716 [CodeCompletion] Refactor how code completion results are returned to support cancellation
This refactors a bunch of code-completion methods around `performOperation` to return their results via a callback only instead of the current mixed approach  of indicating failure via a return value, returning an error string as an inout parameter and success results via a callback. The new guarantee should be that the callback is always called exactly once on control flow graph.

Other than a support for passing the (currently unused) cancelled state through the different instance, there should be no functionality change.
2021-10-28 11:10:30 +02: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
Nathan Hawes
e1a4c5f846 [SourceKit][CursorInfo] Add a field for the source language the symbol was originally defined in
Resolves rdar://75446903
2021-03-18 18:49:25 +10:00
Rintaro Ishizaki
27dc2cf406 [SourceKit] Add a request kind to notify dependencies are updated 2021-02-05 18:41:26 -08:00
Rintaro Ishizaki
77b4f75608 [SourceKit] Reorgantize code completion options
* Abolish 'reuseastcontext' per-request option
* Add 'MaxASTContextReuseCount' global configuration
2020-09-03 19:30:05 -07:00
Nathan Hawes
9d4ed5f39c Manually merge remote-tracking branch 'upstream/master' into manually-merge-master-to-master-rebranch 2020-07-20 16:09:55 -07:00
Suyash Srijan
58a84ea4c1 [NFC] Cleanup some code to use 'swift::getParameterList(ValueDecl)' to fetch parameter lists (#32979) 2020-07-20 19:50:37 +01:00
swift_jenkins
2b1bf9ffd3 Merge remote-tracking branch 'origin/master' into master-next 2020-06-15 14:39:00 -07:00
Bruno Rocha
f000639cce Improve tests and generate the rest of the output 2020-05-29 18:59:25 +02:00
Bruno Rocha
2a48e19ff0 [SourceKit] Add Effective Scope to Index 2020-05-29 18:59:25 +02:00
Arnold Schwaighofer
a195733336 [master-next] Fix compile error ParsedRawSyntaxNode and SwiftLangSupport 2020-05-07 10:43:02 -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
Rintaro Ishizaki
05a87e86c4 [CodeCompletion] Give up fast-completion if dependent files are modified
Check if dependencies are modified since the last checking.
Dependencies:

 - Other source files in the current module
 - Dependent files collected by the dependency tracker

When:

 - If the last dependency check was over N (defaults to 5) seconds ago

Invalidate if:

 - The dependency file is missing
 - The modification time of the dependecy is greater than the last check
 - If the modification time is zero, compare the content using the file
   system from the previous completion and the current completion

rdar://problem/62336432
2020-05-04 13:02:09 -07:00
Owen Voorhees
eb8aeba2b8 [SourceKit] Discover diagnostic documentation relative to sourcekitd 2020-05-04 11:59:48 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Rintaro Ishizaki
4870d1c017 [SourceKit] Don't use diagnostics to indicate fast-completion
Add 'key.reusingastcontext: 1' to the response instead.
Using diagnostics can be a noise to indexing log clients.

rdar://problem/61367416
2020-04-07 16:26:00 -07:00
Michael Forster
345a9147ec Explicit SmallString->std::string conversion.
This is only needed temporarily until commit d7049213 from upstream
LLVM hits the swift/master branch.
2020-03-13 19:16:49 +01:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00
Brent Royal-Gordon
0c478b6be6 Revert "Merge pull request #28665 from CodaFi/the-phantom-menace"
This reverts commit 43a3ab7e35, reversing
changes made to 4f39d9c749.

# Conflicts:
#	include/swift/AST/Attr.def
#	lib/AST/Attr.cpp
#	lib/Serialization/Deserialization.cpp
#	lib/Serialization/ModuleFormat.h
#	lib/Serialization/Serialization.cpp
2020-01-15 15:28:42 -08:00
swift_jenkins
29b0fb925e Merge remote-tracking branch 'origin/master' into master-next 2019-12-19 14:40:17 -08:00
Rintaro Ishizaki
eebcbf6564 [SourceKit] Pass 'EnableASTCaching' flag as an argument
so that it is associated with a specific completion.
2019-12-19 12:20:20 -08:00
Rintaro Ishizaki
044477e7a3 [SourceKit/CodeCompletion] Use callback function to run the second pass
To controls the lifetime of CompilerInstance within CompletionIntance.

- Prevent from using the same CompilerInstance from multiple completion
  requests
- Separate the stacktrace between "fast" and "normal" completions
- Further code consolidation between various completion-like requests
2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
62c44126b6 [SourceKit] Reuse compiler instance between multiple completion
- Introduce ide::CompletionInstance to manage CompilerInstance
- `CompletionInstance` vends the cached CompilerInstance when:
-- The compiler arguments (i.e. CompilerInvocation) has has not changed
-- The primary file is the same
-- The completion happens inside function bodies in both previous and
   current completion
-- The interface hash of the primary file has not changed
- Otherwise, it vends a fresh CompilerInstance and cache it for the next
  completion

rdar://problem/20787086
2019-12-18 21:52:20 -08:00
swift_jenkins
3140acc993 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 21:20:05 -08:00
Robert Widmann
06d27f08fd Define @_implicitly_synthesizes_nested_requirement
State the previously unstated nested type requirement that CodingKeys adds to the witness requirements of a given type. The goal is to make this member cheap to synthesize, and independent of the expensive protocol conformance checks required to append it to the member list.

Further, this makes a clean conceptual separation between what I'm calling "nested type requirements" and actual type and value requirements.

With luck, we'll never have to use this attribute anywhere else.
2019-12-10 16:28:50 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Nathan Hawes
b9d5672ca1 [SourceKit] Add a global-configuration request to control SourceKit's behavior around .swiftsourceinfo files
SwiftSourceInfo files provide source location information for decls coming from
loaded modules. For most IDE use cases it either has an undesirable impact on
performance with no benefit (code completion), results in stale locations being
used instead of more up-to-date indexer locations (cursor info), or has no
observable effect (live diagnostics, which are filtered to just those with a
location in the primary file).

For non-IDE clients of SourceKit though, cursor info providing declaration
locations for symbols from other modules is useful, so add a global
configuration option (and a new request to set it) to control whether
.swiftsourceinfo files are loaded or not based on use case (they are loaded by
default).
2019-12-03 13:15:20 -08:00
swift-ci
5fc88311d0 Merge remote-tracking branch 'origin/master' into master-next 2019-11-13 10:09:52 -08:00
Gwen Mittertreiner
e587c3255c Convert NT paths to DOSPath when resolving Symlinks
GetFinalPathNameByHandleW returns NTPaths (\\?\ Paths) which is an issue
as they don't match the paths stored in the internal dictionaries which
are DOS paths.
2019-11-12 19:57:11 -08:00
swift-ci
e4cbf824ae Merge remote-tracking branch 'origin/master' into master-next 2019-10-11 15:10:04 -07:00
Robert Widmann
060cbb293f [NFC] Downgrade The TypeLoc in VarDecl to a TypeRepr
TypeCheckPattern used to splat the interface type into this, and
different parts of the compiler would check one or the other.   There is
now one source of truth: The interface type.  The type repr is now just
a signal that the user has written an explicit type annotation on
a parameter.  For variables, we will eventually be able to just grab
this information from the parent pattern.
2019-10-11 11:15:51 -07:00
swift-ci
84f192ddce Merge remote-tracking branch 'origin/master' into master-next 2019-10-10 13:50:08 -07:00
Xi Ge
dd33540231 AST: rename printDeclUSRForModuleDoc to printDeclUSR. NFC 2019-10-09 15:29:52 -07:00
swift-ci
b503ced230 Merge remote-tracking branch 'origin/master' into master-next 2019-08-22 16:29:14 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Nathan Hawes
f23c24fe03 [SourceKit] Return a default UID in getUIDForSyntaxNodeKind()
Assert 0 and return a default kind, rather than calling unreachable
as a defensive fix for rdar://problem/53343735.
2019-07-23 11:14:14 -07:00
Ben Langmuir
6e2a7e5a3a Allow passing key.sourcetext to provide in-memory-vfs contents
For testing, passing `-vfs-files=source=@target` with an '@' on the
target file will pass it as source text.
2019-07-16 10:19:24 -07:00
Ben Langmuir
8784a7b96d Migrate to OptionsDictionary to pass arguments to FileSystemProvider 2019-07-16 10:19:24 -07:00
Ben Langmuir
0c2b6b63c7 Rename testvfs to in-memory-vfs 2019-07-16 10:19:24 -07:00
Ben Langmuir
205371c886 Move storage for VFS into editor document
The invocation options are not an appropriate place to put this state,
since it can change between requests. This moves it to the editor
document, allowing us to change the specific VFS instance without
causing a rebuild (unless the contents/timestamps for a dependency
change).
2019-07-16 10:19:24 -07:00
Ben Langmuir
78a7d95f07 Factor getting the filesystem into a method with error handling 2019-07-16 10:19:24 -07:00
Ben Langmuir
6884d3a1fd Move VFS to SwiftLangSupport layer 2019-07-16 10:19:24 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -07:00