Commit Graph

1357 Commits

Author SHA1 Message Date
Robert Widmann
6d60d01420 [NFC] Remove the Legacy Semantic Queries Bit
Clients that wish to avoid semantic requests should decline to register
those requests.
2020-03-19 11:04:12 -07:00
Nathan Hawes
fd82d87db0 Merge pull request #30402 from nathawes/cross-import-code-completion
[IDE/CodeCompletion] Add code completion support for cross import overlays.
2020-03-18 18:16:03 -07:00
Nathan Hawes
63636100be [IDE/CodeCompletion] Add code completion support for cross import overlays.
If a cross-import overlay shadows another module and has a name starting with
'_', don't present that overlay in places where module name completions are
offered and present symbols comining from that module as if they came from
the shadowed module instead.

Resolves rdar://problem/59445688
2020-03-18 12:02:20 -07:00
Dmitri Gribenko
841eeb05b0 Merge pull request #30403 from MForster/forster/string-fixes
Cherry-pick StringRef->std::string conversion fixes into `master`
2020-03-17 12:09:36 +01:00
Robert Widmann
70b6bbcb13 Remove swift::createTypeChecker
Replace it with the "legacy semantic queries" bit. The remaining client
of this bit is SourceKit, which appears to require this bit be set
conditionally so certain semantic property wrapper requests return
a sentinel value.

We should migrate these requests to a syntactic interface as soon as
possible.

rdar://60516325
2020-03-16 19:20:22 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Rintaro Ishizaki
9225cfce3d [CodeCompletion] Type annotation for call argument completions 2020-03-12 17:46:25 -07:00
Rintaro Ishizaki
f8147f72d9 [CodeCompletion] Call argument label with value placeholder
When a completion happens at a call argument position, insert
'label: <#T##TypeName#>' instead of just 'label: '.

rdar://problem/60379654
2020-03-12 11:48:15 -07:00
Rintaro Ishizaki
fbc79d2f47 [CodeCompletion] Support SE-0253 callAsFunction()
- In member completions, when 'callAsFunction' decls are found, suggest
  call patterns
- In call pattern completions, fallback to search 'callAsFunction' if
  the base type is not a function type

