Commit Graph

106 Commits

Author SHA1 Message Date
Nathan Hawes
8edeab75ce [Parse] Don't drop the EnumCaseDecl when it has a trailing comma.
This meant we weren't producing sema diagnostics for the case, and it didn’t
get full syntactic/semantic highlighting or indentation.

enum CasesWithMissingElement {
  case a(Int, String),
  case b(Int, String),
}

Resolves rdar://problem/61476844
2020-04-10 18:22:33 -07:00
Anthony Latsis
016d3bbfae [ASTWalker] Associated type defaults deserve syntax coloring 2020-03-21 08:37:53 +03:00
fischertony
c498ad0283 IDE: Ensure syntax coloring for contextual where clauses 2020-03-05 07:29:28 +03:00
Nathan Hawes
5e1985c989 [SourceKit] Fix SyntaxModel assertion failures due to consuming tokens twice or prematurely
The SyntaxModel walker would end up visiting the attributes attached to a
PatternBindingDecl twice if it contained more than one VarDecl, hitting the
below assertion on the second visit because the tokens corresponding to the
attribute had already been consumed the first time around:
```
Assertion failed: (0 && "Attribute's TokenNodes already consumed?"), function
  handleSpecialDeclAttribute
```
It would also hit the same assertion for attributes on an EnumCaseDecl, but even
when it only had a single child EnumElementDecl.  This because when we visited
the EnumCaseDecl and pushed its structure node, we'd consume and emit any tokens
before it's start position. This meant that when we tried to process the
attributes attached to the child EnumElementDecl its tokens had already been
consumed, triggering the assertion.

In both cases the attributes syntactically attach to the parent
PatternBindingDecl or EnumCaseDecl, but in the AST they're accessed via their
child VarDecls or EnumElementDecls.

Resolves rdar://problem/53747546
2020-02-12 13:44:04 -08:00
Nathan Hawes
666a98cfd8 [syntax-coloring] Add fallback handling for coloring object literals when they don't appear in the AST
Resolves rdar://problem/55680999
2019-10-09 12:15:43 -07:00
Nathan Hawes
888529cf97 [IDE] Fix ModelASTWalker passing syntax nodes before the corresponding AST nodes had been visited
This was causing the tokens comprising image literals to be output separately,
rather than as a single object literal.

Resolves rdar://problem/55045797
2019-09-24 11:39:54 -07:00
Nathan Hawes
5d47b45991 [IDE][Parse] Change the source location of TypeAttributes to point to the @ like DeclAttributes 2019-08-05 11:36:32 -07:00
Nathan Hawes
87d17bfb4c [IDE] Fix ModelASTWalker's handling of type attributes
When looking for the SyntaxNode corresponding to a type attribute (like
@escaping), ModelASTWalker would look for one whose range *started* at the type
attribute's source location. It never found one, though, because the
SyntaxNode's range included the @, while the type attribute's source location
pointed to the name *after* the @.
2019-08-05 11:36:32 -07:00
Nathan Hawes
218f49052a [IDE] Fix SyntaxModel crash due to out-of-order walking of EnumElementDecls
ModelASTWalker was previously constructing SyntaxNodes for EnumElementDecls
manually when visiting their associated EnumCaseDecl so that they would appear
as children rather than siblings. It wasn't actually walking these nodes
though, so missed handling some things, e.g. closures passed as default
argument values. These were also still being visited later, and because the
first visit consumed all the associated TokenNodes, this was triggering an
assertion due to the associated TokenNodes not matching expectations.
2019-07-23 09:34:25 -07:00
Nathan Hawes
a565430239 [IDE][Index] Fix syntax coloring, index, and rename support for custom attributes
This fixes custom attribute syntax highlighting on parameters and functions
(where function builders can be applied). They weren't being walked in
the function position previously and were walked out of source order in the
parameter position.

It also fixes rename of the property wrapper and function builder type
names that can appear in custom attributes, as well as rename of property
wrapper constructors, that can appear after the type names, e.g.
`@Wrapper(initialValue: 10)`. The index now also records these constructor
occurrences, along with implicit occurrences whenever a constructor is
called via default value assignment, e.g. `@Wrapper var foo = 10`, so that
finding calls/references to the constructor includes these locations.

Resolves rdar://problem/49036613
Resolves rdar://problem/50073641
2019-06-26 18:37:47 -07:00
Rintaro Ishizaki
06e8483c36 [IDE] Function builder: add syntax coloring test for custom attribute
rdar://problem/50074156
2019-06-11 17:34:45 -07:00
Rintaro Ishizaki
c14779fa59 [IDE] Property delegate: Add custom attribute coloring test 2019-05-31 11:10:05 -07:00
Xi Ge
d3a192f3c5 SourceKit/SyntaxMap: properly handle object literal syntax for highlighting
We should use parser to figure out the end position of object literal expression instead
of scanning through token stream, which crashes sourcekitd when the syntax is invalid.

