Commit Graph

56 Commits

Author SHA1 Message Date
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Allan Shortlidge
332d770a5c IDE: Stop requiring availability platforms to be classified as keywords. 2025-02-26 18:02:00 -08:00
Rintaro Ishizaki
694e815f07 [Parser] Include all AST nodes from every #if region in ParserUnit
'ParserUnit' is used for analyzing syntax structures _mainly_ in
SourceKit.

Since we removed IfConfigDecl from AST, ParserUnit didn't
inclue any AST in #if ... #endif regions even for active region because
it used to consider all inactive. Instead, consider every region
"active" and include all the AST nodes.

rdar://117387631
2025-02-03 16:22:11 -08:00
Doug Gregor
9936f64c2a Ignore inactive IfConfigDecls in SourceKit's syntax model
Clients that need syntactic information should use SourceKit-LSP or
swift-syntax.
2024-09-07 21:36:39 -07:00
Alex Hoppen
2ff585d6ff [SourceKit] Highlight consuming and borrowing as keywords 2023-06-08 10:59:42 -07:00
Anthony Latsis
ea7662768e Parse: Use TypeRepr * instead of DeclNameRef in a note that points to an extension 2023-01-07 07:11:29 +03:00
Anthony Latsis
a8b83b4e06 Gardening: Migrate test suite to GH issues: SourceKit 2022-09-22 03:21:39 +03:00
Alex Hoppen
fa75cfba72 Merge pull request #60210 from ahoppen/pr/operator-syntax-kind
[SourceKit] Add an operator syntax kind
2022-08-02 19:33:36 +02:00
Alex Hoppen
83380f2682 [SourceKit] Register await as a contextual keyword
`await` in an expresssion should be marked as a contextual keyword, not as an identifier

Resolves apple/sourcekit-lsp#591
2022-07-25 10:26:44 +02:00
Alex Hoppen
a7dcd4604e [SourceKit] Add an operator syntax kind
This will allow us to do semantic highlighting for operators in SourceKit-LSP.
2022-07-25 07:19:49 +02:00
Ben Barham
862f3fc420 [Parse] Set missing contextual keyword token kind for async
Resolves rdar://93080331.
2022-05-13 18:42:09 -07:00
fwcd
9f21b4a2f6 Fix remaining SourceKit tests 2021-05-08 00:40:53 +02:00
fwcd
8d35ed0fe9 Update diags in SourceKit tests to include key.id
- Update SourceKit/DocumentStructure tests
- Update SourceKit/CursorInfo tests
- Update SourceKit/SyntaxMapData tests
- Update SourceKit/Sema tests
- Update SourceKit/CompileNotifications tests
2021-05-07 19:32:04 +02:00
Dmitri Gribenko
b6d0ef5c81 Remove support for a broken std::regex in libstdc++ 4.8
Out of all operating systems ever supported by Swift, only Ubuntu 14.04
had libstdc++ 4.8, and Swift has sunset support for Ubuntu 14.04 for a
while now.
2020-05-19 17:20:55 +02:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Rintaro Ishizaki
aee280ad65 [SourceKit/Testing] Add %diff as an alias for 'diff --strip-trailing-cr' 2020-04-08 11:23:48 -07:00
Saleem Abdulrasool
2265d6e891 tests: adjust the SourceKit tests for line endings (NFCI)
This adjusts the tests for the difference between line endings on
different platforms.  Windows uses CRLF while most Unicies use LF.  This
was exposed during the update to the new LLVM snapshot.
2020-01-14 08:05:34 -08:00
Marcelo Fabri
cab4968da3 [SR-9740][SourceKit] Mark types inside enum case decl as typeidentifiers 2019-01-24 09:14:11 -08:00
Marcelo Fabri
d948823d89 [SR-9576][SourceKit] Fix syntax type when rethrows is present 2019-01-22 20:26:23 -08: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
6bc1b5a389 [libSyntax] Add test variants for building the syntax map via libSyntax 2018-07-13 17:57:00 -07:00
Rintaro Ishizaki
4a247efc0a [Parse] Parse label in tuple type as tok::identifier
Made an utility method 'consumeArgumentLabel', and use it for:
* Labels in tuple type
* Labels in tuple expression
* Argument and parameter names in parameter clause
2018-05-22 13:46:42 +09:00
Rintaro Ishizaki
4c11cf964a [SourceKit] Add SyntaxMap test case for keyword in argument label position 2018-05-22 13:46:32 +09:00
John Fairhurst
677491fc9b [SourceKit] Add syntaxtype for #error/#warning (#14742) 2018-02-21 14:48:18 -08:00
Nathan Hawes
82d8ad2b55 [test] Update syntaxmap test to account for upstream changes 2017-09-15 10:56:01 -07:00
Nathan Hawes
5b82a25240 [SyntaxColoring] Fix losing syntax highlighting for a type or function declaration following an incomplete function decl missing a closing parenthesis
If an edit didn't intersect with an existing highlighted tokens but caused a
later highlighted token to change kind, syntax highlighting would be lost
between the edit and that token.

Resolves rdar://problem/33463141.
2017-09-14 21:36:13 -07:00
Nathan Hawes
c0ee62be93 [syntax-coloring|test] Update test cases for new behaviour and address review comments 2017-09-14 21:34:22 -07:00
Nathan Hawes
f64a19bbbe [syntax-coloring] Relax the requirement that the reported affected range extends to line boundaries
The editor is now assumed to handle affected ranges that don't fall on line boundaries.
2017-09-14 21:34:22 -07:00
Nathan Hawes
13874d3f12 [syntax-coloring] Remove early exit from delta logic when there are no new highlighted tokens but are removed ones, and take account of the range of the mismatching token in the previous syntax map
We still need to adjust the affected range to the line boundaries and return all
tokens on the line when there are no new tokens, as the client will clear all
tokens on that line in its copy of the syntax map leaving the other tokens
unhighlighted. We also need to extend the affected range to include the ranges
of the mismatched tokens from the previous syntaxmap, so their highlighting will
be cleared.

