From c31b24c100859d8027e5f3ea1986b99fbd5dad69 Mon Sep 17 00:00:00 2001 From: Sarrus1 Date: Mon, 22 Jul 2024 20:57:34 -0700 Subject: [PATCH] fix #412 --- CHANGELOG.md | 1 + Cargo.lock | 4 +- crates/hir-def/src/body/lower.rs | 10 +++-- .../text_document/goto_definition/arrays.rs | 16 ++++++++ ...finition__arrays__array_declaration_2.snap | 40 +++++++++++++++++++ crates/syntax/src/generated.rs | 2 +- 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 crates/sourcepawn-studio/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__arrays__array_declaration_2.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index d4486b118..ed5d53e30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/Cargo.lock b/Cargo.lock index f58525155..1f5348d81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2855,8 +2855,8 @@ dependencies = [ [[package]] name = "tree-sitter-sourcepawn" -version = "0.7.5" -source = "git+https://github.com/nilshelmig/tree-sitter-sourcepawn#645d093763bcaaf7535edbdf6575a5c978b16491" +version = "0.7.6" +source = "git+https://github.com/nilshelmig/tree-sitter-sourcepawn#6b9bf9cbab91443380d2ca8a2f6c491cc7fac5bf" dependencies = [ "cc", "tree-sitter", diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index 23e63040c..9c448164e 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -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); @@ -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); @@ -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) } diff --git a/crates/sourcepawn-studio/tests/text_document/goto_definition/arrays.rs b/crates/sourcepawn-studio/tests/text_document/goto_definition/arrays.rs index d3fbff602..b85db06dd 100644 --- a/crates/sourcepawn-studio/tests/text_document/goto_definition/arrays.rs +++ b/crates/sourcepawn-studio/tests/text_document/goto_definition/arrays.rs @@ -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( diff --git a/crates/sourcepawn-studio/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__arrays__array_declaration_2.snap b/crates/sourcepawn-studio/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__arrays__array_declaration_2.snap new file mode 100644 index 000000000..d6a7973ea --- /dev/null +++ b/crates/sourcepawn-studio/tests/text_document/goto_definition/snapshots/main__text_document__goto_definition__arrays__array_declaration_2.snap @@ -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 + } + } + } +] diff --git a/crates/syntax/src/generated.rs b/crates/syntax/src/generated.rs index 0e5480607..338be7dfa 100644 --- a/crates/syntax/src/generated.rs +++ b/crates/syntax/src/generated.rs @@ -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) } }