Fixing: rdar://48390913
2019-05-22 14:29:57 -07:00
Xi Ge
6743b6103b IDE: treat some as keyword for opaque result type 2019-04-19 17:11:03 -07:00
Rintaro Ishizaki
9347328bfe Merge pull request #23961 from AnthonyLatsis/associativity-kind-coloring
Parse: Reinterpret associativity kinds as contextual keywords
2019-04-12 14:10:39 -07:00
fischertony
44dfba81e4 Parse: Reinterpret associativity kinds as contextual keywords 2019-04-11 21:27:39 +03:00
Argyrios Kyrtzidis
b76ac41aff Merge pull request #22090 from marcelofabri/enum-type-syntax-map
[SR-9740][SourceKit] Mark types inside enum case decl as typeidentifiers
2019-03-02 00:10:28 -08:00
Nathan Hawes
a1de792ae3 [IDE][syntax-coloring] Treat unterminated raw strings as strings for syntax coloring purposes
The existing check assumed unterminated strings started with " which is no
longer true now we have raw strings.

Resolves rdar://problem/48269826
2019-02-22 18:53:32 -08:00
Rintaro Ishizaki
d4c3ee6b49 [IDE] Handle '@unknown' attribute in syntax map
`@unknown` is so far the only attribute for statement. Handle it
specially in syntax-map.

