Commit Graph

861 Commits

Author SHA1 Message Date
Ben Langmuir
f8a3afb7bb Fix lifetime of type context in result builder
There usually won't be a lot of expected types, so just use a
SmallVector and copy it instead of trying to get tricky with the
lifetime.
2019-03-19 07:04:39 -07:00
Ben Langmuir
b817cbb9bc [code-completion] Add type context for single-expression closures
When completing in the only expression of closure, use the return type
of the closure as the type context for the code-completion. However,
since code-completion may be on an incomplete input, we only use the
return type to improve the quality of the result, not to mark it
invalid, since (a) we may add another statement afterwards, or (b) if
the context type is Void it doesn't need to match the value.
2019-03-18 17:04:33 -07:00
Rintaro Ishizaki
71aeea93f5 [CodeCompletion] Fix an assertion failure
If the type has unbound generic parameter, we cannot substitute types
for member decls.

rdar://problem/48896424
2019-03-14 12:22:19 -07:00
Rintaro Ishizaki
97d7111fa6 [CodeCompletion] Clean-up result build for method/function all
Don't emit duplicate results for implicitly curried instance methods
with defaulted parameters.
2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
489a53864c [CodeCompletion] Display mapped type for subscript result 2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
c99af83901 [CodeCompletion] Consolidate parameter list processing funcitons
There were 2 functions to output argument list. Consolidate them and
consistently use it from every call like production (i.e. function call,
constructor call, enum with associated values, subscript)
2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
82b5f2a195 [CodeCompletion] Find parsed expression from typechecked decl context
Instead of re-typechecking parsed expression, find typechecked
expression that corresponds to the parsed expression from the
typechecked decl context, because the sub expressions of the parsed
expression can be weirdly mutated/replaced by decl context typechecking.

rdar://problem/48141174
2019-02-28 18:39:46 -08:00
Rintaro Ishizaki
6872f6c0cb Merge pull request #19742 from AnthonyLatsis/class-var-override-compl
[CodeCompletion][Parser] Completions for overridable static members
2019-02-26 09:52:37 -08:00
Rintaro Ishizaki
dc8508435b [CodeCompletion] Show bound generic types for enum elements
We weren't displaying bound generic types for enum elements. It's
inconsistent with functions and initializiers.
2019-02-20 11:31:04 -08:00
Rintaro Ishizaki
25f9b8843c [CodeCompletion] Show the enum type for enum element with assoc values
enum MyEnum {
    case null
    case str(String)
}

When completing elements for enum like this, the former shows `MyEnum`,
but the latter shows `(String) -> MyEnum`. This is inconsistent with
function call pattern which only shows the result type.

rdar://problem/48220244
2019-02-20 10:29:59 -08:00
fischertony
ae415b2a4b When followed by an 'override' or CC token inside a class, treat 'class' as a modifier rather than an introducer. 2019-02-16 16:02:22 +03:00
fischertony
ecfce56110 Don't exclude @autoclosure from the attribute list when printing override completions 2019-02-16 16:02:22 +03:00
fischertony
86d9d7a6b5 Fix override completions when a valid introducer is present but the override keyword is not. 2019-02-16 16:02:22 +03:00
fischertony
bb9482bab5 [CodeCompletion][Parser] Completions for overridable static members 2019-02-16 16:02:06 +03:00
Rintaro Ishizaki
0bebba840e Merge pull request #22539 from rintaro/ide-codecompletion-dottype-rdar22072865
[CodeCompletion] Implement .Type completion in expression context
2019-02-12 16:03:29 -08:00
Rintaro Ishizaki
ec85151a80 [CodeCompletion] Add '.Protocol' completion for protocol in type context 2019-02-12 10:58:30 -08:00
Rintaro Ishizaki
01b8fbc1bf [CodeCompletion] Implement .Type completion in expression context
rdar://problem/22072865
2019-02-12 10:40:08 -08:00
Rintaro Ishizaki
1d845d6e3f [IDE/SourceKit] New SourceKit request for filtered method list
`source.request.conformingmethods` is a new SourceKit request which
receives a source position and a list of protocol namses, returns a list
of methods whose return type conforms to the requested protocols.