rdar://problem/59792682
2020-03-11 16:27:27 -07:00
Rintaro Ishizaki
12fd864543 Merge pull request #30136 from rintaro/ide-completion-rdar59285399
[CodeCompletion] Primarily use getPossibleCallees() for calling signature completion
2020-03-03 11:10:53 -08:00
Rintaro Ishizaki
78d0f6aa4a [CodeCompletion] Primarily use getPossibleCallees() for call signature completion
instead of the pre-typechecked type and the referenced decl in the AST
so that we can suggests all overloads even if it happen to be
typechecked to a method. For example

    struct MyType {
      func foo() {}
      func foo(_ int: Int) {}
      func foo(name: String, value: String) {}
    }
    func test(val: MyType) {
      value.foo(#^COMPLETE^#)
    }

In this case, the call is typechecked to 'MyType.foo(_:)', but we want
to suggest all overloads.

rdar://problem/59285399
2020-02-28 16:44:03 -08:00
Rintaro Ishizaki
fc28f909b8 [CodeCompletion] Tweak canBeUsedAsRequirementFirstType() 2020-02-26 10:58:01 -08:00
Rintaro Ishizaki
0dd0092e9e [CodeCompletion] Only suggest generic params in where for non-protocol
nominal types
2020-02-26 09:57:18 -08:00
Rintaro Ishizaki
ea6886114a [CodeCompletion] Generalize generic requirement completion
Align completion logics for all 'where' clauses.
2020-02-26 09:57:18 -08:00
Rintaro Ishizaki
e5cdbb7fab [CodeCompletion] completeGenericRequirement to use the decl context
instead of the parsed type name for the extension.
Preparation for generalize this to other 'where' clause (e.g. functions)
2020-02-26 09:57:17 -08:00
Rintaro Ishizaki
5cf88a15cf [CodeCompletion] Rename GenericParam kind to GenericRequiremnt
NFC
2020-02-26 09:57:17 -08:00
Rintaro Ishizaki
ea947987e9 [CodeCompletion] Associated types after where on a protocol extesnion
rdar://problem/58580482
2020-02-26 09:57:17 -08:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00
Rintaro Ishizaki
bfa385c0b7 [CodeCompletion] Update for SE-0249 KeyPath as functions
If the context type is a function type that receives one argument, infer
the key path expressions root type from the context.

rdar://problem/59302416
2020-02-13 13:11:36 -08:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Rintaro Ishizaki
cc8d4965f8 [CodeCompletion] Ensure cached results have 'unknown' type relation 2020-02-05 17:05:23 -08:00
Rintaro Ishizaki
566a84d641 [CodeCompletion] Handle new kinds in type relation printing 2020-02-05 15:35:01 -08:00
Rintaro Ishizaki
e9c51a0755 [CodeCompletion] Report 'Unrelated' type relation for keywords 2020-02-05 15:09:14 -08:00
Rintaro Ishizaki
c31bfaeeed [CodeCompletion] Introduce 'Unknown' type relation
Now

* NotApplicable: The result is not relevant for type relation (e.g.
  keywords, and overloads)
* Unknown: the relation was not calculated (e.g. cached results), or the
  context type is unknown.
* Invalid: The result type is invalid for this context (i.e. 'Void' for
  non-'Void' context)
* Unrelated: The result type has no relation to the context type
* Convertible: The result type is convertible to the context type
* Identical: The result type is identical to the context type
2020-02-05 14:23:59 -08:00
Rintaro Ishizaki
17abedf1ef [CodeCompletion] Introduce 'NotApplicable' type relation
For keywords, and overrides.
2020-02-05 14:23:59 -08:00
Rintaro Ishizaki
71aeffdf17 [CodeCompletion] Calculate type relation for EnumElementDecl 2020-02-03 17:20:50 -08:00
David Zarzycki
ed15a9e939 [QoI] Fix -Wmisleading-indentation warnings 2020-01-19 13:31:16 -05:00
Rintaro Ishizaki
ac7ba746f6 [CodeCompletion] Stop printing underlined keyword in override completion
e.g. `__consuming`. Now, conformance completion for
Sequence.makeIterator() is:

  struct MySequence: Sequence {
    func makeIterator() -> some IteratorProtocol {
      <#code#>
    }
  }

rdar://problem/56963545
2020-01-10 13:03:42 -08:00
Rintaro Ishizaki
b9f1e58b37 [CodeCompletion] Use GenericSignature methods to get associatedtype reqs 2020-01-08 21:35:49 -08:00
Rintaro Ishizaki
1dd6fe5688 [CodeCompletion] Stop suggesting opaque result type for generic function
in override completion. As per SE-0244:

> Associated type inference can only infer an opaque result type for a
> non-generic requirement, because the opaque type is parameterized by
> the function's own generic arguments
2020-01-08 17:37:42 -08:00
Rintaro Ishizaki
e388c4a381 [CodeCompletion] Get associatedtype constraints from ProtocolDecl::getRequirementSignature()
instead of AssociatedTypeDecl::getInherited() when checking if the
return type should be suggested as "opaque result type" in override
completion.

AssociatedTypeDecl::getInherited() is not serialized. So if the protocol
is declared in a module, it was never suggested as 'some' result.

rdar://problem/57245073
2020-01-08 17:37:42 -08:00
Varun Gandhi
022314a640 Merge pull request #28643 from kitaisreal/using-located-instead-of-pair
[Compiler]: Using Located<T> instead of std::pair<SourceLoc, T>
2020-01-06 14:22:29 -08:00
Rintaro Ishizaki
ab0475178a [CodeCompletion] Eliminate CodeCompletionCallbacks::completeExpr()
Well, this does nothing. It just set the parser position twice and calls
the consumer's 'handleResults()' without any reason.
It seems it was intended to be a "fallback" completion, but it was never
implemented properly. So just remove it for now.

rdar://problem/58102910
2019-12-20 09:39:02 -08:00
Kita, Maksim
ea6a2dc094 SR-11889: Fixed code review issues
1. Updated Located field names with Pascal Case
2. Updated Located constuctor
3. Formatted lines with more than 80 symbols
2019-12-20 17:18:59 +03:00
Kita, Maksim
b7cb3b67bf SR-11889: Using Located<T> instead of std::pair<SourceLoc, T> 2019-12-20 17:18:58 +03:00
Slava Pestov
3604b21f2a AST: Simplify Expr::getReferencedDecl() 2019-12-19 23:51:53 -05:00
Slava Pestov
3149d6d62c IDE: Preparations for Sema building curry thunks 2019-12-19 23:51:53 -05:00
Rintaro Ishizaki
62078c79dd [ASTPrinter/CodeCompletion] Stop printing base type when possible
rdar://problem/57033931
2019-12-17 16:26:37 -08:00
Brent Royal-Gordon
1df792ae9f [NFC] Convert TypeRepr to use DeclName(Loc)?
Replaces `ComponentIdentTypeRepr::getIdentifier()` and `getIdLoc()` with `getNameRef()` and `getNameLoc()`, which use `DeclName` and `DeclNameRef` respectively.
2019-12-11 00:45:08 -08:00
Robert Widmann
a9ce2babd2 Merge pull request #28624 from CodaFi/heres-looking-up-you-kid
[NFC] Pull Semantic Member Synthesis into TypeChecker's Lookup Entrypoints
2019-12-10 10:40:31 -08:00
Robert Widmann
00407857d0 [NFC] Swap CodeCompletion's lookupQualified for TypeChecker's
This call relied on semantic member synthesis, so now it has to go through TypeChecker::lookupQualified.
2019-12-06 14:18:31 -08:00
Brent Royal-Gordon
63ec1cf5af Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
2019-12-04 16:35:13 -08:00
Rintaro Ishizaki
ad4b9df3c0 [CodeCompletion] Suggest the property name in its didSet clause
Previously, property names are hidden in the whole range of the
declarations. Now, it's only hidden in its own initializer range.

rdar://problem/49697202
2019-12-03 18:12:47 -08:00
Rintaro Ishizaki
97b16ce5e3 [CodeCompletion] Remove unsound check in override completion
In override completion, we didn't use to emit 'class var' with the initial
expression. However, having initial expression does not have any bearing
on whether the declaration is overridable or not.
2019-11-12 17:40:36 +09:00
Rintaro Ishizaki
f6a76f51a0 Utilize forEachTypeWitness()/forEachValueWitness() 2019-11-12 13:30:55 +09:00
Rintaro Ishizaki
2564a6e494 [CodeCompletion] Avoid typechecking all toplevel decls in the current file
- Use `performParseAndResolveImportsOnly()` to invoke the frontend
- Do `bindExtensions()` in `ide::typeCheckContextUntil()`
- Typecheck preceding `TopLevelCodeDecl`s only if the compleiton is in
  a `TopLevelCodeDecl`
- Other related tweaks

rdar://problem/56636747
2019-11-12 12:57:18 +09:00
Robert Widmann
2b08d1b834 [NFC] ASTContext::getLazyResolver -> ASTContext::getLegacyGlobalTypeChecker 2019-11-05 14:44:41 -08:00
Nathan Hawes
aeea756718 Merge pull request #27935 from nathawes/module-qualified-type-completion
[code-completion] Suggest module names, and handle module name bases for member completion in type position
2019-11-01 13:51:17 -07:00
Nathan Hawes
eabb561994 [code-completion] Give Modules a SemanticContextKind of None
This seems more correct than OtherModule, and means they're treated as
low-priority results for the session-based completion APIs. With default
options that means won't be shown in global completion results but will be
once there's some matching filter text. It also sorts them below any symbols
that actually come from other modules, which is desirable, since most symbols
don't need to be module qualified.

The SemanticContextKind change doesn't seem to affect Xcode's handling of the
results.
2019-11-01 11:11:52 -07:00
Nathan Hawes
14107acfe6 Merge pull request #27983 from nathawes/complete-self-dot-init-in-struct-initializer
[code-completion] Suggest self.init in value type constructors
2019-10-31 12:34:36 -07:00