Commit Graph

199 Commits

Author SHA1 Message Date
Ben Langmuir
2bf014dc74 [expand-placeholder] Add support for multiple-trailing closures
Since placeholder expansion works with a single placeholder, which is
somewhat at odds with multiple-trailing closures, we eagerly attempt to
expand all consecutive placeholders of closure type. That is, if the API
has multiple closure parameters at the end, expanding any one of them
will transform all of them to the new syntax.

Example

```
foo(a: <#T##()->()#>, b: <#T##()->()#>)
```

expanding *either* parameter will produce the following:

```
foo {
  <#code#>
} b: {
  <#code#>
}
```

(caveat: the indentation is not part of placeholder expansion, but it's
added here for clarity)

At least for now we do not attempt to corral an existing closure into
the new syntax, so for

```
foo(a: { bar() }, b: <#T##()->()#>)
```

The exansion will be

```
foo(a: { bar() }) {
  <#code#>
}
```

as it was before.

rdar://59688632
2020-05-06 01:56:41 -04:00
Robert Widmann
f9a506d799 [NFC] Strip EditorPlaceholderExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Nathan Hawes
974f8c728c Merge pull request #31299 from nathawes/fix-syntactic-request-crasher
[SourceKit] Fix unreachable hit in DocumentStructureWalker
2020-04-27 10:05:17 -07:00
Nathan Hawes
43eceef394 [SourceKit] Fix unreachable hit in DocumentStructureWalker
Resolves rdar://problem/61967092
2020-04-24 15:34:46 -07:00
Hamish Knight
59b228f3fa Don't emit an error for code completion
Now that we no longer perform whole-file type
checking for code completion, the ASTVerifier is
no longer expecting fully semantically valid AST.
As such, we no longer need to emit an error to
force it to be more lax with its checks.
2020-04-24 13:39:33 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Suyash Srijan
84f8e41dee [Typechecker] Add an hasObservers() convenience method and simplify some code 2020-04-10 00:26:52 +01:00
Argyrios Kyrtzidis
b3b3cd3f81 [SourceKit] Avoid calling AbstractStorageDecl::isSettable during syntactic operations
`isSettable` can trigger typechecking and cause crashes during pure syntactic requests.

rdar://60441208
2020-03-17 18:30:33 -07:00
Michael Forster
345a9147ec Explicit SmallString->std::string conversion.
This is only needed temporarily until commit d7049213 from upstream
LLVM hits the swift/master branch.
2020-03-13 19:16:49 +01:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Hamish Knight
f56b061407 [Parse] Check the SourceFile for #if evaluation
Remove the `EvaluateConditionals` flags from the
parser, and instead query the source file.

This commit also changes ParserUnit such that it
doesn't evaluate #if conditions by default, as
none of its clients appear to require it. The
only client that wasn't explicitly disabling #if
evaluation and is processing the resulting AST is
swift-indent, so this commit also adds a test to
ensure it continues to work correctly with #if
decls.
2020-03-02 14:12:37 -08:00
Hamish Knight
0d5a5e12d5 Move #if evaluation flag out of PersistentParserState
Move this flag onto the parser instead. Now the
only client of PersistentParserState is code
completion.
2020-02-28 10:51:12 -08:00
Owen Voorhees
f11df3ee22 [Diagnostics][SourceKit] Expose diagnostic educational notes through SourceKit requests 2020-02-26 14:30:28 -08:00
Nathan Hawes
2420b6d28b [SourceKit] Don't report the ObjC runtime name without @objc(Name)
We used to compute the mangled name in other cases, but document structure is
a syntactic request and can't guarantee that the class/protocol we're getting
the mangled name of is valid in any way so it often breaks assumptions in the
mangler and causes it to crash. It's not clear if the runtime_name is actually
being used anymore, so this change restricts reporting it to just the cases
where we don't need to mangle.

