Commit Graph

193 Commits

Author SHA1 Message Date
Nathan Hawes
51bace649b [IDE][SourceKit/DocSupport] Add members of underscored protocol extensions in extensions of conforming types.
We would previously hide the protocol, its extensions and members, but the '_'
prefix really just means the protocol itself isn't intended for clients, rather
than its members.

This also adds support for 'fully_annotated_decl' entries in doc-info for
extensions to be consistent with every other decl, and removes the
'fully_annotated_generic_signature' entry we supplied as a fallback.

Also fixes several bugs with the synthesized extensions mechanism:
- The type sustitutions applied to the extension's requirements were computed
  using the extension itself as the decl context rather than the extension's
  nominal. The meant the extension's requirements themselves were assumed to
  hold when determining the substitutions, so equality constraints were always
  met. Because of this extension members were incorrectly merged with the base
  nominal or its extensions despite having additional constraints.
- Types within the requirements weren't being transformed when printed (e.g.
  'Self.Element' was printed rather than 'T') both in the interface output and
  in the requirements list. We were also incorrectly printing requirements
  that were already satisfied once the base type was subsituted in.
- If both the protocol extension and 'enabling' extension of the base nominal
  that added the protocol conformance had conditional requirements, we were
  only printing the protocol extension's requirements in the synthesized
  extension.
- The USR and annotated decl output embedded in the 'key.doc.full_as_xml'
  string for synthesized members were printed to match their original context, rather than
  the synthesized one.

Resolves rdar://problem/57121937
2020-06-02 15:38:34 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Ben Langmuir
8303289567 [sourcekit] Fix use-after-free of request string
The CursorInfoConsumer outlives the request call, so we need to copy the
input filename string. This fixes a use-after-free elucidated by asan.
2020-04-15 15:28:35 -07:00
Nathan Hawes
bce68fa4e5 [IDE][Refactoring] Handle 'callAsFunction' specially in syntactic rename.
This change makes us treat it exactly as we do 'init'. We don't allow renaming the base name,
and don't fail if the basename doesn't match for calls.

Also:
  - explicit init calls/references like `MyType.init(42)` are now reported with
    'init' as a keywordBase range, rather than nothing.
  - cursor info no longer reports rename as available on init/callAsFunction
    calls without arguments, as there's nothing to rename in that case.
  - Improved detection of when a referenced function is a call (rather than
    reference) across syntactic rename, cursor-info, and indexing.

