diff options
| author | Randy Taylor | 2023-02-08 21:43:04 -0500 |
|---|---|---|
| committer | Dmitry Gutov | 2023-02-14 23:54:58 +0200 |
| commit | a3a1ef7bd5eb7a3b74b0fd80ce78ef234c25f573 (patch) | |
| tree | 28377b638081323ee9ce968d5faeb29e50417bf2 | |
| parent | 477aa047ee73d2b93c04a88700263e58cf7bab70 (diff) | |
| download | emacs-a3a1ef7bd5eb7a3b74b0fd80ce78ef234c25f573.tar.gz emacs-a3a1ef7bd5eb7a3b74b0fd80ce78ef234c25f573.zip | |
Fix rust-ts-mode type and module highlighting (Bug#61302)
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode--font-lock-settings):
Specify import queries to avoid clashing with scoped identifiers in
the code. Highlight attributes with font-lock-preprocessor-face.
| -rw-r--r-- | lisp/progmodes/rust-ts-mode.el | 88 |
1 files changed, 72 insertions, 16 deletions
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el index f709b16ff39..f510b7bb6c9 100644 --- a/lisp/progmodes/rust-ts-mode.el +++ b/lisp/progmodes/rust-ts-mode.el | |||
| @@ -124,8 +124,8 @@ | |||
| 124 | (treesit-font-lock-rules | 124 | (treesit-font-lock-rules |
| 125 | :language 'rust | 125 | :language 'rust |
| 126 | :feature 'attribute | 126 | :feature 'attribute |
| 127 | '((attribute_item) @font-lock-constant-face | 127 | '((attribute_item) @font-lock-preprocessor-face |
| 128 | (inner_attribute_item) @font-lock-constant-face) | 128 | (inner_attribute_item) @font-lock-preprocessor-face) |
| 129 | 129 | ||
| 130 | :language 'rust | 130 | :language 'rust |
| 131 | :feature 'bracket | 131 | :feature 'bracket |
| @@ -148,12 +148,6 @@ | |||
| 148 | '(([(block_comment) (line_comment)]) @font-lock-comment-face) | 148 | '(([(block_comment) (line_comment)]) @font-lock-comment-face) |
| 149 | 149 | ||
| 150 | :language 'rust | 150 | :language 'rust |
| 151 | :feature 'constant | ||
| 152 | `((boolean_literal) @font-lock-constant-face | ||
| 153 | ((identifier) @font-lock-constant-face | ||
| 154 | (:match "^[A-Z][A-Z\\d_]*$" @font-lock-constant-face))) | ||
| 155 | |||
| 156 | :language 'rust | ||
| 157 | :feature 'delimiter | 151 | :feature 'delimiter |
| 158 | '((["," "." ";" ":" "::"]) @font-lock-delimiter-face) | 152 | '((["," "." ";" ":" "::"]) @font-lock-delimiter-face) |
| 159 | 153 | ||
| @@ -211,7 +205,54 @@ | |||
| 211 | 205 | ||
| 212 | :language 'rust | 206 | :language 'rust |
| 213 | :feature 'type | 207 | :feature 'type |
| 214 | `((enum_variant name: (identifier) @font-lock-type-face) | 208 | `((scoped_use_list path: (identifier) @font-lock-constant-face) |
| 209 | (scoped_use_list path: (scoped_identifier | ||
| 210 | name: (identifier) @font-lock-constant-face)) | ||
| 211 | |||
| 212 | ((use_as_clause alias: (identifier) @font-lock-type-face) | ||
| 213 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 214 | ((use_as_clause path: (identifier) @font-lock-type-face) | ||
| 215 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 216 | ((use_as_clause path: | ||
| 217 | (scoped_identifier path: (_) | ||
| 218 | name: (identifier) @font-lock-type-face)) | ||
| 219 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 220 | (use_as_clause path: (scoped_identifier name: (identifier) @default)) | ||
| 221 | |||
| 222 | ((use_declaration | ||
| 223 | argument: (scoped_identifier | ||
| 224 | path: (_) @font-lock-constant-face | ||
| 225 | name: (identifier) @font-lock-type-face)) | ||
| 226 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 227 | (use_declaration | ||
| 228 | argument: (scoped_identifier | ||
| 229 | name: (identifier) @default)) | ||
| 230 | |||
| 231 | (use_declaration | ||
| 232 | argument: (scoped_identifier | ||
| 233 | path: (scoped_identifier | ||
| 234 | path: (_) @font-lock-constant-face | ||
| 235 | name: (identifier) @font-lock-constant-face) | ||
| 236 | name: (identifier) @default)) | ||
| 237 | |||
| 238 | (use_declaration | ||
| 239 | argument: (scoped_use_list | ||
| 240 | path: (scoped_identifier | ||
| 241 | path: (_) @font-lock-constant-face | ||
| 242 | name: (identifier) @font-lock-constant-face))) | ||
| 243 | |||
| 244 | ((use_list (identifier) @font-lock-type-face) | ||
| 245 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 246 | (use_list (identifier) @default) | ||
| 247 | ((use_list (scoped_identifier path: (_) | ||
| 248 | name: (identifier) @font-lock-type-face)) | ||
| 249 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 250 | (use_list (scoped_identifier path: (_) | ||
| 251 | name: (identifier) @default)) | ||
| 252 | (use_wildcard (scoped_identifier | ||
| 253 | name: (identifier) @font-lock-constant-face)) | ||
| 254 | |||
| 255 | (enum_variant name: (identifier) @font-lock-type-face) | ||
| 215 | (match_arm | 256 | (match_arm |
| 216 | pattern: (match_pattern (_ type: (identifier) @font-lock-type-face))) | 257 | pattern: (match_pattern (_ type: (identifier) @font-lock-type-face))) |
| 217 | (match_arm | 258 | (match_arm |
| @@ -226,24 +267,39 @@ | |||
| 226 | ((scoped_identifier path: (identifier) @font-lock-type-face) | 267 | ((scoped_identifier path: (identifier) @font-lock-type-face) |
| 227 | (:match "^[A-Z]" @font-lock-type-face)) | 268 | (:match "^[A-Z]" @font-lock-type-face)) |
| 228 | ((scoped_identifier | 269 | ((scoped_identifier |
| 229 | (scoped_identifier | ||
| 230 | path: (identifier) @font-lock-type-face)) | ||
| 231 | (:match "^[A-Z]" @font-lock-type-face)) | ||
| 232 | ((scoped_identifier | ||
| 233 | path: [(identifier) @font-lock-type-face | 270 | path: [(identifier) @font-lock-type-face |
| 234 | (scoped_identifier | 271 | (scoped_identifier |
| 235 | name: (identifier) @font-lock-type-face)]) | 272 | name: (identifier) @font-lock-type-face)]) |
| 236 | (:match "^[A-Z]" @font-lock-type-face)) | 273 | (:match "^[A-Z]" @font-lock-type-face)) |
| 237 | (scoped_type_identifier path: (identifier) @font-lock-type-face) | 274 | ((scoped_identifier path: (identifier) @font-lock-type-face) |
| 275 | (:match | ||
| 276 | "^\\(u8\\|u16\\|u32\\|u64\\|u128\\|usize\\|i8\\|i16\\|i32\\|i64\\|i128\\|isize\\|char\\|str\\)$" | ||
| 277 | @font-lock-type-face)) | ||
| 278 | (scoped_identifier path: (_) @font-lock-constant-face | ||
| 279 | name: (identifier) @font-lock-type-face) | ||
| 280 | (scoped_identifier path: (scoped_identifier | ||
| 281 | name: (identifier) @font-lock-constant-face)) | ||
| 282 | (scoped_type_identifier path: (_) @font-lock-constant-face) | ||
| 283 | (scoped_type_identifier | ||
| 284 | path: (scoped_identifier | ||
| 285 | path: (_) @font-lock-constant-face | ||
| 286 | name: (identifier) @font-lock-constant-face)) | ||
| 238 | (type_identifier) @font-lock-type-face | 287 | (type_identifier) @font-lock-type-face |
| 239 | (use_as_clause alias: (identifier) @font-lock-type-face) | 288 | ;; Ensure function calls aren't highlighted as types. |
| 240 | (use_list (identifier) @font-lock-type-face)) | 289 | (call_expression function: (scoped_identifier name: (identifier) @default))) |
| 241 | 290 | ||
| 242 | :language 'rust | 291 | :language 'rust |
| 243 | :feature 'property | 292 | :feature 'property |
| 244 | '((field_identifier) @font-lock-property-face | 293 | '((field_identifier) @font-lock-property-face |
| 245 | (shorthand_field_initializer (identifier) @font-lock-property-face)) | 294 | (shorthand_field_initializer (identifier) @font-lock-property-face)) |
| 246 | 295 | ||
| 296 | ;; Must be under type, otherwise some imports can be highlighted as consants. | ||
| 297 | :language 'rust | ||
| 298 | :feature 'constant | ||
| 299 | `((boolean_literal) @font-lock-constant-face | ||
| 300 | ((identifier) @font-lock-constant-face | ||
| 301 | (:match "^[A-Z][A-Z\\d_]*$" @font-lock-constant-face))) | ||
| 302 | |||
| 247 | :language 'rust | 303 | :language 'rust |
| 248 | :feature 'variable | 304 | :feature 'variable |
| 249 | '((identifier) @font-lock-variable-name-face | 305 | '((identifier) @font-lock-variable-name-face |