This allows us use an OptionSet parameter for
the request (as currently we can't directly use it
as a parameter due to not having an == definition
for it). It also allows us to regain default
arguments for the source loc and flag parameters.
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase. In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
If we see `MyModule.Type`, the parser thinks this is a metatype type.
Escape the name `Type` so the parser can recognize it's a type name.
Fixes [SR-11422](https://bugs.swift.org/browse/SR-11422) rdar://55094784
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
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).
The backing property for 'foo' is now '_foo', and the projected value '$foo'.
This updates Indexing to report occurrences of foo within both $foo and
_foo occurrences (rather than just $foo - the old _foo).
FindRelatedIdents was similarlar updated, so it reports 'foo' ranges in both
_foo and $foo.
CursorInfo now reports the USR, documentation, and location of foo when invoked
occurrences of $foo or _foo, but now leaves the name, type, and annotated
declaration of _foo/$foo as is. Having the same USR ensures rename invoked on
any of them will still rename via foo. Reporting foo's documentation comment
instead is just to present something more useful to the user.
This is the final piece to get rename and findRelatedIdents to include all foo
and $foo occurrences, for example, in the set of occurrences to be renamed or
shown, regardless of whether they were initiated on a foo or $foo.
Resolves rdar://problem/51695783.
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.
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.
We weren't picking up all occurrences of 'x' in the cases like the below:
case .first(let x), .second(let x):
print("foo \(x)")
fallthrough
case .third(let x):
print("bar \(x)")
We would previously only return occurrences within the case statement the query
was made in (ignoring fallthroughs) and for cases with multiple patterns (as in
the first case above) we would only return the occurrence in the first pattern.
The client usually cares about a subset of all expressions. A way to differentiate
them is by the protocols these expressions' types conform to. This patch allows
the request to add a list of protocol USRs so that the response only includes those
interested expressions that conform to any of the input protocols.
We also add a field to the response for each expression type to indicate the
conforming protocols names that were originally in the input list.
When an empty list of protocol USRs are given, we report all expressions' types
in the file like the old behavior.
rdar://35199889
This custom buffer encapsulates the memory layout details of the response
for the expression type request. From the client side, each expression type
is represented as a tuple of {expr_offset, expr_length, printed_type}.
rdar://35199889
This request collects the types of all expressions in a source file after type checking.
To fulfill this task, the client must provide the path to the Swift source file under
type checking and the necessary compiler arguments to help resolve all dependencies.
Request:
{
<key.request>: (UID) <source.request.expression.type>,
<key.sourcefile>: (string) // Absolute path to the file.
<key.compilerargs>: [string*] // Array of zero or more strings for the compiler arguments,
// e.g ["-sdk", "/path/to/sdk"]. If key.sourcefile is provided,
// these must include the path to that file.
}
Response:
{
<key.printedtypebuffer>: (string) // A text buffer where all expression types are printed to.
<key.expression_type_list>: (array) [expr-type-info*] // A list of expression and type
}
expr-type-info ::=
{
<key.expression_offset>: (int64) // Offset of an expression in the source file
<key.expression_length>: (int64) // Length of an expression in the source file
<key.type_offset>: (int64) // Offset of the printed type of the expression in the printed type buffer
<key.type_length>: (int64) // Length of the printed type of the expression in the printed type buffer
}
rdar:://35199889
Addressing review feedback: this avoids calling shared_from_this() from
outside the implementation. Note: it is not possible to use private
inheritance of enable_shared_from_this to prevent this issue in general,
because enabled_shared_from_this relies on the shared_ptr constructor
being able to detect that the type has this inheritance, which means it
must be public.
If an imported Objective-C method had no owning clang module, passCursorInfoForDecl() would call clang::Module::getFullModuleName() on a null instance. The current implementation of this method happens to terminate its loop immediately and return an empty string, but it’s best not to depend on this. Fixes a UBSan error in SourceKit/Mixed/cursor_mixed_header.swift.
The right way is findBufferContainingLoc. getBufferIdentifierForLoc is
both slower and wrong in the presence of #sourceLocation.
I couldn't come up with a test for the change in IDE/Utils.cpp because
refactoring still seems to be broken around #sourceLocation. I'll file
bugs for that.
- getAsDeclOrDeclExtensionContext -> getAsDecl
This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.
- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)
These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point. The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.
- getAsProtocolExtensionContext -> getExtendedProtocolDecl
Like the above, this didn't return the ExtensionDecl; it returned its
extended type.
This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).
This surfaces more remaining uses of getInOutObjectType() directly.
Having this be a single buffer hardcoded in the SourceManager and set
by all clients is silly. SourceFiles with the 'Main' kind are allowed
to have hashbang lines (`#!`), other files are not. And anyone
manually setting up a Lexer can decide for themselves.
No intended behavioral change.