rdar://problem/47855035 / https://bugs.swift.org/browse/SR-9873
2019-02-06 11:23:53 -08:00
Marcelo Fabri
cab4968da3 [SR-9740][SourceKit] Mark types inside enum case decl as typeidentifiers 2019-01-24 09:14:11 -08:00
Alex Hoppen
798d079714 [IDE] Un-XFAIL test/IDE/coloring.swift 2018-08-31 13:25:11 -07:00
Alex Hoppen
3801bb0e42 [SwiftSyntax] Remove SwiftSyntax from the main swift repository
It has moved to its own repository at https://github.com/apple/swift-syntax
2018-08-30 11:46:22 -07:00
Rintaro Ishizaki
fedc36e4fb [IDE] Don't walk to ExplicitCast expr twice in ModelASTWalker
Explict cast expressions (i.e. 'as', 'as!`, 'as?', and 'is') appear twice in
'SequenceExpr'. For instance, 'a as B' is parsed as:
  (sequence_expr
    (unresolved_declref_expr name='a')
    (coerce_expr writtenType='B')
    (coerce_expr writtenType='B'))
This patch prevents ModelASTWalker from walking into them twice.

rdar://problem/43135727
2018-08-14 08:19:48 +09:00
Rintaro Ishizaki
68019859ed [IDE] Add FIXME in syntax coloring testcase regarding escaped identifier 2018-08-02 10:03:02 +09:00
Rintaro Ishizaki
49f6a28637 [IDE] Use collected token to retrieve range of type identifier
Previously, it used to use length from AST. Because AST doesn't necessarily
holds actual source information, it may emits inacculate syntax info
which cause mis-coloring or compiler crash in the worst case. Instead, use
collected token info which contains actual token length.

https://bugs.swift.org/browse/SR-8378
rdar://problem/42653982
2018-08-02 10:02:58 +09:00
Argyrios Kyrtzidis
a061077bd8 [Parser] Keep source location info for the ownership keywords inside a closure capture list (#18432)
* [Parser] Keep source location info for the ownership keywords inside a closure capture list

This allows to do syntax coloring for 'weak'/'unowned' inside a capture list
rdar://42655051
2018-08-01 09:39:20 -07:00
Argyrios Kyrtzidis
df043f739f [test] Move syntactic coloring tests related to '#' configs and other pound-related keywords to coloring_configs.swift, NFC 2018-07-31 21:44:30 -07:00
Argyrios Kyrtzidis
8782af1627 [test] Separate the syntactic coloring tests related to comments into its own test file, NFC 2018-07-31 21:34:43 -07:00
Xi Ge
571b29b64f SwiftSyntaxTest: refactor command-line argument parsing into a test utility module. NFC (#18418) 2018-07-31 17:05:47 -07:00
Alex Hoppen
179940b65b [swiftSyntax] Add test cases for the SyntaxClassifier 2018-07-30 14:55:54 -07:00
Alex Hoppen
749a13a6fe [libSyntax] Remove the C++ SyntaxClassifier
The recommended way forward is to use the SyntaxClassifier on the Swift
side.

By removing the C++ SyntaxClassifier, we can also eliminate the
-force-libsyntax-based-processing option that was used to bootstrap
incremental parsing and would generate the syntax map from a syntax
tree.
2018-07-30 09:26:18 -07:00
Alex Hoppen
5c22761865 [libSyntax] Enable tests for libSyntax based syntax coloring 2018-07-13 17:57:00 -07:00
Nathan Hawes
90cc29bb2c [syntax-coloring] Highlight unterminated regular and multi-line strings as strings
Also add tests for syntax map deltas when editing multi-line strings
2017-09-14 21:34:21 -07:00
Xi Ge
87ce54e3f2 Re-apply "Paser: IfConfigDecl should reflect the underlying source. rdar://34315827" 2017-09-12 12:59:25 -07:00
Xi Ge
2a07534bc1 Revert "Paser: IfConfigDecl should reflect the underlying source. rdar://34315827"
For test failure witnessed in bots: https://ci.swift.org/job/oss-swift-incremental-RA-osx/462/
2017-09-12 12:49:02 -07:00
Xi Ge
bfe6a64708 Paser: IfConfigDecl should reflect the underlying source. rdar://34315827 2017-09-12 11:58:49 -07:00
Nathan Hawes
df91a46729 Filter out 0-length tokens when generating syntax model nodes.
Resolves rdar://problem/33601932.
2017-08-03 13:09:18 -07:00
Xi Ge
b8cf32f1e9 Revert "[syntax-coloring] Rework the syntax map to use offset + length and simplify the delta logic" (#10633)
Resolving rdar://32988175.
2017-06-27 12:28:41 -07:00
Nathan Hawes
fa3873ec8e [syntax-coloring] Highlight unterminated regular and multi-line strings as strings
Also add tests for syntax map deltas when editing multi-line strings
2017-06-15 13:16:04 -07:00
Nathan Hawes
e5426ecfa5 Revert "[SyntaxColor] Improve highligting of multiline strings"
This reverts commit 86d0fc37bc.
This was causing a performance regression.

Resolves rdar://problem/32434045
2017-05-26 16:46:03 -07:00
Nathan Hawes
56fb4a5d9f [SyntaxColor] Improve highligting of multiline strings
Multiline strings (and multiline tokens in general) were not well supported by the existing highlighting logic. Edits
on one line can make tokens appear/disappear on previous and later lines, which broke assumptions in the existing
logic, and left odd ranges of source unhighlighted or out of date. This patch accounts for these changes, and also
changes unterminated  multiline (and regular strings) to still be highlighted as strings, so the rest of the
file doesn't look like plain text.

Resolves rdar://problem/32148117.
2017-05-22 16:53:32 -07:00
Nathan Hawes
52374a9812 [parser] Account for the length of multine string quotes when tokenizing interpolated string components
This fixes a syntax coloring issue when only the innermost " character were highlighted as part of the string, e.g:

""<str>"
  This is a string
  "</str>""
2017-05-13 12:08:45 -07: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
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Nathan Hawes
d257f1dd36 [SyntaxColor] Restrict the keywords colored as identifiers to just those that can be used as argument labels. rdar://problem/29098176
Most keywords can be used as argument labels. When they are they shouldn't be
colored as a keyword. This patch fixes three issues with this:
-  keywords as local argument labels (where an external label was also present)
were still colored as keywords
- 'let', 'var', and 'inout' cannot be used as argument labels, but were colored
as identifiers rather than keywords when used like one
- the check to see if a keyword token is being used as an argument label wasn't
quite restrictive enough, e.g. treating the 'let's in 'case (let x, let y):' as
identifiers.
2016-11-07 10:47:04 -08:00
Ben Langmuir
f07457834a [sourcekitd] Replace a slow std::regex with custom parsing
This gave a roughly 40-45% improvement in sourcekitd's incremental
syntax-only parse time in files with a lot of doc comments (test case
was ~6000 lines, with ~780 lines being doc comments). This is on the
critical path for every edit.

While there were a few smaller improvements we could have made to the
original code, ultimately std::regex is slow, and it was better to just
use a custom parser for these simple patterns.

rdar://problem/28809397
2016-10-18 11:29:25 -07:00
Xi Ge
e6f263fe31 [SyntaxColor] Respect keywords' syntax kind when they appear in conditions. (#5076)
Keywords like 'let' can serve as argument labels. When they do so, we should
highlight them as identifiers instead of keywords. However, the check for this
situation seems overly lenient so that when 'let', 'var' appear in conditions
of IfStmt or GuardStmt, they are wrongly highlighted as identifiers too. This
commit strengthens the checking to preserve keywords' identity in these statements.
rdar://28297337
2016-09-29 19:36:55 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Ben Langmuir
9ffd738f4d [syntax-map] Add a test for inout in its correct position 2016-08-09 12:17:36 -07:00
Ben Langmuir
74113f92ce [syntax-map] Fix array-of-object-literal syntax map, argument label keywords
Argument labels are allowed to use keywords, in which case we want to
treat them as identifiers in the syntax map (except for '_'). This
commit moves calculation of that into the original lexing instead of
in the model walker, which makes it much more robust, since the model
walker was only guessing about what was next on the the TokenNodes list.

This fixes a bug where arrays of object literals would only have the
first object correct (the following ones were identifiers), as well as
some incorrect cases where we treated keywords as identifiers.

rdar://problem/27726422
2016-08-09 10:25:42 -07:00