rdar://problem/44699573
2019-02-08 12:56:58 -08:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Slava Pestov
e3c5eb7d3a IDE: Remove unused function 2019-01-14 14:57:03 -05:00
Rintaro Ishizaki
b446d6b051 Merge pull request #21377 from rintaro/ide-contextinfo
[SourceKit][IDE] New SourceKit request to retrieve context type information
2019-01-15 01:54:16 +09:00
Rintaro Ishizaki
cc1d5c1147 [IDE] Move typeCheckContext() to ExprContextAnalysis.cpp
NFC
2019-01-10 17:52:37 +09:00
Rintaro Ishizaki
2fbd3fe682 [IDE] Move ExprContextAnalyser to its own file
NFC
2019-01-10 17:52:37 +09:00
Rintaro Ishizaki
d17bb78a0b [AST] Add shouldHideFromEditor() method
This replaces shouldHideDeclFromCompletionResults() in IDE.
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
867c28ea74 [IDE] Rename collectArgumentExpectation() to analyzeApplyExpr()
Removed unnecessary arguments.
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
e3387c6fdb [IDE] ExprContextAnalyzer::Analyze() doesn't need to return success 2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
758ba5e5d0 [IDE] Decouple ExprContextAnalyzer and ExprContextInfo
Just refactoring.
ExprContextInfo automatically construct analyzer and analyze().
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
5c64324740 [IDE] Refactor ExprContextAnalyzer. NFC
We don't need to keep ExprFinder beyond analysis.
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
2fb542537f [IDE] Rename CodeCompletionTypeContextAnalyzer to ExprContextAnalyzer
NFC
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
b033f4880c [CodeCompletion] Only analyze inner most context
Now that this passes all test cases we currently have. Stop analyzing
outer contexts because it may emit invalid context type.
2019-01-10 17:52:36 +09:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Rintaro Ishizaki
4b39c20ace [CodeCompletion] Unresolved member completion at type parameter context
We need to map 'GenericTypeParamType' to 'ArchetypeType' to lookup its
members.

rdar://problem/46657585
2019-01-09 14:44:29 +09:00
Slava Pestov
dffa857b2a Merge pull request #21704 from slavapestov/remove-restate-filtering-consumer
Fix a crash by removing the RestateFilteringConsumer
2019-01-08 08:03:59 -05:00
Slava Pestov
c41be6ee0c IDE: Fix another usage of lookupVisibleMemberDecls() to not pass in an existential type
It's better to use the 'Self' archetype here.
2019-01-08 00:14:52 -05:00
Slava Pestov
8a201af7e6 IDE: Fix a usage of lookupVisibleMemberDecls() to not pass in an existential type
It's better to use the 'Self' archetype here.
2019-01-08 00:14:52 -05:00
Slava Pestov
f81c23d154 IDE: Replace some dead code with an assert 2019-01-08 00:14:52 -05:00
Argyrios Kyrtzidis
ab7427723e [Parse/Syntax] Refactoring to decouple the parser from syntax tree creation
Instead of creating syntax nodes directly, modify the parser to invoke an abstract interface 'SyntaxParseActions' while it is parsing the source code.
This decouples the act of parsing from the act of forming a syntax tree representation.
'SyntaxTreeCreator' is an implementation of SyntaxParseActions that handles the logic of creating a syntax tree.
To enforce the layering separation of parsing and syntax tree creation, a static library swiftSyntaxParse is introduced to compose the two.

This decoupling is important for introducing a syntax parser library for SwiftSyntax to directly access parsing.
2019-01-07 19:52:59 -08:00
swift-ci
39161d5b36 Merge pull request #20600 from adrian-prantl/36032653 2018-12-05 17:01:58 -08:00
Adrian Prantl
d63debeb60 Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.

