mt-lang 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63970cb18bb8d90aee1270f838e8a6520c0f4bce08871f36ffc53f9cbf11c8a0
4
- data.tar.gz: f0faadd64e77babdde7b98fa2866681d7d8de8749dfb9d5e312a856be795b68d
3
+ metadata.gz: a2b1f14318677bf9232d4163ad6aac3905650056716de05bf89762f08e1aa7d5
4
+ data.tar.gz: af90e63fd1c9fd21f6af721c1c039b61159d931d20eaa3eaca3b41369da053c1
5
5
  SHA512:
6
- metadata.gz: 03fb4af02f332e10f66abe76fd5e79a701f9a29ef91bfd0670e0988e0fd6e82e1424432f3d163b4d8f80330269c0484cc8f54cd20a521d1889e44fa9ecc138ed
7
- data.tar.gz: a40c9ba93dfeb52a6752f33cba2365e4f941f1f7bee992ddb80eb6702f051b3830acbf79cce8c0c1bc6f3fe2a99d15d21ca827e1f3d9ef0e03c446dca8ead2d8
6
+ metadata.gz: cef8b0d7f55c4d9496f41d02b0ace0df87f233ff8c24892768543ff3518e68271a2e4613a7654cef661506d42835d1ea8baa9b3d84225614aae420c0d105a0a4
7
+ data.tar.gz: b55024abb91b7fdf2694b4be82bf972f1410aa01b949952d30fb49be517fddd501467ebc55fcf3a6dc1a1eb01334709aa74c26a231348026e3197cc5b163b74c
data/lib/milk_tea/base.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "pathname"
4
4
 
5
5
  module MilkTea
6
- VERSION = "0.2.16"
6
+ VERSION = "0.2.17"
7
7
 
8
8
  def self.root
9
9
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
@@ -122,6 +122,15 @@ module MilkTea
122
122
  start_line = [binding.ast.respond_to?(:line) ? binding.ast.line : nil, snapshots.first.line].compact.min
123
123
  end_line = snapshots.last.line
124
124
 
125
+ # Generic function bodies are not analysed during structural checking,
126
+ # so the frame only has the initial snapshot at the declaration line.
127
+ # Extend end_line to cover the actual body so that completion and hover
128
+ # lookups for parameters resolve correctly inside the body.
129
+ if snapshots.length == 1 && binding.ast.respond_to?(:body) && binding.ast.body
130
+ body_end = last_ast_line(binding.ast.body)
131
+ end_line = body_end if body_end && body_end > end_line
132
+ end
133
+
125
134
  @local_completion_frames << LocalCompletionFrame.new(
126
135
  start_line:,
127
136
  end_line:,
@@ -350,6 +359,34 @@ module MilkTea
350
359
  end
351
360
  end
352
361
 
362
+ # Returns the highest line number across a list of AST statement nodes,
363
+ # recursing into nested bodies (if/else/match/while/for/defer/unsafe).
364
+ def last_ast_line(statements)
365
+ return nil if statements.nil? || statements.empty?
366
+
367
+ statements.filter_map do |stmt|
368
+ case stmt
369
+ when AST::IfStmt
370
+ branch_lines = stmt.branches.filter_map { |b| last_ast_line(b.body) }
371
+ else_lines = last_ast_line(stmt.else_body)
372
+ [stmt.line, *branch_lines, else_lines].compact.max
373
+ when AST::WhileStmt, AST::ForStmt, AST::UnsafeStmt, AST::ErrorBlockStmt
374
+ [stmt.respond_to?(:line) ? stmt.line : nil, last_ast_line(stmt.body)].compact.max
375
+ when AST::MatchStmt
376
+ arm_lines = stmt.arms.filter_map { |arm| last_ast_line(arm.body) }
377
+ [stmt.line, *arm_lines].compact.max
378
+ when AST::DeferStmt
379
+ [stmt.respond_to?(:line) ? stmt.line : nil, last_ast_line(stmt.body)].compact.max
380
+ when AST::WhenStmt
381
+ branch_lines = stmt.branches.filter_map { |b| last_ast_line(b.body) }
382
+ else_lines = last_ast_line(stmt.else_body)
383
+ [stmt.line, *branch_lines, else_lines].compact.max
384
+ else
385
+ stmt.respond_to?(:line) ? stmt.line : nil
386
+ end
387
+ end.compact.max
388
+ end
389
+
353
390
  end
354
391
  end
355
392
  end
@@ -725,6 +725,18 @@ module MilkTea
725
725
  dispatch_receiver_type = method_dispatch_receiver_type_for_completion(receiver_type)
726
726
  receiver_candidates << dispatch_receiver_type if dispatch_receiver_type != receiver_type
727
727
 
728
+ # For GenericInstance or Nullable-wrapped GenericInstance, also try the
729
+ # struct definition from facts.types — method registration keys are
730
+ # always the GenericStructDefinition, not a GenericInstance.
731
+ [dispatch_receiver_type, receiver_type].each do |candidate|
732
+ base = candidate
733
+ base = base.base while base.is_a?(Types::Nullable)
734
+ next unless base.is_a?(Types::GenericInstance)
735
+
736
+ definition = facts.types[base.name]
737
+ receiver_candidates << definition if definition && !receiver_candidates.include?(definition)
738
+ end
739
+
728
740
  receiver_candidates.each do |candidate|
729
741
  facts.methods.fetch(candidate, {}).each do |name, binding|
730
742
  methods[name] ||= binding
@@ -745,10 +757,7 @@ module MilkTea
745
757
  return receiver_type.definition if receiver_type.is_a?(Types::StructInstance) || receiver_type.is_a?(Types::VariantInstance)
746
758
 
747
759
  if receiver_type.is_a?(Types::Nullable)
748
- dispatch_base_type = method_dispatch_receiver_type_for_completion(receiver_type.base)
749
- return receiver_type if dispatch_base_type == receiver_type.base
750
-
751
- return Types::Registry.nullable(dispatch_base_type)
760
+ return method_dispatch_receiver_type_for_completion(receiver_type.base)
752
761
  end
753
762
 
754
763
  return receiver_type unless receiver_type.is_a?(Types::GenericInstance)
@@ -764,6 +773,7 @@ module MilkTea
764
773
  end
765
774
 
766
775
  def project_field_receiver_type_for_completion(type, facts = nil)
776
+ type = type.base while type.is_a?(Types::Nullable)
767
777
  type = project_receiver_type_for_completion(type)
768
778
  return type.definition if type.is_a?(Types::StructInstance) || type.is_a?(Types::VariantInstance)
769
779
  return field_type_from_struct_definition(type, facts) if facts
@@ -100,7 +100,7 @@ module MilkTea
100
100
  extending = nil
101
101
  each_ast_node(ast) do |node|
102
102
  next unless node.is_a?(AST::ExtendingBlock)
103
- if node.line && node.end_line && lsp_line + 1 >= node.line && lsp_line + 1 <= node.end_line
103
+ if node.line && lsp_line + 1 >= node.line && (!node.respond_to?(:end_line) || !node.end_line || lsp_line + 1 <= node.end_line)
104
104
  extending = node
105
105
  end
106
106
  end
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.16
4
+ version: 0.2.17
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.16 installed!
586
+ Milk Tea 0.2.17 installed!
587
587
 
588
588
  System requirements:
589
589
  - A C compiler (gcc or clang) must be available on PATH