View Source cure_lsp_type_holes (cure v0.7.0)

Type Holes - Interactive Type Inference

Provides Idris-style type holes where you can write:

  • ?hole - Named hole (e.g., ?returnType)
  • _ - Anonymous hole

Features

  1. Hover on hole - Shows inferred type
  2. Code action - "Fill in hole with: List(Int)"
  3. SMT-based inference - Uses type checker + constraint solving

Usage Examples

Return Type Hole

def double_list(numbers: List(Int)): ? =
    map(numbers, fn(x) -> x * 2 end)
    
% Hover shows: ?returnType :: List(Int)
% Code action: Fill in return type

Parameter Type Hole

def process(x: _): Int =
    x + 1
    
% Infers: x :: Int

Expression Type Hole

let result: ? = compute_value()
% Shows inferred type from compute_value

Implementation

Type holes are detected during parsing and marked in the AST. The LSP provides:

  1. Diagnostics (info-level) for each hole
  2. Hover information with inferred type
  3. Code action to fill in the type

Summary

Functions

find_type_holes/1

-spec find_type_holes(term()) ->
                         [{atom(), term(), #location{line :: term(), column :: term(), file :: term()}}].

format_inferred_type/1

generate_hole_code_actions(Uri, Diagnostic, AST)

-spec generate_hole_code_actions(binary(), map(), term()) -> [map()].

generate_hole_diagnostics(Uri, AST)

-spec generate_hole_diagnostics(binary(), term()) -> [map()].

generate_hole_hover(Line, Character, AST)

-spec generate_hole_hover(integer(), integer(), term()) -> map() | undefined.

hole_name/1

infer_from_context(Hole, AST, State)

-spec infer_from_context(term(), term(), map()) -> {ok, term()} | {error, term()}.

infer_hole_type/3

-spec infer_hole_type(term(), term(), map()) -> {ok, term()} | {error, term()}.

is_type_hole/1

-spec is_type_hole(term()) -> boolean().