rdar://problem/40956377
2020-02-14 11:40:09 -08:00
Nathan Hawes
43523df08a [IDE] Remove call to getFormalAccess() in inferAccessSyntactically()
It should have been recursing into inferAccessSyntactically() to avoid
any chance of triggering name lookup.
2019-11-18 11:25:50 -08:00
Nathan Hawes
11d20b8c92 [IDE] Avoid name binding in sourcekitd's syntactic requests
It looks like we recently started binding extensions to their nominals in order
to continue to compute access levels via ValueDecl::getFormalAccess() after an
assertion was added to enforce that bindExtensions had been called before
anything tried to call ExtensionDecl::getBoundNominal() - which
getFormalAccess() depends on. Sourcekitd's syntactic requests are made on every
keypress in the editor though, so we shouldn't do any name binding (which may
require module loading) to keep them as fast as possible.

This patch restores the old inferAccessLevel() functions we used prior to the
switch to ValueDecl::getFormalAccess() (plus a few fixes) that does as much as
it can syntactically, without any name binding, and simply doesn't report the
access level in cases where it couldn't be computed without name-binding.

This also fixes an assertion hit we were getting trying to bind extensions in
inactive ifconfig clauses, which ASTScope doesn't support.

Resolves rdar://problem/57202584
2019-11-16 13:41:20 -08:00
Robert Widmann
48805b1d44 Give ASTContext TypeCheckerOptions
Strip TypeChecker of all of this state.
2019-11-12 09:56:01 -08:00
Robert Widmann
0267384e11 Fixup SourceKit and Tests
Patch up all the places that are making a syntactic judgement about the
isInvalid() bit in a ValueDecl.  They may continue to use that query,
but most guard themselves on whether the interface type has been set.
2019-10-30 15:09:14 -07:00
Jordan Rose
5c2185f395 Merge pull request #27868 from owenv/diag-info-refactor
[Diagnostics] Refactor DiagnosticConsumer interface to remove unnecessary params
2019-10-30 14:49:11 -07:00
Ben Langmuir
c864eab859 [edit] Fix racy access to SemanticInfo
Specifically, if the document was re-opened, we would drop the reference
and the call to readSemanticInfo could use-after-free the array of
diagnostics. This manifested as a very rare crash while testing
sourcekit-lsp.
2019-10-29 16:33:36 -07:00
Owen Voorhees
8a6711769e [Diagnostics] Refactor DiagnosticConsumer interface
DiagnosticInfo now holds all the information needed to consume
a diagnostic, so remove unneeded parameters from handleDiagnostic.
2019-10-29 13:52:12 -07:00
Doug Gregor
d8f7c9e72c [Parser] Introduce a request for parsing type and extension members.
Ensure that lazy parsing of the members of nominal type definitions
and extensions is handled through a request. Most of the effort here
is in establishing a new request zone for parser requests.
2019-08-28 21:39:56 -07:00
Argyrios Kyrtzidis
0135e01d02 Rename the swift-format utility to swift-indent
This is to distinguish the C++ indenting functionality from the new formatter that is written in Swift.
2019-07-26 11:40:54 -07:00
Slava Pestov
8561407dc3 SourceKit: Register type checker request functions
Some requests are implemented in lib/Sema/, even if they don't require a
LazyResolver. Be sure to register their request functions in SourceKit so
that these requests can be kicked off when needed.
2019-07-23 16:13:28 -04:00
Marc Rasi
ccd2f2ab56 make re-opening a file update its vfs 2019-07-16 14:24:37 -07:00
Marc Rasi
3b44b27b30 propagate vfs to more places, remove vfs arg
Propagates the VFS to the SemanticInfo that gets used when then
original editor.open is syntactic only.

Removes unnecessary filesystem arg (get filesystem from class field
instead).

Adds test for the VFS being propagated into the SemanticInfo.

Refactors test/SourceKit/CursorInfo/injected_vfs.swift to use
-print-raw-response for all its tests, for consistency.
2019-07-16 11:39:00 -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
Nathan Hawes
0d59bffd81 [SourceKit] Fix placeholder expansion not working inside #if
Update the PlaceholderFinder ASTWalker to walk into the clauses of
IfConfigDecls. It wasn't previously, resulting in any placeholders there not
being expanded.