This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.

This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.

rdar://problem/36032653
2018-12-05 13:54:13 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Rintaro Ishizaki
337d53f217 [CodeCompletion] Be lenient in callee analysis
Accept `getInterfaceType->hasError()` declarations. Even if the part of
the declaration has error, we still have chance to get context info from
the other part of it. For instance:

  func foo(x: Int, y: INt) { }
  foo(x: #^COMPLETE^#

We should resolve 'Int' as the context type even if parameter `y` is an
error type.
2018-12-03 17:26:12 +09:00
Rintaro Ishizaki
56c531d05a [CodeCompletion][NFC] Add some doc comments 2018-11-27 08:02:47 +09:00
Rintaro Ishizaki
c55d6ce7bd [CodeCompletion] Fix call arguments completion in overloaded case
In `<expr> '(' <code-completion-token>` case, we usually complete call
arguments. If '<expr>' isn't typechecked, for example, because of
overloading, we used to give up arguments completions.

Now, use possible callee informations from the context type analyzer. This
increases the chance to provide accurate completions.

rdar://problem/43703157
2018-11-27 02:41:11 +09:00
Rintaro Ishizaki
8a6c540e74 [CodeCompletion][NFC] Collect possible callees instead of params
in context type analysis.
Still NFC, but this is needed by later commits.
2018-11-27 02:41:03 +09:00
Rintaro Ishizaki
1af807894e [CodeCompletion][NFC] Store context results in analyzer member fields
To simplify call-site code.
2018-11-26 23:09:29 +09:00
Rintaro Ishizaki
bd4f20dd5f [CodeCompletion][NFC] Move collectArgumentExpectation()
These functions are only used by CodeCompletionTypeContextAnalyzer.
Move them into it.
2018-11-26 20:06:38 +09:00
Rintaro Ishizaki
5df5711b67 [CodeCompletion] Rework getOperatorCompletions() (#20632)
In postfix completion, for operator completion, we do:

  1. Type check the operand without applying it, but set the resolved
     type to the root of the expression.
  2. For each possible operators:
      i. Build temporary binary/postfix expression
      ii. Perform type checking to see whether the operator is applicable 

This could be very slow especially if the operand is complex.

* Introduce `ReusePrecheckedType` option to constraint system. With
  this option, CSGen respects pre-stored types in expressions and doesn't
  take its sub-expressions into account.
  * Improve type checking performance because type variables aren't
     generated for sub-expressions of LHS (45511835)
  * Guarantee that the operand is not modified by the type checker because
     expression walkers in `CSGen` doesn't walk into the operand.

* Introduce `TypeChecker::findLHS()` to find LHS for a infix operator from
  pre-folded expression. We used to `foldSequence()` temporary
  `SequenceExpr` and find 'CodeCompletionExpr' for each attempt.
  * No need to flatten folded expression after initial type-checking.
  * Save memory of temporary `BinaryExpr` which used to be allocated by
    `foldSequence()`.
  * Improve accuracy of the completion. `foldSequence()` recovers invalid
    combination of operators by `left` associative manner (with
    diagnostics). This used to cause false-positive results. For instance,
    `a == b <HERE>` used to suggest `==` operator. `findLHS()` returns
    `nullptr` for such invalid combination.

rdar://problem/45511835
https://bugs.swift.org/browse/SR-9061
2018-11-22 21:20:51 +09:00
Arnold Schwaighofer
2ac6cda9a7 Make sure the code completion takes both private imports and testable
imports into account separately.
2018-11-12 14:53:56 -08:00
Pavel Yaskevich
b3f86259a8 [CodeCompletion] Add isAutoClosure flag to parameter builder 2018-11-10 11:59:28 -08:00
Arnold Schwaighofer
6cc3d377ff Refactor part2 2018-11-08 18:16:17 -08:00