Resolves rdar://problem/60340429
2020-04-12 17:14:15 -07:00
Nathan Hawes
9f6f76308e Add method to ModuleDecl to lazily compute the underlying module for cross-import overlays
Also update code completion, indexing, interface generation and doc info to use it.
2020-04-03 16:04:32 -07:00
Nathan Hawes
8b03b05f1d [Index] Add index support for cross import overlays.
Resolves rdar://problem/59445445
2020-03-25 10:04:41 -07:00
Nathan Hawes
a7e1cb3925 [SourceKit] Update cursor info to report symbols from cross-import overlays as coming from the underylying module.
Also refactor some of the interface generation cross-import support code to be
shared.
2020-03-20 21:49:51 -07:00
Puyan Lotfi
8132596e83 Handling strict conversion criteria for StringRef to std::string from TOT llvm. 2020-03-13 19:08:22 +01:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Argyrios Kyrtzidis
11e79dc665 [SourceKit] Remove a globally shared variable from inside a method that doesn't seem to get used anymore 2020-02-19 14:42:23 -08:00
John Fairhurst
0e8f4d4f32 [SourceKit] Fix cursorinfo.modulename with sourceinfo 2020-02-07 12:24:16 +00:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Hamish Knight
2853615880 Add type to package inputs to UnqualifiedLookupRequest
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.
2019-11-15 16:35:14 -08:00
Hamish Knight
3aa7158d6c Switch UnqualifiedLookup callers over to UnqualifiedLookupRequest 2019-11-15 14:25:42 -08:00
Hamish Knight
ed77b86c24 getInterfaceType() always returns a type 2019-11-12 07:50:29 -08:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
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.
2019-09-30 14:04:36 -07:00
Robert Widmann
1233cdf596 Update SourceKit for getInterfaceType() changes 2019-09-23 17:24:18 -07:00
Harlan Haskins
2893d96927 [ModuleInterfaces] Escape Type and Protocol when module-qualifying
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
2019-09-09 17:20:27 -07:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
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.
2019-08-19 23:00:57 -04:00
marcrasi
a98bfd69e0 Merge pull request #26168 from marcrasi/vfs-attempt-2
[apple/swift] [sourcekit] Add an optional virtual file system per request and/or open document
2019-07-17 15:24:57 -07:00
Xi Ge
8f1a9b4789 IDE+Evaluator: refactor range info resolver to an IDE evaluator request. NFC 2019-07-17 12:20:09 -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
Marc Rasi
840f4b90d9 some cleanup 2019-07-16 10:19:24 -07:00
Marc Rasi
7e15723805 add custom fs to editor.open and cursorinfo 2019-07-16 10:19:24 -07:00
Xi Ge
8915cf8c4d Sourcekit/Evaluator: refactor cursor-info resolver to using the evaluator model. NFC
This change adds a new IDE request ID zone and refactors the cursor-info resolver
to use the request evaluator model.
2019-07-16 09:55:16 -07:00
Nathan Hawes
a0052c9c06 Merge pull request #25758 from nathawes/property-wrapper-rename
[IDE][Index] Property wrapper rename support
2019-06-28 16:25:45 -07:00
Xi Ge
ff32d5899a SourceKit/ExpressionType: allow users to canonicalize collected expression types
The default response of the expression type request doesn't canonicalize expression
types. This patch adds a flag to allow users to canonicalize them.
2019-06-28 11:36:44 -07:00
Nathan Hawes
e08a6c1994 [IDE][Index][test] Update sourcekit/indexing support for latest property wrapper changes
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.
2019-06-28 10:15:00 -07:00
Nathan Hawes
91e2e35a77 [IDE] Update CursorInfo and FindRelatedIdents to treat property wrapper backing properties as the underlying property
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.
2019-06-26 18:37:47 -07:00
Rintaro Ishizaki
db2c11787b [AST] Inherit doc-brief comment from protocol, superclass, and requirement
rdar://problem/38422822
2019-06-20 10:04:05 -07:00
David Goldman
cb14b8b535 RequestResult class and Pass*InfoForDecl fixes 2019-05-28 04:35:16 -04:00
David Goldman
1b1756cb55 Add InternalDiagnostic to CursorInfoData and NameTranslatingInfo 2019-05-28 04:24:25 -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
a3a4d2d22b Add InternalDiagnostic to CursorInfoData and NameTranslatingInfo 2019-05-03 11:01:22 -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
Nathan Hawes
0b9aac05ea [sourcekitd][RelatedIdents] Fix handling of var decls in fallthrough case statements
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.
2019-03-20 09:18:57 -07:00
Xi Ge
35b17d7a6c SourceKit: allow expression type request to specify a list of protocol USRs for filtering
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
2019-03-13 14:07:33 -07:00
Xi Ge
cca6fea65a Merge pull request #22835 from nkcsgexi/custom-buffer
sourcekitd: define a new custom buffer for expression type response.
2019-02-25 16:29:14 -08:00
Xi Ge
3fc52305a3 sourcekitd: define a new custom buffer for expression type response.
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
2019-02-22 16:58:10 -08:00
Slava Pestov
3dc5ae36a6 SourceKit: Use Demangle::getTypeDeclForUSR() to implement 'CursorInfo for USR' request
Fixes <rdar://problem/47819208>.
2019-02-22 16:13:03 -05:00
Xi Ge
74e86a8f35 SourceKit: Add a new request to collect expression types in a source file.
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
2019-02-20 10:49:39 -08:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Xi Ge
d620dfae5e Sourcekit/DocSupport: include fully annotated generic signatures for extension decls. rdar://40906297 2018-12-04 14:29:28 -08:00
Ben Langmuir
b04ffcca86 [sourcekit] Change getASTManager() to return shared_ptr
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.
2018-09-25 16:42:41 -07:00