Commit Graph

285 Commits

Author SHA1 Message Date
Rintaro Ishizaki
7ef93b2a67 [Basic] Move copyCString to Basic/StringExtras.
Also, use StringRef.copy() instead of copyString().
2022-02-18 11:34:45 -08:00
Ben Barham
bf0bcfa8e1 [IDE] Only consider synthesized extensions when in the same module
Only declarations in the same module as synthesized extension's target
are placed within a synthesized extension. We should thus not add
"::SYNTHESIZED::" to the USR if the given declaration is in a different
and.

As an example, `Foundation` adds a method `components(separatedBy:)` to
`String` through an extension on `StringProtocol`. But since it is
within `Foundation` and not `Swift` it will *not* be in a synthesized
extension of `String` or `StringProtocol`. So it should not have
"::SYNTHESIZED::" added and should also not being in the `String` group.

Resolves rdar://71355632.
2021-12-24 09:17:41 +10:00
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
Ben Barham
fd7d59daa6 [CursorInfo] Add a synthesized field
Mark implicit declarations with a `synthesized` field, since while we
still want them to have a cursor info result (eg. for their USR to find
possible overrides), it's likely that clients will want to treat them
differently to results that have a real location in source.

An alternative could be to remove the location entirely, but:
  - the module name would also have to be removed to prevent wasted
    lookups in the generated interface
  - having the location could still be useful as the location that
    caused the synthesized declaration (though at the moment only
    synthesized initializers have a location)

Resolves rdar://84990655
2021-11-05 15:52:10 +10:00
Ben Barham
8128450690 [CursorInfo] Always add module name to response
To simplify clients, have the cursorinfo result be consistent whether
requesting a symbol within the current module or not, ie. do not skip
adding the module name.

Resolves rdar://77003299
2021-10-22 12:35:53 +10:00
Alex Hoppen
2f19d1847f [SourceKit] Add a dedicated request to retrieve the diagnostics of a file
Currently, SourceKit always implicitly sends diagnostics to the client after every edit. This doesn’t match our new cancellation story because diagnostics retrieval is no request and thus can’t be cancelled.

Instead, diagnostics retrieval should be a standalone request, which returns a cancellation token like every other request and which can thus also be cancelled as such.

The indented transition path here is to change all open and edit requests to be syntactic only. When diagnostics are needed, the new diagnostics request should be used.

rdar://83391522
2021-10-13 21:28:18 +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
Rintaro Ishizaki
7e7b2c3557 [CodeCompletion] Annotate override completions
* "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
2021-09-02 12:12:26 -07:00
Ben Barham
c7620fa979 [Refactorings] Add cursor refactorings for the start of the range
When a range is a single expression/statement/decl or part of
expression, also return cursor based refactorings for the start of the
range.

This is a stop gap until the available refactorings are properly fixed
to be more lenient in general - the current fix is a little odd as eg.
if all of `foo.bar()` is selected, rename will be returned as an
available refactoring for `foo`. Still an improvement over completely
missing cursor based refactorings, however.

Resolves rdar://82060063
2021-08-18 14:04:10 +10:00
Rintaro Ishizaki
6e69a44c3d [ASTPrinter] Intorduce 'IntroducerKeyword' name kind
For more fine grained annoations. For now, it's handled as the same as
'Keyword' name kind.

Fix an issue where 'extension' wasn't marked as "keyword".

Also, move 'static' priting out of 'SkipIntroducerKeywords' guard
because 'static' is not an declaration introducer.
2021-07-29 12:50:24 -07:00
Fredrik Wieczerkowski
7a73c99510 Migrate VariableTypeCollector to SourceRange
- Add SourceRange::contains and SourceRange::overlaps
- Use SourceRange in VariableTypeCollector
2021-06-21 19:33:52 +02:00
Fredrik Wieczerkowski
2703d08877 Add CollectVariableType request to SourceKit
- Add VariableTypeCollector
  This new SourceEntityWalker collects types from variable declarations.
- Add SwiftLangSupport::collectVariableTypes
- Implement CollectVariableType request
- Provide information about explicit types in CollectVarType
- Fix HasExplicitType in VariableTypeArray
- Fix typo
- Implement ranged CollectVariableTypes requests
- Use offset/length params for CollectVariableType in sourcekitd-test
- Address a bunch of PR suggestions
- Remove CanonicalType from VariableTypeCollector
  This turned out not to be needed (for now).
- Improve doc comment on VariableTypeCollector::getTypeOffsets
- Remove unused CanonicalTy variable
- Remove out-of-date comment
- Run clang-format on the CollectVariableType implementation
- Fix some minor style issues
- Use emplace_back while collecting variable infos
- Pass CollectVariableType range to VariableTypeCollector
- Use capitalized variable names in VariableTypeArray
  ...as recommended by the LLVM coding standards
