Skip to content

Commit

Permalink
fix #412
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarrus1 committed Jul 23, 2024
1 parent ba311ba commit c31b24c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Fixed generic events not being included (see #411).
- Fixed missing IntelliSense for some invalid syntax (see #406).
- Fixed static expressions not being evaluated (see #412).

## [0.13.2]

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ impl ExprCollector<'_> {
}
// endregion: Statements
// region: Expressions
TSKind::assignment_expression | TSKind::binary_expression => {
TSKind::assignment_expression
| TSKind::binary_expression
| TSKind::preproc_binary_expression => {
let lhs = self.collect_expr(expr.child_by_field_name("left")?);
let rhs = self.collect_expr(expr.child_by_field_name("right")?);
let op = expr.child_by_field_name("operator").map(TSKind::from);
Expand Down Expand Up @@ -368,7 +370,9 @@ impl ExprCollector<'_> {
};
Some(self.alloc_expr(access, NodePtr::from(&field)))
}
TSKind::unary_expression | TSKind::update_expression => {
TSKind::unary_expression
| TSKind::update_expression
| TSKind::preproc_unary_expression => {
// For our needs, unary and update expressions are the same
let expr = expr.child_by_field_name("argument")?;
let op = expr.child_by_field_name("operator").map(TSKind::from);
Expand Down Expand Up @@ -434,7 +438,7 @@ impl ExprCollector<'_> {
TSKind::null => {
Some(self.alloc_expr(Expr::Literal(Literal::Null), NodePtr::from(&expr)))
}
TSKind::parenthesized_expression => {
TSKind::parenthesized_expression | TSKind::preproc_parenthesized_expression => {
let expr = expr.child_by_field_name("expression")?;
self.maybe_collect_expr(expr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ void foo() {
));
}

#[test]
fn array_declaration_2() {
assert_json_snapshot!(goto_definition(
r#"
%! main.sp
int arr[] =
|
^
{
(0 << 1)
};
"#,
));
}

#[test]
fn array_indexed_access_1() {
assert_json_snapshot!(goto_definition(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
source: crates/sourcepawn-studio/tests/text_document/goto_definition/arrays.rs
assertion_line: 22
expression: "goto_definition(r#\"\n%! main.sp\nint arr[] =\n |\n ^\n{\n\t(0 << 1)\n\n};\n\"#)"
---
[
{
"originSelectionRange": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 0,
"character": 7
}
},
"targetUri": "file:///main.sp",
"targetRange": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 4,
"character": 1
}
},
"targetSelectionRange": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 0,
"character": 7
}
}
}
]
2 changes: 1 addition & 1 deletion crates/syntax/src/generated.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# ! [cfg_attr (rustfmt , rustfmt_skip)] # ! [allow (bad_style , missing_docs , unreachable_pub , unused)] # [derive (Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug)] # [repr (u16)] pub enum TSKind { anon_end = 0 , identifier = 1 , anon_LPAREN = 2 , anon_RPAREN = 3 , anon_BANG = 4 , anon_TILDE = 5 , anon_DASH = 6 , anon_PLUS = 7 , anon_AMP = 8 , anon_DOT_DOT_DOT = 9 , anon_STAR = 10 , anon_SLASH = 11 , anon_PERCENT = 12 , anon_PIPE_PIPE = 13 , anon_AMP_AMP = 14 , anon_PIPE = 15 , anon_CARET = 16 , anon_EQ_EQ = 17 , anon_BANG_EQ = 18 , anon_GT = 19 , anon_GT_EQ = 20 , anon_LT_EQ = 21 , anon_LT = 22 , anon_LT_LT = 23 , anon_GT_GT = 24 , anon_GT_GT_GT = 25 , anon_POUNDinclude = 26 , anon_POUNDtryinclude = 27 , anon_POUNDdefine = 28 , anon_COMMA = 29 , macro_param = 30 , anon_POUNDundef = 31 , anon_POUNDif = 32 , anon_POUNDelseif = 33 , anon_POUNDassert = 34 , anon_defined = 35 , preproc_else = 36 , preproc_endif = 37 , preproc_endinput = 38 , anon_POUNDpragma = 39 , anon_POUNDerror = 40 , anon_POUNDwarning = 41 , anon_using__intrinsics__DOTHandle = 42 , anon_assert = 43 , anon_static_assert = 44 , anon_EQ = 45 , anon_forward = 46 , anon_native = 47 , alias_operator = 48 , anon_operator = 49 , anon_COLON = 50 , anon_const = 51 , anon_public = 52 , anon_stock = 53 , anon_static = 54 , anon_new = 55 , anon_decl = 56 , anon_enum = 57 , anon_PLUS_EQ = 58 , anon_DASH_EQ = 59 , anon_STAR_EQ = 60 , anon_SLASH_EQ = 61 , anon_PIPE_EQ = 62 , anon_AMP_EQ = 63 , anon_CARET_EQ = 64 , anon_TILDE_EQ = 65 , anon_LT_LT_EQ = 66 , anon_GT_GT_EQ = 67 , anon_LBRACE = 68 , anon_RBRACE = 69 , anon_struct = 70 , anon_typedef = 71 , anon_typeset = 72 , anon_function = 73 , anon_funcenum = 74 , anon_functag = 75 , anon_methodmap = 76 , anon___nullable__ = 77 , anon_property = 78 , anon_get = 79 , anon_set = 80 , anon_LBRACK = 81 , anon_RBRACK = 82 , anon_void = 83 , anon_bool = 84 , anon_int = 85 , anon_float = 86 , anon_char = 87 , anon__ = 88 , anon_Float = 89 , anon_String = 90 , any_type = 91 , anon_for = 92 , anon_while = 93 , anon_do = 94 , anon_break = 95 , anon_continue = 96 , anon_if = 97 , anon_else = 98 , anon_switch = 99 , anon_case = 100 , anon_COLON_ = 101 , anon_default_ = 102 , anon_return_ = 103 , anon_delete_ = 104 , anon__manual_semicolon_ = 105 , anon_GT_GT_GT_EQ_ = 106 , anon_PERCENT_EQ_ = 107 , anon_DOT_ = 108 , anon_QMARK_ = 109 , anon_COLON_COLON_ = 110 , anon_DASH_DASH_ = 111 , anon_PLUS_PLUS_ = 112 , anon_sizeof_ = 113 , anon_view_as_ = 114 , int_literal = 115 , float_literal = 116 , anon_SQUOTE_ = 117 , character = 118 , anon_DQUOTE_ = 119 , anon_string_literal_token1_ = 120 , escape_sequence = 121 , bool_literal = 122 , null = 123 , this = 124 , system_lib_string = 125 , comment = 126 , anon__automatic_semicolon_ = 127 , anon__ternary_colon_ = 128 , preproc_arg = 129 , source_file = 130 , preproc_include = 131 , preproc_tryinclude = 132 , preproc_macro = 133 , preproc_define = 134 , preproc_undefine = 135 , preproc_if = 136 , preproc_elseif = 137 , preproc_assert = 138 , preproc_pragma = 139 , preproc_error = 140 , preproc_warning = 141 , hardcoded_symbol = 142 , assertion = 143 , function_definition = 144 , function_declaration = 145 , function_declaration_kind = 146 , parameter_declarations = 147 , parameter_declaration = 148 , rest_parameter = 149 , alias_declaration = 150 , alias_assignment = 151 , global_variable_declaration = 152 , variable_declaration_statement = 153 , variable_storage_class = 154 , visibility = 155 , variable_declaration = 156 , dynamic_array_declaration = 157 , dynamic_array = 158 , new_expression = 159 , old_global_variable_declaration = 160 , old_variable_declaration_statement = 161 , old_for_loop_variable_declaration_statement = 162 , old_variable_declaration = 163 , r#enum = 164 , enum_entries = 165 , enum_entry = 166 , enum_struct = 167 , enum_struct_field = 168 , enum_struct_method = 169 , typedef = 170 , typeset = 171 , typedef_expression = 172 , funcenum = 173 , funcenum_member = 174 , functag = 175 , methodmap = 176 , methodmap_alias = 177 , methodmap_native = 178 , methodmap_native_constructor = 179 , methodmap_native_destructor = 180 , methodmap_method = 181 , methodmap_method_constructor = 182 , methodmap_method_destructor = 183 , methodmap_property = 184 , methodmap_property_alias = 185 , methodmap_property_native = 186 , methodmap_property_method = 187 , methodmap_property_getter = 188 , methodmap_property_setter = 189 , r#struct = 190 , struct_field = 191 , struct_declaration = 192 , struct_constructor = 193 , struct_field_value = 194 , r#type = 195 , array_type = 196 , old_type = 197 , dimension = 198 , fixed_dimension = 199 , builtin_type = 200 , old_builtin_type = 201 , block = 202 , for_statement = 203 , while_statement = 204 , do_while_statement = 205 , break_statement = 206 , continue_statement = 207 , condition_statement = 208 , switch_statement = 209 , switch_case = 210 , expression_statement = 211 , return_statement = 212 , delete_statement = 213 , anon__semicolon_ = 214 , anon__expression_ = 215 , anon__case_expression_ = 216 , assignment_expression = 217 , call_expression = 218 , call_arguments = 219 , named_arg = 220 , ignore_argument = 221 , array_indexed_access = 222 , parenthesized_expression = 223 , comma_expression = 224 , ternary_expression = 225 , field_access = 226 , scope_access = 227 , unary_expression = 228 , case_unary_expression = 229 , binary_expression = 230 , case_binary_expression = 231 , update_expression = 232 , anon__sizeof_call_expression_ = 233 , array_scope_access = 234 , sizeof_expression = 235 , view_as = 236 , old_type_cast = 237 , array_literal = 238 , anon__literal_ = 239 , char_literal = 240 , string_literal = 241 , rest_operator = 242 , anon_source_file_repeat1_ = 243 , anon_preproc_macro_repeat1_ = 244 , anon_function_definition_repeat1_ = 245 , anon_parameter_declarations_repeat1_ = 246 , anon_parameter_declaration_repeat1_ = 247 , anon_global_variable_declaration_repeat1_ = 248 , anon_variable_declaration_statement_repeat1_ = 249 , anon_dynamic_array_repeat1_ = 250 , anon_old_global_variable_declaration_repeat1_ = 251 , anon_enum_entries_repeat1_ = 252 , anon_enum_struct_repeat1_ = 253 , anon_typeset_repeat1_ = 254 , anon_funcenum_repeat1_ = 255 , anon_methodmap_repeat1_ = 256 , anon_methodmap_property_repeat1_ = 257 , anon_struct_repeat1_ = 258 , anon_struct_constructor_repeat1_ = 259 , anon_block_repeat1_ = 260 , anon_for_statement_repeat1_ = 261 , anon_switch_statement_repeat1_ = 262 , anon_switch_case_repeat1_ = 263 , anon_call_arguments_repeat1_ = 264 , anon_array_literal_repeat1_ = 265 , anon_string_literal_repeat1_ = 266 } impl From < tree_sitter :: Node < '_ >> for TSKind { fn from (v : tree_sitter :: Node < '_ >) -> Self { unsafe { :: std :: mem :: transmute (v . kind_id ()) } } } impl From < & tree_sitter :: Node < '_ >> for TSKind { fn from (v : & tree_sitter :: Node < '_ >) -> Self { Self :: from (* v) } }
# ! [cfg_attr (rustfmt , rustfmt_skip)] # ! [allow (bad_style , missing_docs , unreachable_pub , unused)] # [derive (Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug)] # [repr (u16)] pub enum TSKind { anon_end = 0 , identifier = 1 , anon_LPAREN = 2 , anon_RPAREN = 3 , anon_BANG = 4 , anon_TILDE = 5 , anon_DASH = 6 , anon_PLUS = 7 , anon_AMP = 8 , anon_DOT_DOT_DOT = 9 , anon_STAR = 10 , anon_SLASH = 11 , anon_PERCENT = 12 , anon_PIPE_PIPE = 13 , anon_AMP_AMP = 14 , anon_PIPE = 15 , anon_CARET = 16 , anon_EQ_EQ = 17 , anon_BANG_EQ = 18 , anon_GT = 19 , anon_GT_EQ = 20 , anon_LT_EQ = 21 , anon_LT = 22 , anon_LT_LT = 23 , anon_GT_GT = 24 , anon_GT_GT_GT = 25 , anon_POUNDinclude = 26 , anon_POUNDtryinclude = 27 , anon_POUNDdefine = 28 , anon_COMMA = 29 , macro_param = 30 , anon_POUNDundef = 31 , anon_POUNDif = 32 , anon_POUNDelseif = 33 , anon_POUNDassert = 34 , anon_defined = 35 , preproc_else = 36 , preproc_endif = 37 , preproc_endinput = 38 , anon_POUNDpragma = 39 , anon_POUNDerror = 40 , anon_POUNDwarning = 41 , anon_using__intrinsics__DOTHandle = 42 , anon_assert = 43 , anon_static_assert = 44 , anon_EQ = 45 , anon_forward = 46 , anon_native = 47 , alias_operator = 48 , anon_operator = 49 , anon_COLON = 50 , anon_const = 51 , anon_public = 52 , anon_stock = 53 , anon_static = 54 , anon_new = 55 , anon_decl = 56 , anon_enum = 57 , anon_PLUS_EQ = 58 , anon_DASH_EQ = 59 , anon_STAR_EQ = 60 , anon_SLASH_EQ = 61 , anon_PIPE_EQ = 62 , anon_AMP_EQ = 63 , anon_CARET_EQ = 64 , anon_TILDE_EQ = 65 , anon_LT_LT_EQ = 66 , anon_GT_GT_EQ = 67 , anon_LBRACE = 68 , anon_RBRACE = 69 , anon_struct = 70 , anon_typedef = 71 , anon_typeset = 72 , anon_function = 73 , anon_funcenum = 74 , anon_functag = 75 , anon_methodmap = 76 , anon___nullable__ = 77 , anon_property = 78 , anon_get = 79 , anon_set = 80 , anon_LBRACK = 81 , anon_RBRACK = 82 , anon_void = 83 , anon_bool = 84 , anon_int = 85 , anon_float = 86 , anon_char = 87 , anon__ = 88 , anon_Float = 89 , anon_String = 90 , any_type = 91 , anon_for = 92 , anon_while = 93 , anon_do = 94 , anon_break = 95 , anon_continue = 96 , anon_if = 97 , anon_else = 98 , anon_switch = 99 , anon_case = 100 , anon_COLON_ = 101 , anon_default_ = 102 , anon_return_ = 103 , anon_delete_ = 104 , anon__manual_semicolon_ = 105 , anon_GT_GT_GT_EQ_ = 106 , anon_PERCENT_EQ_ = 107 , anon_DOT_ = 108 , anon_QMARK_ = 109 , anon_COLON_COLON_ = 110 , anon_DASH_DASH_ = 111 , anon_PLUS_PLUS_ = 112 , anon_sizeof_ = 113 , anon_view_as_ = 114 , int_literal = 115 , float_literal = 116 , anon_SQUOTE_ = 117 , character = 118 , anon_DQUOTE_ = 119 , anon_string_literal_token1_ = 120 , escape_sequence = 121 , bool_literal = 122 , null = 123 , this = 124 , system_lib_string = 125 , comment = 126 , anon__automatic_semicolon_ = 127 , anon__ternary_colon_ = 128 , preproc_arg = 129 , source_file = 130 , anon__preproc_expression_ = 131 , preproc_parenthesized_expression = 132 , preproc_unary_expression = 133 , preproc_binary_expression = 134 , preproc_include = 135 , preproc_tryinclude = 136 , preproc_macro = 137 , preproc_define = 138 , preproc_undefine = 139 , preproc_if = 140 , preproc_elseif = 141 , preproc_assert = 142 , preproc_defined_condition = 143 , preproc_pragma = 144 , preproc_error = 145 , preproc_warning = 146 , hardcoded_symbol = 147 , assertion = 148 , function_definition = 149 , function_declaration = 150 , function_declaration_kind = 151 , parameter_declarations = 152 , parameter_declaration = 153 , rest_parameter = 154 , alias_declaration = 155 , alias_assignment = 156 , global_variable_declaration = 157 , variable_declaration_statement = 158 , variable_storage_class = 159 , visibility = 160 , variable_declaration = 161 , dynamic_array_declaration = 162 , dynamic_array = 163 , new_expression = 164 , old_global_variable_declaration = 165 , old_variable_declaration_statement = 166 , old_for_loop_variable_declaration_statement = 167 , old_variable_declaration = 168 , r#enum = 169 , enum_entries = 170 , enum_entry = 171 , enum_struct = 172 , enum_struct_field = 173 , enum_struct_method = 174 , typedef = 175 , typeset = 176 , typedef_expression = 177 , funcenum = 178 , funcenum_member = 179 , functag = 180 , methodmap = 181 , methodmap_alias = 182 , methodmap_native = 183 , methodmap_native_constructor = 184 , methodmap_native_destructor = 185 , methodmap_method = 186 , methodmap_method_constructor = 187 , methodmap_method_destructor = 188 , methodmap_property = 189 , methodmap_property_alias = 190 , methodmap_property_native = 191 , methodmap_property_method = 192 , methodmap_property_getter = 193 , methodmap_property_setter = 194 , r#struct = 195 , struct_field = 196 , struct_declaration = 197 , struct_constructor = 198 , struct_field_value = 199 , r#type = 200 , array_type = 201 , old_type = 202 , dimension = 203 , fixed_dimension = 204 , builtin_type = 205 , old_builtin_type = 206 , block = 207 , for_statement = 208 , while_statement = 209 , do_while_statement = 210 , break_statement = 211 , continue_statement = 212 , condition_statement = 213 , switch_statement = 214 , switch_case = 215 , expression_statement = 216 , return_statement = 217 , delete_statement = 218 , anon__semicolon_ = 219 , anon__expression_ = 220 , anon__case_expression_ = 221 , assignment_expression = 222 , call_expression = 223 , call_arguments = 224 , named_arg = 225 , ignore_argument = 226 , array_indexed_access = 227 , parenthesized_expression = 228 , comma_expression = 229 , ternary_expression = 230 , field_access = 231 , scope_access = 232 , unary_expression = 233 , case_unary_expression = 234 , binary_expression = 235 , case_binary_expression = 236 , update_expression = 237 , anon__sizeof_call_expression_ = 238 , array_scope_access = 239 , sizeof_expression = 240 , view_as = 241 , old_type_cast = 242 , array_literal = 243 , anon__literal_ = 244 , char_literal = 245 , string_literal = 246 , rest_operator = 247 , anon_source_file_repeat1_ = 248 , anon_preproc_macro_repeat1_ = 249 , anon_function_definition_repeat1_ = 250 , anon_parameter_declarations_repeat1_ = 251 , anon_parameter_declaration_repeat1_ = 252 , anon_global_variable_declaration_repeat1_ = 253 , anon_variable_declaration_statement_repeat1_ = 254 , anon_dynamic_array_repeat1_ = 255 , anon_old_global_variable_declaration_repeat1_ = 256 , anon_enum_entries_repeat1_ = 257 , anon_enum_struct_repeat1_ = 258 , anon_typeset_repeat1_ = 259 , anon_funcenum_repeat1_ = 260 , anon_methodmap_repeat1_ = 261 , anon_methodmap_property_repeat1_ = 262 , anon_struct_repeat1_ = 263 , anon_struct_constructor_repeat1_ = 264 , anon_block_repeat1_ = 265 , anon_for_statement_repeat1_ = 266 , anon_switch_statement_repeat1_ = 267 , anon_switch_case_repeat1_ = 268 , anon_call_arguments_repeat1_ = 269 , anon_array_literal_repeat1_ = 270 , anon_string_literal_repeat1_ = 271 } impl From < tree_sitter :: Node < '_ >> for TSKind { fn from (v : tree_sitter :: Node < '_ >) -> Self { unsafe { :: std :: mem :: transmute (v . kind_id ()) } } } impl From < & tree_sitter :: Node < '_ >> for TSKind { fn from (v : & tree_sitter :: Node < '_ >) -> Self { Self :: from (* v) } }

0 comments on commit c31b24c

Please sign in to comment.