Commit Graph

122 Commits

Author SHA1 Message Date
Nathan Hawes
58859f5699 [SourceKit/CodeFormat] Update indentation for braceless multiple trailing closures. 2020-05-06 01:56:41 -04:00
John McCall
a518e759d9 WIP for a different syntax for multiple trailing closures
that allows arbitrary `label: {}` suffixes after an initial
unlabeled closure.

Type-checking is not yet correct, as well as code-completion
and other kinds of tooling.
2020-05-06 01:56:40 -04:00
Nathan Hawes
c5c8c584a1 Add indentation support for multiple trailing closures.
Resolves rdar://problem/60250267
2020-05-06 01:56:40 -04:00
Robert Widmann
19ab68db98 [NFC] Strip UnresolvedSpecializeExpr of its TypeLoc
No caller needed the type
2020-04-28 20:10:10 -07:00
Nathan Hawes
e01c1a1579 [SourceKit/CodeFormat] Get 'trailing' indentation to work in more places and fix a bug where multi-line string indentation was modified.
E.g. if/guard condition patterns are column-aligned, but hitting enter after
the ',' below wasn't column-aligning the next empty line:

guard let x = Optional(42),
// No indentation added here after enter

Also the isTargetContext() check takes a start and end token location, but
wasn't accounting for the end location pointing a multiline string, so we
weren't walking into such nodes. This meant we didn't realise the target
location was within a multiline string in some cases, and we ended up
interfering with whitespace in its content.
2020-04-19 15:11:16 -07:00
Nathan Hawes
9e0e611949 [SourceKit/CodeFormat] Update hasOutdent check to handle specialization ranges < >
They were missed before, so < > that should trigger outdenting weren't. E.g.
let x = foo<
  Int, String, Int
>()
    .count // Indented becase we didn't process the < > brackets previously.
2020-04-15 19:20:20 -07:00
Nathan Hawes
6f50aa4957 Merge pull request #30891 from nathawes/indent-enum-case-decl
[SourceKit/CodeFormat] Column-align enum element decls and the items in their parameter lists.
2020-04-13 12:08:05 -07:00
Nathan Hawes
13d5a8addb Merge pull request #30870 from nathawes/mutiple-catch-pattern-indentation
[SourceKit/CodeFormat] Column-align multiple patterns in catch clauses
2020-04-10 19:07:44 -07:00
Nathan Hawes
df3b6a83bb [SourceKit/CodeFormat] Don't modify multiline string indentation regardless of it being column-aligned or not.
Resolves rdar://problem/61463947
2020-04-08 12:11:48 -07:00
Nathan Hawes
c6a06e0feb [SourceKit/CodeFormat] Column-align enum element decls and the items in their parameter lists.
Resolves rdar://problem/61461022
2020-04-08 10:16:59 -07:00
Nathan Hawes
19d6effc5e [SourceKit/CodeFormat] Column-align multiple patterns in catch clauses.
Catch clauses now support mutliple patterns. Like 'case' patterns, these
should be column-aligned if split across multiple lines.

do {
  ...
} catch MyErr.a(let x),
        MyErr.b(let x) {
  print("hello")
}
2020-04-08 09:46:09 -07:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Nathan Hawes
2a93296fb6 [SourceKit/CodeFormat] Simplify ContextOverride a little, and only propagate ContextLocs when necessary.
We don't actually need to set a ContextOverride unless the ContextLoc and L
paren/brace/bracket are on different lines. Combined with the fact that we
only set them if the L and R parens/braces/brackets are on different lines
to, it guarantees there will be at most one override that's applicable on
any given line, which lets us simplify the logic somewhat.
2020-03-11 23:06:44 -07:00
Nathan Hawes
aedafe980f [SourceKit/CodeFormat] Improve documentation and fix propagation of ContextLocs.
- Rename several symbols to make it clearer whether the ranges they deal with
  are open or closed.