- Use PrintOptions for type printing in VariableTypeCollector
- Return void for collectVariableType
  This seems to be cleaner stylistically.
- Avoid visiting subranges of invalid range in VariableTypeCollector
- Use std::string for type buffer in VariableTypeCollectorASTConsumer
- Use plural for PrintedType in VariableTypeArray
- Remove unused fields in VariableTypeArrayBuilder
- Add suggested doc comments to VariableTypeArray
- Remove unused VariableTypeInfo.TypeLength
- Fix typo of ostream in VariableTypeCollectorASTConsumer
- Fix typo
- Document Offset and Length semantics in collectVariableTypes
2021-06-21 19:28:29 +02:00
QuietMisdreavus
40b084e5c0 Merge pull request #37640 from apple/QuietMisdreavus/spi-symbols
add symbol-graph flag to include SPI symbols
2021-06-04 11:34:48 -06:00
Argyrios Kyrtzidis
53264a64d9 Merge pull request #37547 from bnbarham/line-col-crash
[SourceKit] Map line and column using the latest snapshot
2021-05-21 08:53:06 -07:00
Ben Barham
0f21991f02 [SourceKit] Map line and column using the latest snapshot
During a cursor info request, the resolved offset was mapped to line and
column using the buffer inside `SwiftDocumentSyntaxInfo`.

However, prior to 54683ca607,
`editorReplaceText` was not updating the syntax info. This meant that
snapshots would be more up to date than the buffer in the syntax info,
allowing for the possibility of an invalid offset.

While 54683ca607 would also fix this,
snapshots actually have a `getLineAndColumn` anyway. Use that instead of
grabbing the buffer from syntax info.

Resolves rdar://78161348.
2021-05-21 15:42:33 +10:00
Victoria Mitchell
d281722589 add symbol-graph flag to include SPI symbols
rdar://70794131
2021-05-20 15:10:49 -06:00
Alex Hoppen
44f8e195ef [SourceKit] Recover if compiler arguments have errors
If the compiler arguments have errors in them (e.g. because a file with the same name is used twice), we can often still fulfill SourceKit requests because the compiler argument errors are only relevant for later stages of the compilation process.

Instead of bailing out early, do a best effor retrieving the compiler arguments that are valid and ignoring the errors.

Fixes rdar://77618144
2021-05-19 22:31:15 +02:00
Ben Barham
73d9f5b843 [SourceKit] Remove OptimizeForIDE global configuration
Have SourceKit return locations for symbols outside of the current
module as well. Callsites of location and comment information should
explicitly disable retrieving serialized information where performance
is a concern.

Resolves rdar://75582627
2021-05-01 11:37:23 +10:00
Ben Barham
f773e980ce [SourceKit/CursorInfo] Include line and column in result
Add line/column in addition to offset so clients need not map it
themselves.
2021-05-01 09:39:15 +10:00
Ben Barham
828d12764c [SourceKit/CursorInfo] Add locations for external files to result
.swiftsourceinfo files contain the serialized location for declarations.
Use this when outputting locations in cursor info so that clients need
not perform an extra index lookup for external modules.
2021-05-01 09:38:58 +10:00
Ben Barham
9ca7663f23 [Gardening] Move functions only used in SourceKit out of lib/IDE
NFC - `getLocationInfo` and `getLocationInfoForClangNode` are both moved
and formatted with clang-format.
2021-04-21 13:22:37 +10:00
QuietMisdreavus
170dcd88bc Merge pull request #36863 from apple/QuietMisdreavus/docs-inheritance
[SymbolGraph] Add information about "inherited docs" for synthesized symbols
2021-04-19 19:40:38 -06:00
Ben Barham
299df93a7f Merge pull request #36807 from bnbarham/use-original-locs
Replace uses of presumed locations where they do not make sense
2021-04-13 08:48:23 +10:00
Victoria Mitchell
f4154d6019 add flag to skip docs on synthesized symbols 2021-04-11 17:40:37 -05:00
Ben Barham
20f45ec284 Replace uses of presumed locations where they do not make sense
Various uses of `getPresumedLineAndColumnForLoc` were likely added when
that function was the very misleading name `getLineAndColumn`. Change
these to use `getLineAndColumnForBuffer` instead where appropriate, ie.
we want the underlying file rather than the location to display to the
user.

There were also some cases where the buffer identifier had been swapped
to use the display name instead, under the assumption that the presumed
location was needed. Updated those as well.

SingleRawComment: Lines are only used when merging comments, where the
original location is fine to use.

Index: Doesn't store the file set in #sourceLocation, so using the
presumed line would end up pointing to a location that makes no sense.

