Commit Graph

75 Commits

Author SHA1 Message Date
Rintaro Ishizaki
6dd5d9482f [CodeCompletion] Introduce "Flair" in code completion
To describe fine grained priorities.

Introduce 'CodeCompletionFlair' that is a set of more descriptive flags for
prioritizing completion items. This aims to replace '
SemanticContextKind::ExpressionSpecific' which was a "catch all"
prioritization flag.
2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
3c2433c942 [CodeCompletion] Prioritize call argument pattern
struct Foo {
    init(_ arg1: String, arg2: Int) {}
    init(label: Int) {}
  }
  func test(strVal: String) {
    _ = Foo(<HERE>)
  }

In this case, 'strVal' was prioritized because it can use as an argument
for 'init(_:arg2:)'. However, argument labels are almost always
preferable, and if the user actually want 'strVal', they can input a few
characters to get it at the top. So we should always prioritize call
argument patterns.

rdar://77188260
2021-04-29 13:23:15 -07:00
Ben Langmuir
be7b5a7179 [completion] Clarify and simplify not-recommended state
Combine IsNotRecommended with NotRecommendedReason and improve the names
of the existing cases to more clearly identify the cases they apply to.
Now all not-recommended completions are required to have a reason.
2021-04-19 09:43:28 -07:00
Ben Langmuir
222e2c7f4c Lift ImportDepth utility out of SourceKit into IDE (NFC) 2021-03-09 13:52:56 -08:00
Brent Royal-Gordon
f71923778b Add -testable-import-module frontend flag
This is just like -import-module, but it does an @testable import. Simple, right?

Fixes rdar://66544654.
2020-10-09 18:59:20 -07:00
Brent Royal-Gordon
b440ab7331 [NFC] Move several types/functions to Import.h
To help consolidate our various types describing imports, this commit moves the following types and methods to Import.h:

* ImplicitImports
* ImplicitStdlibKind
* ImplicitImportInfo
* ModuleDecl::ImportedModule
* ModuleDecl::OrderImportedModules (as ImportedModule::Order)
* ModuleDecl::removeDuplicateImports() (as ImportedModule::removeDuplicates())
* SourceFile::ImportFlags
* SourceFile::ImportOptions
* SourceFile::ImportedModuleDesc

This commit is large and intentionally kept mechanical—nothing interesting to see here.
2020-10-09 18:57:07 -07:00
Varun Gandhi
d3369f7711 [NFC] Rename ImportFilterKind cases to be clearer. 2020-09-23 12:50:20 -07:00
Ben Barham
4f5d4d80bb [Gardening] Add re-usable copy* utility methods to use in code completion
Various copy* methods were re-implemented in a bunch of files, move them
to CodeCompletion.h so they can be re-used everywhere that needs them.
2020-09-10 11:42:33 +10:00
Ben Langmuir
cf87ad805f [gardening] Move filter name printing alongside other completion methods 2020-08-25 10:39:19 -07:00
Ben Langmuir
6480bfaad2 [gardening] Move FuzzyStringMatcher to libIDE 2020-08-25 10:39:08 -07:00
Martin Boehme
d806ba53f6 Give OptionSet an initializer_list constructor.
This makes it easier to specify OptionSet arguments.

Also modify appropriate uses of ModuleDecl::ImportFilter to take
advantage of the new constructor.
2020-06-22 06:57:29 +02:00
Rintaro Ishizaki
7086ffb79f [CodeCompletion] Annotated result type
Introduced 'TypeAnnotationBegin' chunk kind for grouping the result type
name chunks.

rdar://problem/62617558
2020-05-11 22:56:22 -07:00
Rintaro Ishizaki
75a0c9f819 [CodeCompletion] Add 'IsSystem' flag to code completion result item
'key.is_system: 1' is added if the associated declaration is from a
system module.

rdar://problem/62617558
2020-05-11 12:24:36 -07:00
Ben Langmuir
37b98af4e6 [CodeCompletion] Pre-expand closures in argument completion
When completing a single argument for a trailing closure, pre-expand the
closure expression syntax instead of using a placeholder. It's not valid
to pass a non-closure anyway.

rdar://62189182
2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
e9c438cdd5 [CodeCompletion] Dont mark type mismatching items 'not recommended'
func foo() {}
let a: Int = #^HERE^#

Previously, we marked 'foo()' as 'NotRecommented' because 'Void' doesn't
have any member hence it cannot be 'Int'. But it wass confusing with
'deprecated'.

Now that we output 'typerelation' which is 'invalid' in this case. So clients
can deprioritize results, or even filter them out.