Also add more comments to better document the new syntax map structure and
behaviour.
2017-09-14 21:34:22 -07:00
Nathan Hawes
391b0d860d [syntax-coloring] Add test with nested tokens 2017-09-14 21:34:22 -07:00
Nathan Hawes
77d502cb39 [syntax-coloring] Fix incorrectly reporting a no-op when a token is removed 2017-09-14 21:34:21 -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
Nathan Hawes
6b9690ac5c [syntax-coloring] Rework the syntax map to use offset+length rather than start/end line+column and simplify the delta logic
This patch changes the syntax map data structure it uses to be offset based
rather than line/col based in order to avoid calling getLineAndColumn for the
start and end offset of every token. This removes the 30% of time spent in
getLineAndColumn for this request in large files (rdar://problem/28965123).

The logic for returning the affected range and the token ranges to highlight
following an edit also made several assumptions that no longer hold. This
patch changes it to compare the syntax maps from before and after the edit,
find the first mismtaching tokens from the start and end of the syntax maps
and return the tokens in that range (adjusted to line boundaries). This fixes
syntax highlighting issues with interpolated multi-line strings
(rdar://problem/32148117) and block comments.

With the above changes the per-keystroke time spent for syntax highlighting
(with sematic info disabled) dropped from ~80ms to just under 50ms for a
12KLOC file.
2017-09-14 21:34:21 -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
Argyrios Kyrtzidis
0cfc56ec04 [SourceKit] If diagnostics are 'stale' for a particular snapshot then ignore them and only return the syntactic parser diagnostics (#10388)
This makes sure that diagnostics returned for a particular state of source buffer are consistent and accurate.
rdar://32769873
2017-06-20 12:26:32 -07:00
Nathan Hawes
3791e12895 [syntax-coloring] Remove early exit from delta logic when there are no new highlighted tokens but are removed ones, and take account of the range of the mismatching token in the previous syntax map
We still need to adjust the affected range to the line boundaries and return all
tokens on the line when there are no new tokens, as the client will clear all
tokens on that line in its copy of the syntax map leaving the other tokens
unhighlighted. We also need to extend the affected range to include the ranges
of the mismatched tokens from the previous syntaxmap, so their highlighting will
be cleared.

Also add more comments to better document the new syntax map structure and
behaviour.
2017-06-19 11:45:08 -07:00
Nathan Hawes
04674ffd9c [syntax-coloring] Add test with nested tokens 2017-06-15 13:16:05 -07:00
Nathan Hawes
1158137d95 [syntax-coloring] Fix incorrectly reporting a no-op when a token is removed 2017-06-15 13:16:04 -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
09cb55ebf3 [syntax-coloring] Rework the syntax map to use offset+length rather than start/end line+column and simplify the delta logic
This patch changes the syntax map data structure it uses to be offset based
rather than line/col based in order to avoid calling getLineAndColumn for the
start and end offset of every token. This removes the 30% of time spent in
getLineAndColumn for this request in large files (rdar://problem/28965123).

The logic for returning the affected range and the token ranges to highlight
following an edit also made several assumptions that no longer hold. This
patch changes it to compare the syntax maps from before and after the edit,
find the first mismtaching tokens from the start and end of the syntax maps
and return the tokens in that range (adjusted to line boundaries). This fixes
syntax highlighting issues with interpolated multi-line strings
(rdar://problem/32148117) and block comments.

With the above changes the per-keystroke time spent for syntax highlighting
(with sematic info disabled) dropped from ~80ms to just under 50ms for a
12KLOC file.
2017-06-15 13:15:43 -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
Rintaro Ishizaki
9eee4adc91 [Parse] Parameter list parsing cleanup
* Removed `parseConstructorArguments()`, unified with
  `parseSingleParameterClause()`.
* Use `parseSingleParameterClause()` from `parseFunctionSignature()`, so
  that we can share the recovery code.
* Removed `isFirstParameterClause` parameter from `mapParsedParameters`,
  because it's predictable from `paramContext`.
2016-12-07 23:20:30 +09: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
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
Xi Ge
3e03b78b77 [SyntaxColoring] Tolerating empty spaces between doc-comment openning… (#3373)
* [SyntaxColoring] Tolerating empty spaces between doc-comment opennings and field keywords. rdar://26310081

* [test] Update test for SourceKit.
2016-07-06 22:41:58 -07:00
Xi Ge
500fdd22d1 [Syntax] Avoid highlighting keyword-like labels in call arguments as … (#3369)
* [Syntax] Avoid highlighting keyword-like labels in call arguments as keywords. rdar://24460689

* [test] Update test for SourceKit.
2016-07-06 22:40:44 -07:00
Brian Croom
98e3ca8bc4 Annotate some SourceKit tests that fail on Linux.
* A bunch of them require objc_interop because they import code containing
  Objective-C.
* Many others fail on Ubuntu 14.04 because the C++ there doesn't have a
  functional std::regex implementation which is required by the
  `complete-test` tool.

It may be possible to adjust some of these tests in the future to not
need these extra requirements, but this is a straightforward way to
clean up Linux test results for now.
2016-06-14 08:55:48 -04:00
David Farler
05235956fc SourceKit: Include up to closing paren in object literals
rdar://problem/26451674
2016-05-24 18:29:01 -07:00