-
-
Notifications
You must be signed in to change notification settings - Fork 89
Add Swift programming language #2734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
atacan
wants to merge
22
commits into
cursorless-dev:main
Choose a base branch
from
atacan:add-swift
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+480
−0
Open
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c706436
initial edits for Swift language support
atacan c3a0c3c
additional scope features
atacan 37c03d1
replace `collectionKey` with `key.mapPair`
atacan e01350e
remove the Swift-specific type scopes since they're not in the standa…
atacan 1110787
ensure proper alignment between the scope support map and the tree-si…
atacan 3a54328
wip
atacan e9323fe
swift MDX
atacan 3f4506c
deleted
atacan 1655be7
start from scratch
atacan e6b91c8
Add Swift grammar rules and declarations to swift.scm
atacan 231064a
start small
atacan 8a0ddd2
make the function work
atacan f2d8d64
swift.scm by adding class and protocol declarations.
atacan 31d4d2a
full support not-support list
atacan dbda618
Enhance swift.scm by adding support for import, property, typealias, …
atacan a568661
Add support for ternary expressions and enhance comment handling in s…
atacan df4ac3d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 53ec6d1
Add support for switch statements and enhance if/guard statement hand…
atacan 1cc4244
wrong folder?
atacan 93437b6
swift playground
atacan 5a7de2e
Add support for protocol declarations and enhance argument handling i…
atacan 4e7087c
Merge branch 'main' into add-swift
AndreasArvidsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"imports": ["swift"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; | ||
import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; | ||
|
||
const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; | ||
|
||
export const swiftScopeSupport: LanguageScopeSupportFacetMap = { | ||
// Collections | ||
list: supported, | ||
map: supported, | ||
|
||
// Control flow | ||
ifStatement: supported, | ||
"condition.if": supported, | ||
"condition.switchCase": supported, | ||
"condition.switchCase.iteration": supported, | ||
|
||
// Text fragments | ||
"string.singleLine": supported, | ||
"string.multiLine": supported, | ||
"comment.line": supported, | ||
"comment.block": supported, | ||
|
||
// Statements and blocks | ||
statement: supported, | ||
|
||
// Classes and types | ||
class: supported, | ||
className: supported, | ||
"type.class": supported, | ||
"type.variable": supported, | ||
"type.return": supported, | ||
"type.field": supported, | ||
|
||
// Functions | ||
anonymousFunction: supported, | ||
namedFunction: supported, | ||
functionCall: supported, | ||
functionCallee: supported, | ||
|
||
// Arguments and parameters | ||
"argument.formal": supported, | ||
"argument.actual": supported, | ||
|
||
// Names and values | ||
"name.function": supported, | ||
"name.variable": supported, | ||
"name.field": supported, | ||
"value.variable": supported, | ||
"value.field": supported, | ||
|
||
// Swift-specific features | ||
regularExpression: notApplicable, // Swift doesn't have regex literals | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/cursorless-org-docs/src/docs/user/languages/swift.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Language from "./Language"; | ||
|
||
# Swift | ||
|
||
<Language languageId="swift"></Language> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
;; https://github.com/tree-sitter/tree-sitter-swift/blob/master/src/grammar.json | ||
|
||
;; Basic statements and declarations | ||
[ | ||
(function_declaration) | ||
(class_declaration) | ||
(struct_declaration) | ||
(protocol_declaration) | ||
(enum_declaration) | ||
(extension_declaration) | ||
(import_declaration) | ||
(variable_declaration) | ||
(if_statement) | ||
(guard_statement) | ||
(for_statement) | ||
(while_statement) | ||
(repeat_while_statement) | ||
(do_statement) | ||
(return_statement) | ||
(break_statement) | ||
(continue_statement) | ||
(throw_statement) | ||
(switch_statement) | ||
] @statement | ||
|
||
;; String literals | ||
(line_string_literal) @string | ||
|
||
;; Comments | ||
[ | ||
(line_comment) | ||
(multiline_comment) | ||
] @comment | ||
|
||
;; Class declarations | ||
(class_declaration | ||
name: (_) @className | ||
) @class @_.domain | ||
|
||
;; Function declarations | ||
(function_declaration | ||
name: (_) @functionName | ||
) @namedFunction @_.domain | ||
|
||
;; Method declarations in classes/protocols | ||
(function_declaration | ||
name: (_) @functionName | ||
) @namedFunction @_.domain | ||
|
||
;; Initializer declarations | ||
(initializer_declaration) @namedFunction @_.domain | ||
|
||
;; Anonymous functions (closures) | ||
(closure_expression) @anonymousFunction | ||
|
||
;; Function calls | ||
(call_expression) @functionCall | ||
|
||
;; Function callee | ||
(call_expression | ||
function: (_) @functionCallee | ||
) @_.domain | ||
|
||
;; Collections | ||
(array_expression) @list | ||
(dictionary_expression) @map | ||
|
||
;; Dictionary key-value pairs | ||
(dictionary_element | ||
key: (_) @key @value.leading.endOf | ||
value: (_) @value @key.trailing.startOf | ||
) @_.domain | ||
|
||
;; Control flow | ||
(if_statement) @ifStatement | ||
|
||
;; Switch statement and cases | ||
(switch_statement | ||
condition: (_) @condition | ||
) @_.domain | ||
|
||
(switch_case | ||
value: (_) @condition | ||
) @branch @_.domain | ||
|
||
(default_case) @branch | ||
|
||
;; If statement branches | ||
(if_statement | ||
condition: (_) @condition | ||
body: (_) @branch | ||
alternative: (_)? @branch | ||
) @_.domain | ||
|
||
;; Try-catch blocks | ||
(do_statement | ||
"try" @branch.start | ||
body: (_) @branch.end | ||
) | ||
|
||
(catch_clause) @branch | ||
|
||
;; Parameters | ||
(parameter | ||
name: (_) @name | ||
type: (_) @type | ||
) @_.domain | ||
|
||
;; Variable declarations | ||
(variable_declaration | ||
pattern: (_) @name | ||
type: (_)? @type | ||
value: (_)? @value | ||
) @_.domain | ||
|
||
;; Type annotations | ||
(type_annotation | ||
type: (_) @type | ||
) @_.domain | ||
|
||
;; Return type annotations | ||
(function_declaration | ||
return_type: (_) @type | ||
) @_.domain | ||
|
||
;; Function arguments | ||
(call_expression | ||
arguments: (tuple_expression | ||
(_)? @_.leading.endOf | ||
. | ||
(_) @argument.actual | ||
. | ||
(_)? @_.trailing.startOf | ||
) | ||
) @_.domain | ||
|
||
;; Function parameters | ||
(parameter_clause | ||
(_)? @_.leading.endOf | ||
. | ||
(_) @argument.formal | ||
. | ||
(_)? @_.trailing.startOf | ||
) @_.domain |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.