Skip to content

Commit

Permalink
ensure proper alignment between the scope support map and the tree-si…
Browse files Browse the repository at this point in the history
…tter query file. Here are the key changes made:

1. In swift.ts:
Removed all iteration-specific scopes
Simplified to use base scope types only
Removed unsupported Swift-specific scopes
Kept only standard scope types that are documented and used across languages
In swift.scm:
Removed @textFragment annotations
Simplified function declarations to use standard @namedFunction
Updated dictionary key-value pairs to use standard @key and @value
Removed iteration-specific scopes
Updated argument handling to use @argument.actual and @argument.formal
Removed operator-specific annotations
Simplified branch and condition handling
Removed all iteration scopes for blocks, classes, and file-level
  • Loading branch information
atacan committed Jan 18, 2025
1 parent e01350e commit 1110787
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 176 deletions.
104 changes: 11 additions & 93 deletions packages/common/src/scopeSupportFacets/swift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,121 +7,39 @@ export const swiftScopeSupport: LanguageScopeSupportFacetMap = {
// Collections
list: supported,
map: supported,
"key.mapPair": supported,
"key.mapPair.iteration": supported,
key: supported,

// Control flow
ifStatement: supported,
switchStatementSubject: supported,

branch: supported,
condition: supported,

// Text fragments
"textFragment.string.singleLine": supported,
"textFragment.string.multiLine": supported,
"textFragment.comment.line": supported,
"textFragment.comment.block": supported,
string: supported,
comment: supported,

// Statements and blocks
statement: supported,
"statement.iteration.document": supported,
"statement.iteration.block": supported,

// Classes and types
class: supported,
className: supported,
type: supported,

// Functions
anonymousFunction: supported,
namedFunction: supported,
"namedFunction.iteration": supported,
"namedFunction.iteration.document": supported,
"namedFunction.method": supported,
"namedFunction.method.iteration.class": supported,
"namedFunction.constructor": supported,

// Function names
functionName: supported,
"functionName.iteration": supported,
"functionName.iteration.document": supported,
"functionName.method": supported,
"functionName.method.iteration.class": supported,
"functionName.constructor": supported,

// Function calls
functionCall: supported,
"functionCall.constructor": supported,
functionCallee: supported,
"functionCallee.constructor": supported,

// Arguments and parameters
"argument.actual": supported,
"argument.actual.iteration": supported,
"argument.actual.method": supported,
"argument.actual.method.iteration": supported,
"argument.actual.constructor": supported,
"argument.actual.constructor.iteration": supported,
"argument.formal": supported,
"argument.formal.iteration": supported,
"argument.formal.method": supported,
"argument.formal.method.iteration": supported,
"argument.formal.constructor": supported,
"argument.formal.constructor.iteration": supported,

// Comments
"comment.line": supported,
"comment.block": supported,

// Strings
"string.singleLine": supported,
"string.multiLine": supported,

// Branches
"branch.if": supported,
"branch.if.iteration": supported,
"branch.try": supported,
"branch.switchCase": supported,
"branch.switchCase.iteration": supported,
"branch.ternary": notApplicable, // Swift doesn't have ternary operators in the same way

// Conditions
"condition.if": supported,
"condition.while": supported,
"condition.doWhile": supported,
"condition.for": supported,
"condition.ternary": notApplicable,
"condition.switchCase": supported,

// Names
"name.argument.formal": supported,
"name.argument.formal.iteration": supported,
"name.argument.formal.method": supported,
"name.argument.formal.method.iteration": supported,
"name.argument.formal.constructor": supported,
"name.argument.formal.constructor.iteration": supported,
"name.foreach": supported,
"name.assignment": supported,
"name.assignment.pattern": supported,
"name.variable": supported,
"name.variable.pattern": supported,
"name.function": supported,
"name.method": supported,
"name.constructor": supported,
"name.class": supported,
"name.field": supported,
"argument.actual": supported,

// Types
"type.argument.formal": supported,
"type.argument.formal.iteration": supported,
"type.argument.formal.method": supported,
"type.argument.formal.method.iteration": supported,
"type.argument.formal.constructor": supported,
"type.argument.formal.constructor.iteration": supported,
"type.return": supported,
"type.field": supported,
"type.interface": supported,
"type.variable": supported,
// Names and values
name: supported,
value: supported,

// Swift-specific features
disqualifyDelimiter: supported,
fieldAccess: supported,
regularExpression: notApplicable, // Swift doesn't have regex literals
};
103 changes: 20 additions & 83 deletions queries/swift.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
] @statement

