mt-lang 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/milk_tea/base.rb +1 -1
- data/lib/milk_tea/core/parser/statements.rb +2 -1
- data/lib/milk_tea/lsp/server/hover.rb +65 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 440292bdf9bb8c311ff6172c6b063defbae416862b2f3369b70c4249bcc09f37
|
|
4
|
+
data.tar.gz: 4793a630eff4f1672659c682e3fb9df769e6d7aaf20facc3742216b7af8fe388
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba82f455b038f4bfcf2b3d2748db4327fec835bf676f854578aca8c21f5614836b693385c70679cbece42917a7a2093a405029f4e6b7a7fa9dcb2c0a1af13257
|
|
7
|
+
data.tar.gz: 51f8316e7466ae58c141168a3f350c2104fc61a859d41e1a21316a7d56c11d7ea0ca49113f7c6aa69fe9bf2a06c055ff6d6d94fa0d931096d76ddc1e38610ccd
|
data/lib/milk_tea/base.rb
CHANGED
|
@@ -87,6 +87,7 @@ module MilkTea
|
|
|
87
87
|
|
|
88
88
|
def parse_local_decl(kind)
|
|
89
89
|
line = previous.line
|
|
90
|
+
column = previous.column
|
|
90
91
|
name_token = nil
|
|
91
92
|
name = nil
|
|
92
93
|
var_type = nil
|
|
@@ -145,7 +146,7 @@ module MilkTea
|
|
|
145
146
|
consume_end_of_statement
|
|
146
147
|
end
|
|
147
148
|
|
|
148
|
-
AST::LocalDecl.new(kind:, name:, type: var_type, value:, else_binding:, else_body:, line:, column: name_token&.column ||
|
|
149
|
+
AST::LocalDecl.new(kind:, name:, type: var_type, value:, else_binding:, else_body:, line:, column: name_token&.column || column, destructure_bindings:, destructure_type_name:)
|
|
149
150
|
rescue ParseError => e
|
|
150
151
|
raise unless @recovery_errors && name
|
|
151
152
|
|
|
@@ -224,6 +224,54 @@ module MilkTea
|
|
|
224
224
|
},
|
|
225
225
|
}.freeze
|
|
226
226
|
|
|
227
|
+
BUILTIN_TYPE_DOCS = {
|
|
228
|
+
'bool' => '1-byte boolean: `true` or `false`.',
|
|
229
|
+
'byte' => '8-bit signed integer. Range: -128 to 127.',
|
|
230
|
+
'ubyte' => '8-bit unsigned integer. Range: 0 to 255. Also used for `char` literals like `\'A\'`.',
|
|
231
|
+
'char' => '8-bit character type (alias for `ubyte`).',
|
|
232
|
+
'short' => '16-bit signed integer. Range: -32,768 to 32,767.',
|
|
233
|
+
'ushort' => '16-bit unsigned integer. Range: 0 to 65,535.',
|
|
234
|
+
'int' => '32-bit signed integer. Range: -2,147,483,648 to 2,147,483,647. Default enum backing type.',
|
|
235
|
+
'uint' => '32-bit unsigned integer. Range: 0 to 4,294,967,295.',
|
|
236
|
+
'long' => '64-bit signed integer.',
|
|
237
|
+
'ulong' => '64-bit unsigned integer.',
|
|
238
|
+
'ptr_int' => 'Pointer-sized signed integer. Width matches the target platform pointer size.',
|
|
239
|
+
'ptr_uint' => 'Pointer-sized unsigned integer. Return type for `size_of`, `align_of`, `offset_of`.',
|
|
240
|
+
'float' => '32-bit IEEE 754 single-precision float.',
|
|
241
|
+
'double' => '64-bit IEEE 754 double-precision float.',
|
|
242
|
+
'void' => 'Empty type for functions with no return value. Not a storable type.',
|
|
243
|
+
'str' => 'Non-owning UTF-8 string view (pointer + length). Not null-terminated.',
|
|
244
|
+
'cstr' => 'Null-terminated C string. Used at FFI boundaries.',
|
|
245
|
+
'vec2' => '2-component float vector. Fields: `.x`, `.y`. Supports component-wise arithmetic.',
|
|
246
|
+
'vec3' => '3-component float vector. Fields: `.x`, `.y`, `.z`. Supports component-wise arithmetic and `dot`/`cross`/`length` via `std.linear_algebra`.',
|
|
247
|
+
'vec4' => '4-component float vector. Fields: `.x`, `.y`, `.z`, `.w`. Supports component-wise arithmetic.',
|
|
248
|
+
'ivec2' => '2-component integer vector. Fields: `.x`, `.y`. Supports component-wise arithmetic.',
|
|
249
|
+
'ivec3' => '3-component integer vector. Fields: `.x`, `.y`, `.z`. Supports component-wise arithmetic.',
|
|
250
|
+
'ivec4' => '4-component integer vector. Fields: `.x`, `.y`, `.z`, `.w`. Supports component-wise arithmetic.',
|
|
251
|
+
'mat3' => '3×3 column-major float matrix. Columns: `.col0`–`.col2` (each `vec3`). Supports `identity`, `transpose` via `std.linear_algebra`.',
|
|
252
|
+
'mat4' => '4×4 column-major float matrix. Columns: `.col0`–`.col3` (each `vec4`). Supports `identity`, `transpose` via `std.linear_algebra`.',
|
|
253
|
+
'quat' => 'Quaternion. Fields: `.x`, `.y`, `.z`, `.w`. Layout-compatible with `vec4`. Supports `identity`, `conjugate` via `std.linear_algebra`.',
|
|
254
|
+
'ptr' => 'Generic pointer type: `ptr[T]`. Raw mutable pointer. Requires `unsafe` for indexing, dereference, and arithmetic.',
|
|
255
|
+
'const_ptr' => 'Read-only pointer type: `const_ptr[T]`. Immutable pointer, does not require `unsafe` for dereference.',
|
|
256
|
+
'own' => 'Owning heap pointer: `own[T]`. Auto-dereferences like `ref`. Storable, returnable, and nullable. Allocated via `heap.must_alloc[T](count)`.',
|
|
257
|
+
'ref' => 'Non-null borrow reference: `ref[T]`. Auto-dereferences for member access and method calls. Cannot be stored in module variables or constants.',
|
|
258
|
+
'span' => 'Borrowed pointer-plus-length view: `span[T]`. Constructed via `span[T](data = ..., len = ...)`. Arrays coerce implicitly.',
|
|
259
|
+
'array' => 'Fixed-length array: `array[T, N]`. Constructed via `array[T, N](elements...)`. Omitted trailing elements default to zero.',
|
|
260
|
+
'str_buffer' => 'Fixed-capacity mutable UTF-8 text buffer: `str_buffer[N]`. Methods: `assign`, `append`, `assign_format`, `append_format`, `clear`, `as_str`, `as_cstr`.',
|
|
261
|
+
'atomic' => 'Atomic value for lock-free concurrent access: `atomic[T]`. `T` must be a primitive integer or `bool`. Methods: `load`, `store`, `add`, `sub`, `exchange`. Uses C11 `_Atomic`.',
|
|
262
|
+
'Task' => 'Async task future: `Task[T]`. Returned by `async function`. Use `await` to unwrap, or `aio.wait`/`aio.run` to drive.',
|
|
263
|
+
'Option' => 'Built-in optional type: `Option[T]`. Arms: `some(value: T)` and `none`. Use `let ... else:` or `?` for safe unwrapping.',
|
|
264
|
+
'Result' => 'Built-in result type: `Result[T, E]`. Arms: `success(value: T)` and `failure(error: E)`. Use `let ... else:` or `?` for error propagation.',
|
|
265
|
+
'SoA' => 'Struct-of-Arrays: `SoA[T, N]`. Each struct field becomes a separate array of length `N`. Access `soa[i].field` reads from column `field` at row `i`.',
|
|
266
|
+
'struct_handle' => 'Compile-time handle for a struct type. Obtained via reflection builtins like `fields_of`.',
|
|
267
|
+
'field_handle' => 'Compile-time handle for a struct field. Exposes `.name` and `.type`. Obtained via `field_of` and `fields_of`.',
|
|
268
|
+
'callable_handle' => 'Compile-time handle for a callable declaration. Obtained via `callable_of`. Used with `has_attribute`, `attribute_of`.',
|
|
269
|
+
'attribute_handle' => 'Compile-time handle for an applied attribute. Obtained via `attribute_of` and `attributes_of`. Use `attribute_arg[T]` to read arguments.',
|
|
270
|
+
'member_handle' => 'Compile-time handle for an enum or flags member. Exposes `.name` and `.value`. Obtained via `members_of`.',
|
|
271
|
+
'EventError' => 'Built-in enum returned when event listener capacity is exhausted. Single member: `full`.',
|
|
272
|
+
'Subscription' => 'Opaque handle returned by `event.subscribe`. Pass to `event.unsubscribe` to remove a listener.',
|
|
273
|
+
}.freeze
|
|
274
|
+
|
|
227
275
|
def handle_hover(params)
|
|
228
276
|
stages = new_perf_stages
|
|
229
277
|
total_start = stages ? monotonic_time : nil
|
|
@@ -238,7 +286,16 @@ module MilkTea
|
|
|
238
286
|
token_kind = token&.type || :none
|
|
239
287
|
unless token&.type == :identifier
|
|
240
288
|
info = builtin_keyword_hover_info(token)
|
|
241
|
-
|
|
289
|
+
if info
|
|
290
|
+
result_state = 'hit'
|
|
291
|
+
return {
|
|
292
|
+
contents: {
|
|
293
|
+
kind: 'markdown',
|
|
294
|
+
value: render_hover_markdown(info)
|
|
295
|
+
},
|
|
296
|
+
range: token_to_range(token)
|
|
297
|
+
}
|
|
298
|
+
end
|
|
242
299
|
|
|
243
300
|
result_state = 'not-identifier'
|
|
244
301
|
return nil
|
|
@@ -369,6 +426,7 @@ module MilkTea
|
|
|
369
426
|
elsif facts.types.key?(name)
|
|
370
427
|
type = facts.types[name]
|
|
371
428
|
signature = type_hover_signature(name, type)
|
|
429
|
+
docs ||= BUILTIN_TYPE_DOCS[name]
|
|
372
430
|
elsif (binding = facts.values[name])
|
|
373
431
|
signature = value_hover_signature(binding)
|
|
374
432
|
elsif (import_binding = facts.imports[name])
|
|
@@ -386,6 +444,7 @@ module MilkTea
|
|
|
386
444
|
signature = value_hover_signature(val)
|
|
387
445
|
elsif module_binding.types.key?(name)
|
|
388
446
|
signature = "type #{name}"
|
|
447
|
+
docs ||= BUILTIN_TYPE_DOCS[name]
|
|
389
448
|
elsif (binding = module_binding.interfaces[name])
|
|
390
449
|
signature = interface_signature(binding)
|
|
391
450
|
source_location = module_member_definition_location(uri, module_binding.name, name)
|
|
@@ -1335,7 +1394,7 @@ module MilkTea
|
|
|
1335
1394
|
end
|
|
1336
1395
|
|
|
1337
1396
|
def builtin_type_constructor_hover_info(name, tokens, token_index)
|
|
1338
|
-
return nil unless %w[array span Option Result SoA].include?(name)
|
|
1397
|
+
return nil unless %w[array span Option Result SoA str_buffer].include?(name)
|
|
1339
1398
|
|
|
1340
1399
|
lbracket_index = next_non_trivia_token_index(tokens, token_index + 1)
|
|
1341
1400
|
return nil unless lbracket_index && tokens[lbracket_index].type == :lbracket
|
|
@@ -1387,8 +1446,10 @@ module MilkTea
|
|
|
1387
1446
|
when 'Option'
|
|
1388
1447
|
'`Option[T]` is the built-in optional value type with `some(value = ...)` and `none` arms.'
|
|
1389
1448
|
when 'Result'
|
|
1390
|
-
|
|
1391
|
-
|
|
1449
|
+
'`Result[T, E]` is the built-in success/failure type with `success(value = ...)` and `failure(error = ...)` arms.'
|
|
1450
|
+
when 'str_buffer'
|
|
1451
|
+
'`str_buffer[N]` is a fixed-capacity mutable UTF-8 text buffer. Methods: `assign`, `append`, `assign_format`, `append_format`, `clear`, `len`, `as_str`, `as_cstr`.'
|
|
1452
|
+
end
|
|
1392
1453
|
|
|
1393
1454
|
{
|
|
1394
1455
|
signature: "builtin type #{specialization}",
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mt-lang
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Long (Teefan) Tran
|
|
@@ -583,7 +583,7 @@ metadata:
|
|
|
583
583
|
homepage_uri: https://teefan.github.io/mt-lang/
|
|
584
584
|
source_code_uri: https://github.com/teefan/mt-lang
|
|
585
585
|
post_install_message: |
|
|
586
|
-
Milk Tea 0.2.
|
|
586
|
+
Milk Tea 0.2.11 installed!
|
|
587
587
|
|
|
588
588
|
System requirements:
|
|
589
589
|
- A C compiler (gcc or clang) must be available on PATH
|