- Add comments documenting the implementation of OutdentChecker::hasOutdent
- Fix a bug where code after a doc coment block of the '/**' style was being
  indented 1 space.
- Fix IsInStringLiteral not being set if the indent target was in a string
  segment of an interpolated multiline string.
- Update OutdentChecker::hasOutdent to propagate indent contexts from
  parent parens/brackets/braces to child parens/brackets/braces that start
  later in the same line (like FormatWalker already does). This changes the
  braces in the example below to 'inherit' a ContextLoc from their parent
  square brackets, which have a ContextLoc at 'foo'. This makes the whole
  expression be correctly considered 'outdenting':

  foo(a: "hello"
      b: "hello")[x: {
    print("hello")
  }]
2020-03-10 21:04:22 -07:00
Nathan Hawes
a368434432 [SourceKit/CodeFormat] Re-work and improve the indentation implementation.
This restructures the indentation logic around producing a single IndentContext
for the line being indented. An IndentContext has:
- a ContextLoc, which points to a source location to indent relative to,
- a Kind, indicating whether we should align with that location exactly, or
  with the start of the content on its containing line, and
- an IndentLevel with the relative number of levels to indent by.

It also improves the handling of:
- chained and nested parens, braces, square brackets and angle brackets, and
  how those interact with the exact alignment of parameters, call arguments,
  and tuple, array and dictionary elements.
- Indenting to the correct level after an incomplete expression, statement or
  decl.

Resolves:
rdar://problem/59135010
rdar://problem/25519439
rdar://problem/50137394
rdar://problem/48410444
rdar://problem/48643521
rdar://problem/42171947
rdar://problem/40130724
rdar://problem/41405163
rdar://problem/39367027
rdar://problem/36332430
rdar://problem/34464828
rdar://problem/33113738
rdar://problem/32314354
rdar://problem/30106520
rdar://problem/29773848
rdar://problem/27301544
rdar://problem/27776466
rdar://problem/27230819
rdar://problem/25490868
rdar://problem/23482354
rdar://problem/20193017
rdar://problem/47117735
rdar://problem/55950781
rdar://problem/55939440
rdar://problem/53247352
rdar://problem/54326612
rdar://problem/53131527
rdar://problem/48399673
rdar://problem/51361639
rdar://problem/58285950
rdar://problem/58286076
rdar://problem/53828204
rdar://problem/58286182
rdar://problem/58504167
rdar://problem/58286327
rdar://problem/53828026
rdar://problem/57623821
rdar://problem/56965360
rdar://problem/54470937
rdar://problem/55580761
rdar://problem/46928002
rdar://problem/35807378
rdar://problem/39397252
rdar://problem/26692035
rdar://problem/33760223
rdar://problem/48934744
rdar://problem/43315903
rdar://problem/24630624
2020-03-10 21:04:21 -07:00
David Zarzycki
3d1739fa86 NFC: Fix -Wdeprecated-copy warnings 2020-01-07 16:09:00 -05:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04: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
Xi Ge
a35ee51502 Merge pull request #26117 from nkcsgexi/52392291
SourceKit/Formatting: avoid indenting for consecutive dot-member calls
2019-07-12 16:58:03 -07:00
Xi Ge
f27ccabdb1 SourceKit/Formatting: avoid indenting for consecutive dot-member calls
rdar://52392291
2019-07-12 14:03:03 -07:00
Doug Gregor
015b7c5266 [AST] Use AbstractFunctionDecl::getBodySourceRange() more frequently.
A number of callers to AbstractFunctionDecl::getBody() were only
extracting the source range of the body... which can be retrieved more
efficiently with getBodySourceRange().
2019-07-11 21:31:21 -07:00
Xi Ge
c2d8c460f3 SourceKit/Indentation: avoid indenting closing paren of function-like decls if it appears in a new line
rdar://51719094
2019-07-02 12:41:08 -07:00
Xi Ge
5280254325 Sourcekit/Indentation: avoid indenting dot member access appearing after trailing closure 2019-06-11 15:12:30 -07:00
Xi Ge
2b190648c0 SourceKit/Indentation: avoid indenting the end of subscript expressions in call chain.
rdar://50591281
2019-06-11 10:54:07 -07:00
Xi Ge
c7cf96660a SourceKit/Indentation: align function names in chained trailing closures
Chained trailing closures are sibling-like thus they should be aligned.