;; String literals
(line_string_literal) @string @textFragment
(line_string_literal) @string

;; Comments
[
(line_comment)
(multiline_comment)
] @comment @textFragment
] @comment

;; Class declarations
(class_declaration
Expand All @@ -40,15 +40,15 @@
;; Function declarations
(function_declaration
name: (_) @functionName
) @namedFunction @functionName.domain
) @namedFunction @_.domain

;; Method declarations in classes/protocols
(function_declaration
name: (_) @functionName
) @namedFunction.method @functionName.method.domain
) @namedFunction @_.domain

;; Initializer declarations
(initializer_declaration) @namedFunction.constructor @functionName.constructor.domain
(initializer_declaration) @namedFunction @_.domain

;; Anonymous functions (closures)
(closure_expression) @anonymousFunction
Expand All @@ -67,50 +67,30 @@

;; Dictionary key-value pairs
(dictionary_element
key: (_) @key.mapPair @value.leading.endOf
value: (_) @value @key.mapPair.trailing.startOf
key: (_) @key @value.leading.endOf
value: (_) @value @key.trailing.startOf
) @_.domain

;; Control flow
(if_statement) @ifStatement

;; Switch statement and cases
(switch_statement
condition: (_) @private.switchStatementSubject
condition: (_) @condition
) @_.domain

(switch_case
value: (_) @condition
) @branch @condition.domain
) @branch @_.domain

(default_case) @branch

(switch_statement) @branch.iteration @condition.iteration

;; If statement branches
(if_statement
condition: (_) @condition
body: (_) @branch.end.endOf @branch.removal.end.endOf
alternative: (_
(if_statement) @branch.removal.end.startOf
)?
) @branch.start.startOf @branch.removal.start.startOf @condition.domain

;; Else if branches
(else_clause
(if_statement
condition: (_) @condition
body: (_) @branch.end.endOf @condition.domain.end.endOf
)
) @branch.start.startOf @condition.domain.start.startOf

;; Else branches
(else_clause
(code_block)
) @branch

;; If statement iteration
(if_statement) @branch.iteration
body: (_) @branch
alternative: (_)? @branch
) @_.domain

;; Try-catch blocks
(do_statement
Expand All @@ -120,21 +100,6 @@

(catch_clause) @branch

(do_statement) @branch.iteration

;; Conditions
(if_statement
condition: (_) @condition
) @_.domain

(while_statement
condition: (_) @condition
) @_.domain

(guard_statement
condition: (_) @condition
) @_.domain

;; Parameters
(parameter
name: (_) @name
Expand All @@ -158,50 +123,22 @@
return_type: (_) @type
) @_.domain

;; Operators that should be disqualified as delimiters
operator: [
"<"
"<="
">"
">="
] @disqualifyDelimiter

;; Function arguments
(call_expression
arguments: (tuple_expression
(_)? @_.leading.endOf
.
(_) @argumentOrParameter
(_) @argument.actual
.
(_)? @_.trailing.startOf
)
) @_.domain

;; Parameter list iteration scope
;; Function parameters
(parameter_clause
"(" @argumentOrParameter.iteration.start.endOf
")" @argumentOrParameter.iteration.end.startOf
) @argumentOrParameter.iteration.domain

;; Argument list iteration scope
(call_expression
arguments: (tuple_expression
"(" @argumentOrParameter.iteration.start.endOf
")" @argumentOrParameter.iteration.end.startOf
)
) @argumentOrParameter.iteration.domain

;; Block iteration scopes
(code_block
"{" @statement.iteration.start.endOf @name.iteration.start.endOf @value.iteration.start.endOf @type.iteration.start.endOf
"}" @statement.iteration.end.startOf @name.iteration.end.startOf @value.iteration.end.startOf @type.iteration.end.startOf
)

;; Class/struct body iteration scope
[
(class_declaration)
(struct_declaration)
] @namedFunction.method.iteration.class @functionName.method.iteration.class

;; File-level iteration scope
(source_file) @statement.iteration @name.iteration @value.iteration @type.iteration @namedFunction.iteration @functionName.iteration
(_)? @_.leading.endOf
.
(_) @argument.formal
.
(_)? @_.trailing.startOf
) @_.domain

0 comments on commit 1110787

Please sign in to comment.