Essentially, just wire up cancellation tokens and cancellation flags for `CompletionInstance` and make sure to return `CancellableResult::cancelled()` when cancellation is detected.
rdar://83391488
We had some situations left that neither returned an error, nor called the callback with results in `performOperation`. Return an error in these and adjust the tests to correctly match the error.
* "description" for override completion is now annotatable
* "description" doesn't include attributes and decl introducer, but it
includes generic paramters, effects specifiers, result type clause,
and generic where clauses
* "name" now only include the name and the parameter names
* "sourcetext" should be the same
rdar://63835352
`CodeCompletioString::getName()` was used only as the sorting keys in
`CodeCompletionContext::sortCompletionResults()` which is effectively
deprecated. There's no reason to check them in `swift-ide-test`. Instead,
check `printCodeCompletionResultFilterName()` that is actually used for
filtering.
The patch introduces a new setting instead of changing existing settings
because the generated interfaces in the IDE have slightly different
requirements; the extended type there is unconditionally not printed
qualified (even if it is ambiguous). This is likely because the
ambiguity heuristic is very weak; it doesn't even do name lookup.
Simplifying that logic would be nice, but then we'd need to update
a bunch of IDE/print* tests and end up with more more visual clutter
in the IDE.
Introducing the new setting means we can change the behavior for
swiftinterface files without affecting the behavior for IDE interfaces.
Fixes rdar://79093752.
The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.
We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
'InvalidAsyncContext' depends on the decl context. That may case
"sticky" not-recommended If it's cached for a non-async context.
To workaround this, stop checking 'InvalidAsyncContext' when collecting
completion items for caching. Also consistently use the 'SourceFile' as
the decl context to avoid decl context specific behavior.
rdar://78315441
When matching an argument to a parameter list, if there is no matching
parameter, the argument list is not applicable to the parameters. In
such case, code completion should not suggest argument labels of the
function.
rdar://77867723
For example, non-Darwin platforms probably don't want
`#colorLiteral(red:green:blue":alpha:)` and `#imageLiteral(named:)`.
Add an completion option to include them, which is "on" by default.
rdar://75620636
Previously, completing inside non single expression body might cause a
crash if you had done any completion with single expression in the same
body.
e.g.
func test() {
test(#^HERE^#)
}
after that:
func test() {
test(arg)
if #^HERE^#
}
That was because the `hasSingleExpressionBody` wasn't cleared when
reusing the function for subsequent completions.
This patch just clears it whenever a new parsed body is set to a
function.
rdar://75358153
struct Foo {
init(_ arg1: String, arg2: Int) {}
init(label: Int) {}
}
func test(strVal: String) {
_ = Foo(<HERE>)
}
In this case, 'strVal' was prioritized because it can use as an argument
for 'init(_:arg2:)'. However, argument labels are almost always
preferable, and if the user actually want 'strVal', they can input a few
characters to get it at the top. So we should always prioritize call
argument patterns.
rdar://77188260
The diagnosticc engine is keeping track of state which might modify parsing/typechecking behaviour. In the added test case the `fatalErrorOccurred` flag was during the first completion. The flag was still `true` for the second completion, causing parsing/typechecking to behave slightly differently. Because of this, the ExprRewriter failed when applying a constraint system solution, not properly cleaning up its `ExprStack`.
This PR tackles both issues:
1) Reset the `hadError` flags in the diagnostics engine
2) Clean up the `ExprRewriter`’s `ExprStack` when rewriting a target fails.
Either of these changes fixes the crash in the test case but I think both could manifest through different code paths in different scenarios.
Fixes rdar://76051976 [SR-14430]
Consolidate ThrowsKeyword, RethrowsKeyword, and AsyncKeyword to
EffectsSpecifierKeyword.
Abolish 'key.throwsoffset' and 'key.throwslength' as they aren't used.
These tests relied on timing between completion runs in order to check
that fast completion was working properly for completions in VFS files.
That is, they would assume that two runs happening one after another
without a sleep inbetween would always run fast completion.
However, that's not necessarily the case and there have been cases where
a dependency check happens despite its interval being fairly long
(multi-second).
This change emulates the same behaviour by changing the interval
between 0/100, which should prevent any timing issues.
Resolves rdar://72144331
A previous change updated the checkdep tests to move the sleep before
copying over files. This fixed cases where the modification time would
be the same second as the dependency check. Unfortunately this
introduced a slightly different form of flakiness - if the sleep went
too long, the completion that was meant to re-use the AST would see that
it's time to check dependencies and thus skip the fast completion path.
One fix for that would be to add a smaller sleep before, a longer sleep
after, and increase the dependency check time. That increases the
runtime of the tests even further though, so instead just update the
timestamps manually to be in the past/future in order to invoke the path
we want to test. This also allows a 0 dependency check time (ie. always
check), which makes the tests even faster.
Resolves rdar://71861446
Also, continue trying opening files even if any of primary files are
missing so that the caller can know all files failed to open.
rdar://problem/33757793
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
Calculate and set the type relation in each result building logic which
knows the actual result type.
CodeCompletionResultBuilder couldn't know the actual result type. From
the declaration alone, it cannot know the correct result type because it
doesn't know how the declaration is used (e.g. calling? referencing by
compound name? curried?)
The tests were matching the previous implementation's output, which sometimes produced 'unknown' and sometimes 'unrelated' in cases where there was no expected type from the context.
This was not needed. The list of depenencies should not be changed
during fast-completion sessions.
This was also harmful because it calls stat(2) for all the dependency
files.
rdar://problem/67773257
'SM.getCodeCompletionBufferID()' returns the buffer ID of the previous
code completion. 'CI.getCodeCompletionFile()->getBufferID()' always
returns the original source buffer ID of the current file in the main
module. The latter is needed for excluding buffer ID for dependency checking.
rdar://problem/66301353
`PreCheckFunctionBuilderRequest` applies `PreCheckExpression` to the
expressions inside the function body. Previously it used to receive only
`AnyFunctionRef` (`FunctionDecl` or `ClosureExpr`) as the parameter.
However, when fast-completion kicks-in, it replaces the body of the
function, then tries to call `PreCheckFunctionBuilderRequest` again, with
the same function decl as before. It used to return cached "Success"
result, but it didn't actually apply `PreCheckExpression`. So any
`UnresolvedDeclRefExpr` remained unresolved.
In this patch, make `PreCheckFunctionBuilderRequest` receive "body" of the
function as well, so it doesn't return the cached result for the *previous*
body.
rdar://problem/65692922
Return type in the closure signature is often redundant when expanding
placeholders, because the type of the clossures are usually inferred
from the context (i.e. calling function), users don't need to write the
return type explicitly.
They are not only redundant, but also sometimes harmful when the return
type is a generic parameter or its requirement. Actually, there is no
correct spelling in such cases.
So omit the return type and the parentheses around the parameter clause.
rdar://problem/63607976
Out of all operating systems ever supported by Swift, only Ubuntu 14.04
had libstdc++ 4.8, and Swift has sunset support for Ubuntu 14.04 for a
while now.