Commit Graph

54 Commits

Author SHA1 Message Date
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
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
Xi Ge
f27ccabdb1 SourceKit/Formatting: avoid indenting for consecutive dot-member calls
rdar://52392291
2019-07-12 14:03:03 -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
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
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
Argyrios Kyrtzidis
1dcb1e083a [sourcekitd] Expose the indentation option for extra indentation of switch case
rdar://51079623
2019-05-23 16:21:30 -07: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
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
Rintaro Ishizaki
3cecef02b9 [SourceKit] Add regression test for rdar 32789463 (already fixed) (#14151)
This crasher has already been fixed in 34e2aec662
2018-01-25 22:06:16 +09:00
Argyrios Kyrtzidis
fdd407f904 [test] Re-enable test/SourceKit/CodeFormat/indent-implicit-getter.swift (#12317)
This was disabled a long time ago due to a crash but I cannot reproduce such a crash currently.
rdar://26484736
2017-10-06 16:37:09 -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
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
David Farler
776a799a86 Revert "[test][SourceKit] Add a test to ensure sibling-based indentation work for arguments with trailing comments. rdar://27776466"
The code that fixed this test has to be reverted for the time being.

This reverts commit 6880afaeba.
2016-11-18 13:23:31 -08:00
Xi Ge
6880afaeba [test][SourceKit] Add a test to ensure sibling-based indentation work for arguments with trailing comments. rdar://27776466
The radar is no longer an issue after @bitjammer's change on preserving
trivia on tokens.
2016-11-16 16:19:43 -08:00
Xi Ge
e5d77911a2 [SourceKit] Indent property getters disregarding of empty bodies. rdar://28049927 (#5246)
[SourceKit] Indentation: when the indented line starts with open brace and the
line before starts with a leading declaration keywords, we never add
indentation level on the brace. rdar://28049927
2016-10-11 19:23:29 -07:00
Xi Ge
7cb5d9a8a2 [SourceKit] When function calls taking multiple closures, align the end of them. rdar://27473586 (#4787) 2016-09-14 19:13:50 -07:00
Xi Ge
365bb52a31 [SourceKit] Avoid adding indentation at the end of a CaptureListExpr. rdar://28193169 (#4749) 2016-09-13 13:33:34 -07:00
Xi Ge
c29286171f [Parser] Preserve empty getter functions for indentation (#4586)
* [Parser] Preserve empty getter functions to make sure indentation inside its body still works. rdar://28049927

* Using the consistent identifier even though they are identical.
2016-09-01 14:56:23 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Xi Ge
5d07b4b068 [SourceKit][Format] Avoid indenting when multiple function call ends at the same line.
This fixes SR-603.
2016-07-25 17:57:57 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Xi Ge
2ed177046e [SourceKit] Check location validity before getting the line number to fix a crash. rdar://26756189 (#3364) 2016-07-06 21:26:09 -07:00
Argyrios Kyrtzidis
d10220920b [IDE/format] Disable the sibling check for dictionary/array literal elements.
This ends up creating too much indentation in some common cases.
This effectively get us back to indentation behavior of Swift 2.2.

Addresses rdar://26290643.
2016-05-23 17:23:40 -07:00
Xi Ge
6ad5e8bc13 [SourceKit][Test] Add a test to ensure function arguments' labels are aligned properly. rdar://26069993 2016-05-03 14:33:32 -07:00
Xi Ge
589d9a8a3e CodeFormat: Avoid indenting the close bracket of a closure if the closure is on the RHS of an assignment expression. rdar://24507930 2016-03-29 13:08:55 -07:00
Xi Ge
701277e751 Allow SourceEntityWalker to visit operator decls, so that they can get indented properly. rdar://25246628 2016-03-19 14:47:58 -07:00
Xi Ge
5dbabf5cb3 [Test] SourceKit: Add a test for indenting unnamed parameters. rdar://25178551 2016-03-18 17:24:31 -07:00
Ben Langmuir
14ce05977c Disable CodeFormat/indent-implicit-getter.swift while we investigate a crash 2016-03-18 12:08:29 -07:00
Xi Ge
a91cc97058 [SourceKit] Indentation: aligning parameters when argument names are present. rdar://24862107
Fix is in AST by removing unnecessary override.
Originally reported by: https://twitter.com/JohnRHeaton/status/702526804138074112
2016-02-26 12:09:24 -08:00
Xi Ge
c5408c8beb [SourceKit] Indentation: indent the first element in a collection expression according to the position of the left bracket, if they are not in the same line.
We treat this as a mutated version of sibling-based indentation, where an extra level is needed. rdar://24630624
2016-02-18 13:28:44 -08:00
Xi Ge
4e85583718 add test 2016-02-18 13:28:44 -08:00
Xi Ge
ad33048af9 [test] Add a test for indenting class var. 2016-02-10 10:18:58 -08:00
Xi Ge
a2490e2ae1 [SourceKit][CodeFormat] Awake the indent-sibling test after coping with the recent updates on AST representation of parameters. 2016-02-01 14:55:20 -08:00
Xi Ge
e92fb8109f [SourceKit][CodeFormat] When indenting a getter without the leading keyword, first check if the getter is implicit. rdar://24348021 2016-02-01 11:59:27 -08:00
Xi Ge
c0bd16e9cd [test] Add a test for indenting didset 2016-02-01 10:33:14 -08:00
Argyrios Kyrtzidis
7a982d6b8e [sourcekit] When printing requests/responses make sure to escape the strings.
This makes it more clear what the response string contains, plus you can copy the
printed request directly for passing to sourcekitd_request_create_from_yaml.
2016-01-22 13:29:32 -08:00
Xi Ge
562de320d3 [SourceKit][CodeFormat] Indent case label items of a case statement as siblings. rdar://24279926 2016-01-21 14:01:26 -08:00
Xi Ge
d87e0713a6 [Parser] For accessors, never enclose 'static' keywords as their start locations.
This problem is manifested as a SourceKit indentation problem in rdar://24251847.
2016-01-20 16:51:43 -08:00
Xi Ge
a65ffab3e7 [SourceKit][CodeFormat] When indent to siblings, respect tuple elements' names. rdar://24251847 2016-01-20 10:47:52 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00