Also update CallExprFinder (used to determine if expansions should use trailing
closure syntax) to walk into inactive if-config clauses. Previously it only
walked into active regions, so expansions never used trailing closure syntax in
inactive regions.

Resolves rdar://problem/51995648
2019-07-09 14:18:40 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -07:00
Argyrios Kyrtzidis
1dcb1e083a [sourcekitd] Expose the indentation option for extra indentation of switch case
rdar://51079623
2019-05-23 16:21:30 -07:00
Ben Langmuir
6377199e2f [placeholder-expansion] Expand trailing closure in statements correctly
In addition to brace statements (previously handled), several other
statements allow a trailing closure (return, yield, throw). Also fix the
handling of statements nested within expressions for closures - both
single-expression bodies and brace statements.

This also fixes a particular regression caused by single-expression
function bodies where we would fail to expand to a trailing closure when
a function body only contained a single expression.

rdar://50227500
2019-04-26 11:58:52 -07:00
Ben Langmuir
27b12bfe89 Merge pull request #23978 from AnthonyLatsis/expand-closure-check-braces
SourceKit: Account for existing braces when expanding closure placeholders
2019-04-25 15:00:40 -07:00
Ben Langmuir
effab8c522 Handle dynamic member lookup in annotation and cursor info
Ensure the various entity walkers handle the implicit subscript
reference correctly (usually by ignoring it) and fall through to the
underlying declarations.

rdar://49028895
2019-04-16 15:37:32 -07:00
Ben Langmuir
6af24d083c [index] Fix dynamicMemberLookup subscript reference implicit role
When building the implicit subscript expression, set the "implicit" bit
correctly and pass it through in the indexer so that we get implicit
refernces to the subscript. This would be useful for e.g. searching for
all uses of the dynamic subscript.
2019-04-16 15:37:32 -07:00
fischertony
7344fdb0a4 SourceKit: Account for existing braces when expanding closure placeholders 2019-04-12 07:30:28 +03:00
David Ungar
44daa88ebd Format 2019-04-03 12:53:31 -07:00
David Ungar
9cc3a4a9d8 Rename defaultDiagnosticLoc to bufferIndirectlyCausingDiagnostic. 2019-04-03 12:52:49 -07:00
David Ungar
c139c5909a Pass defaultDiagnosticLoc to handleDiagnostic, not currentPrimaryInput. 2019-04-02 22:27:55 -07:00
David Ungar
7a0e0ffc8a Store current primary in diagnostic engine, pass it down via handleDiagnostic. Unformmated. 2019-04-02 00:43:28 -07:00
Rintaro Ishizaki
606b551f87 [SourceKit] Fix a crash in SwiftDocumentStructureWalker::getObjCSelectorName()
SourceKit document structure request used to crash if if there's inititalizer
with single named parameter with `@IBAction` attribute.

This used to happen because
ConstructorDecl::isObjCZeroParameterWithLongSelector() requires
interface type of the parameter but the constructor doesn't have it at
this stage.

This change fixes that by not vending ObjC name for
constructor or destructors.

rdar://problem/47426948
2019-01-25 17:10:52 -08:00
Argyrios Kyrtzidis
c7ac859310 [Parse] Optimize syntax parsing: Speed-up Lexer::lexTrivia()
Introduce ParsedTrivia which is a more efficient structure to use during lexing than syntax::Trivia.
2019-01-17 12:10:27 -08: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
Argyrios Kyrtzidis
66be4a58b4 [Parser] Introduce ParserUnit::parse() function to avoid duplication of code 2018-12-16 09:52:15 -08:00
Xi Ge
7f7a756ea4 sourcekit: avoid evaluating pound conditions while perform syntactic parsing. rdar://46143404 2018-12-03 14:56:25 -08:00
Argyrios Kyrtzidis
f913a239f8 [SourceKit] Avoid the 'error: no input files' diagnostic notification for syntactic-only requests
rdar://44989868
2018-10-13 09:48:00 -07: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