rdar://problem/57726512
2020-05-05 10:40:05 -07:00
Daniel Sweeney
ea526c6383 Converting ModuleDecl::ImportedModule from std::pair to a dedicated struct. (#31360) 2020-04-30 20:26:03 -07:00
Hamish Knight
453667f659 [Frontend] Validate ImplicitImportModuleNames early
Check whether the user has provided a valid
identifier when parsing the options. Also make
ImplicitImportModuleNames a private member of
FrontendOptions to prevent mutation after being
parsed.
2020-04-20 13:20:35 -07:00
Rintaro Ishizaki
773a464e83 [CodeCompletion] Add an option to emit annotated description 2020-04-07 00:46:14 -07:00
Rintaro Ishizaki
979906cce2 [CodeCompletion] Don't manually handle Equal opeerator 2020-04-06 13:49:43 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01: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
swift-ci
23021d96fc Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 11:04:29 -08:00
Rintaro Ishizaki
cc8d4965f8 [CodeCompletion] Ensure cached results have 'unknown' type relation 2020-02-05 17:05:23 -08:00
swift_jenkins
29b0fb925e Merge remote-tracking branch 'origin/master' into master-next 2019-12-19 14:40:17 -08:00
Rintaro Ishizaki
62c44126b6 [SourceKit] Reuse compiler instance between multiple completion
- Introduce ide::CompletionInstance to manage CompilerInstance
- `CompletionInstance` vends the cached CompilerInstance when:
-- The compiler arguments (i.e. CompilerInvocation) has has not changed
-- The primary file is the same
-- The completion happens inside function bodies in both previous and
   current completion
-- The interface hash of the primary file has not changed
- Otherwise, it vends a fresh CompilerInstance and cache it for the next
  completion

rdar://problem/20787086
2019-12-18 21:52:20 -08:00
swift-ci
dce64e93ee Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 10:49:47 -07:00
Nathan Hawes
54defbc7f7 [code-completion] Remove special handling for completion on the RHS of an assignment
This simplifies the code and prevents an assertion failure this code was
hitting computing the type relations between the result types and what it
determined as the expected type.

Resolves rdar://problem/53958454
2019-09-17 18:59:33 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Gwen Mittertreiner
518196cde9 Properly Compare True and False Order in Sourcekit
Comparing "false" > "true" will return 0, which when returned by compare
indicates the two are equal which will result in a non deterministic
ordering of "false" and "true". Using .compare returns a negative number
as expected.
2019-07-10 18:25:53 -07:00
Ben Langmuir
81ce653bc3 Merge pull request #23587 from benlangmuir/cc-omit-return
[code-completion] Add type context for single-expression function bodies
2019-04-25 13:49:45 -07:00
Rintaro Ishizaki
7078862921 [CodeCompletion] Provide 'some' keyword where applicable
rdar://problem/49353647
2019-04-19 17:11:16 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Ben Langmuir
b14cd916a3 [code-completion] Add type context for single-expression functions
Extend the support for single-expression closures to handle
single-expression functions of all kinds. This allows, e.g.

    func foo() -> MyEnum { .<here> }

to complete members of `MyEnum`.
2019-03-26 16:45:27 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Rintaro Ishizaki
66c71d1bf7 [SourceKit] Force print '?' for optional method call in code completion. (#16910)
Calling '@objc optional func' requires '?' or '!' after its name. When
completing method calls for them, 'key.sourcetext' should have '?'
whereas 'key.name' shouldn't.
Note that we deliberately do not use optional type name for
'key.typename'. This is consistent with optional chain '?.<propertyName>'
behavior.

rdar://problem/37904574
2018-05-31 16:06:23 -07:00
Ben Langmuir
93d22c9ff0 [code-completion] Add a new custom completion context for a for-each sequence
For normal completions it behaves the same as PostfixExprBeginning, but
it provides a hook for clients to provide a custom completion for this
position.  For example, you might want to a x ..< y snippet in this
position.

rdar://problem/29910383
2017-07-19 13:29:36 -07:00
Ben Langmuir
61a151989a [code-completion] Add filter rules for description in addition filter-name
The filter name isn't helpful if you want to make rules about specific
overloads - e.g. only show the [Int] subscript on Array.

rdar://problem/28920034
2017-06-15 16:32:29 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
practicalswift
a7b34c0b25 [gardening] Remove unused variable prevCase 2017-03-07 16:26:34 +01:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Rintaro Ishizaki
81c1edee5d [CodeCompletion] Suffix ": " instead of "=" when completing attribute argument names
In addtion, renamed DeclAttrParamEqual to DeclAttrParamColon.
2016-08-17 02:33:04 +09:00
Ben Langmuir
c8f7da4de1 [CodeCompletion] Support a narrow case for producing trailing closures directly
This adds a narrow special case in code-completion for control-flow-like
methods such as DispatchQueue().sync that are () -> (), to add a new
completion where the trailing closure is immediately expanded rather
than having to invoke placeholder expansion as a second step.

rdar://problem/26628804
2016-07-01 14:16:57 -07:00
Ben Langmuir
4600b1dd12 [CodeCompletion] Fix incorrect upper bound for assertion
This assertion was bogus if there were fewer results than N.
2016-06-04 18:22:18 -07:00
Ben Langmuir
122350d450 [CodeCompletion] Apply filter rules directly to inner results
... and don't try to filter the extended results.  Once the results are
extended with the common prefix they will not match identifier filter
rules, which will create differences between completions depending on
whether they had a filter text or were a postfix expression.  Also,
allow filtering by name directly on the inner operator name for inner
operators.

rdar://problem/26312235
2016-05-25 12:07:17 -07:00
Ben Langmuir
5615b38040 [CodeCompletion] Show 'return' completion by default when appropriate
Ideally we would have precise completion for all our keywords; for now,
just imporove handling of 'return', which we can do by checking if the
current context is a function/closure/init/subscript/etc.

rdar://problem/26307555
2016-05-24 11:01:22 -07:00
Ben Langmuir
b4ce34aba9 [CodeCompletion] Remove ... and & from function filter names
The filter name of a function should match the spelling of the function
name according to the language except that we don't insert _ for unnamed
parameters because underscores are legal inside identifiers and we don't
want to introduce spurious matches (also, we keep the () on a
parameterless function for disambiguation).

rdar://problem/26118915
2016-05-10 11:13:45 -07:00
Ben Langmuir
69967ca45c [CodeCompletion] Identify known operators and force a fixed sort order
In the new code-completion code path, force any known operators to go
through a fixed sort order. To identify operators unambiguously, add a
new BuiltinOperator code-completion kind to handle non-decl operators
(!, ., ?., and =).

rdar://problem/25994246
rdar://problem/23440367
2016-05-03 10:23:13 -07:00