rdar://22205716
2019-06-10 17:07:20 -07:00
Xi Ge
b520708f07 Sourcekit/Indentation: avoid indenting the end of array/dictionary literals if they appear at the argument end
rdar://40093469
2019-05-30 15:51:50 -07:00
Xi Ge
c93700aa8b Address several post-commit comments. NFC 2019-02-14 22:09:32 -08:00
Xi Ge
8dbbb2ba1d sourcekitd/format: avoid performing sibling-based indentation for PrefixUnaryExpr.
rdar://47659949
2019-01-31 15:44:19 -08:00
Keith Smiley
2d91af2077 IDE: Fix formatting of closing square brackets
Previously closing square brackets would be caught in the logic for
elements in collections, indenting them to the same level. Now they are
indented with the normal non-sibling logic, which indents them
correctly.
2018-07-25 20:27:32 -07:00
Slava Pestov
5213f80e7e IDE: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-22 20:56:56 -07:00
Ben Langmuir
45936f5242 [gardening] Tweak comment wording 2018-04-13 13:49:57 -07:00
Sho Ikeda
976c7f9c27 [gardening][IDE] Replace typedef with using 2018-03-26 13:45:36 +09:00
Xi Ge
7fe3c5cfdd Formatting: Avoid crashing when indent width is 0. rdar://37835956 (#14873) 2018-02-28 11:00:20 -08:00
Xi Ge
61317432d7 Formatting: sanitize formatting option of 0 tab-width. rdar://37835956 (#14861)
If the format option specifies using tab of zero width, we reset the
tab width to a non-zero value.
2018-02-27 13:00:27 -08:00
Saleem Abdulrasool
b7963d8417 IDE: provide const overload for operator*
Provide a const overload for `operator*` for `SourceLocIterator` as the
MSVC C++ runtime uses the const overload for the `std::lower_bound`
algorithm.
2018-02-01 14:33:03 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Slava Pestov
0715eaeaed AST: Move SourceEntityWalker to IDE 2017-11-13 22:10:41 -08:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Xi Ge
b17ccf1ae7 Formatting: when aligning siblings in indentation, we should respect use tab setting. rdar://32611247 (#11334)
We use white spaces for the remaining that cannot be filled with tabs.
2017-08-04 12:14:23 -07:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Xi Ge
df64cd7686 Formatting: Avoid formatting multi-line string literals since it may change behavior. rdar://32135036 (#9582) 2017-05-13 18:21:18 -07:00
practicalswift
437a186032 [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar) 2017-05-09 11:26:07 +02:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Slava Pestov
4f4e6f6ebf Sema: Remove another workaround and fuzz harder
We used to drop the entire generic parameter list if one of the
entries failed to parse. This caused a problem where the generic
parameters were still available for name lookup, so they had
to be special-cased since there's no generic environment set up
in this case.

Now, keep the parts of the generic parameter list around that
parsed successfully.

When I first made the change, almost a hundred crashers regressed;
now all the underlying issues have been fixed.

The result is that in addition to removing a crappy hack we get
some more mileage out of the compiler_crashers, because stuff like
this now builds a generic environment:

class S<T{...}
2017-02-03 17:02:04 -08:00
Slava Pestov
b3cabb0745 Use llvm casts in various places instead of looking at {Expr,Decl,TypeBase}::getKind()
Also add some FIXMEs for some code in debug info emission that
looks incorrect.
2017-01-30 00:08:53 -08: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
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00