Editor functionality: Formatting and refactoring are on the current
file. Using the presumed location would result in incorrect
replacements.
2021-04-10 09:49:31 +10:00
Victoria Mitchell
ba2b92be4e call it PrintMessages instead 2021-04-07 08:58:20 -06:00
Victoria Mitchell
0c5955b7fa silence symbolgraph-extract output without -v flag
rdar://72630103
2021-04-06 16:40:38 -06:00
Nathan Hawes
08250f058a [SourceKit/CursorInfo] Report the set of decls referenced in the symbol graph's "declarationFragments" field.
Resolves rdar://75809521
2021-04-03 09:42:54 +10:00
Ben Barham
3ea9bed415 [SourceKit/CursorInfo] Add constructor to call results
Cursor info for a constructor would previously give the cursor info for
the containing type only. It now also adds cursor info for the
constructor itself in a "secondary_symbols" field.

Refactor `passCursorInfoForDecl` to use a single allocator rather than
keeping track of positions in a buffer and assigning everything at the
end of the function.

Refactor the various available refactoring gathering functions to take a
SmallVectorImpl and to not copy strings where they don't need to.

Resolves rdar://75385556
2021-03-30 13:23:59 +10:00
Ben Barham
19f23130d0 [SourceKit/CursorInfo] Mark dynamic calls
Adds two new fields to the cursor info response:
  1. is_dynamic: whether a call is dynamic
  2. receivers: receivers of the call (USRs)

Users of the CursorInfo request can use "is_dynamic" to decide whether
to lookup overrides or not, and then the "receivers" as the starting
point of the lookup.

Resolves rdar://75385900
2021-03-20 13:57:01 +10: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
Nathan Hawes
bba702940c [CusorInfo] Fix ASAN heap-use-after-free failure when reporting parent contexts.
Resolves rdar://problem/74289832
2021-02-16 18:57:46 +10:00
Argyrios Kyrtzidis
9ef86bd110 Merge pull request #35873 from nathawes/cursor-info-parent-usrs
[SourceKit][SymbolGraph] Add a 'parent_contexts' field the CursorInfo response
2021-02-11 21:24:01 -08:00
Nathan Hawes
6d940951ca [SourceKit][SymbolGraph] Add a 'ParentContexts' field the CursorInfo response
When the SymbolGraph json is requested via (key.retrieve_symbol_graph: 1) this adds
a new field in the response that lists all the parent contexts of the symbol under
the cursor with their symbol graph kind and name, and their USR:

key.parent_contexts: [
    {
      key.kind: "swift.struct",
      key.name: "Parent",
      key.usr: "s:27cursor_symbol_graph_parents6ParentV"
    },
    ...
  ]
}

Resolves rdar://problem/73904365
2021-02-10 16:35:57 +10:00
shreyaa-sharmaa
2b11d7acc7 Task SR-14138 Replace std::transform with llvm::transform 2021-02-04 12:58:33 +05:30
Varun Gandhi
f9570b2d34 [NFC] Pass full convention printing boolean for types etc.
When -experimental-print-full-convention is set, we should be printing
the full convention in diagnostics, doc comments etc.
2021-01-25 18:47:39 -08:00
Nathan Hawes
388052b6ab [SymbolGraph][CursorInfo] Add option to SourceKit's CursorInfo request to include the SymbolGraph JSON
Adds a new 'key.retrieve_symbol_graph' option to the request. When set to 1 it
includes the JSON for a SymbolGraph containing a single node for the symbol at
the requested position.

This also extends the SymbolGraph library with a new entry point to get a graph
for a single symbol, and to additionally support type substitution to match the
existing CursorInfo behavior (e.g. so that when invoked on `first` in
`Array<Int>().first`, the type is given as `Int?` rather than `Element?`).

Resolves rdar://problem/70551509
2020-12-12 14:38:41 +10:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Slava Pestov
658d4bf813 SourceKit: Refactor walkRelatedDecls() to not use unqualified lookup
This function used to perform an unqualified lookup without a source
location, to either find top-level members or members of a type.

Since this form of unqualified lookup is no longer supported, let's
instead explicitly call lookupInModule() or lookupQualified(),
depending on whether we're looking inside a type or not.
2020-09-06 15:52:19 -04:00
Nathan Hawes
1c58abf6a3 Merge pull request #32575 from nathawes/fix-no-quickhelp-for-shorthand-arguments
[SourceKit/CursorInfo] Still print implicit decls in cursorinfo to handle compiler synthesized decls
2020-06-29 11:35:02 -07:00
Saleem Abdulrasool
2a200b2089 SourceKit: silence as -Wmisleading-indent warning (NFCI)
Undent the code that was mis-indended leading to a warning with clang.
2020-06-28 15:06:59 -07:00
Nathan Hawes
a1f0155525 [SourceKit/CursorInfo] Still print implicit decls in cursorinfo to handle compiler synthesized decls
We weren't printing memberwise inits, shorthand arguments (e.g. $0, $1), and
other implicit decls, so cursor info would give empty annotated decl and fully
annotated decl fields for them.

Resolves rdar://problem/58929991
2020-06-26 11:12:10 -07:00
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