Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion TypedSyntax/src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,21 @@ function type_annotation_mode(node, @nospecialize(T); type_annotations::Bool, hi
return type_annotate, pre, pre2, post
end

"""
type_string(type)

Overload this function to implement custom annotations for types. For example,
`type_string(::Type{Float32}) = "F32"` would result in `F32` being used to annotate
any instance of a `Float32`.
"""
type_string(T) = string(T)

function show_annotation(io, @nospecialize(T), post, node, position; iswarn::Bool)
diagnostics = get(io, :diagnostics, nothing)
inlay_hints = get(io, :inlay_hints, nothing)

print(io, post)
T_str = string(T)
T_str = type_string(T)
if iswarn && is_type_unstable(T)
color = is_small_union_or_tunion(T) ? :yellow : :red
printstyled(io, "::", T_str; color)
Expand Down
1 change: 1 addition & 0 deletions src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using REPL: REPL, AbstractTerminal
using JuliaSyntax
using JuliaSyntax: SyntaxNode, AbstractSyntaxNode, child, children
using TypedSyntax
using TypedSyntax: type_string
using WidthLimitedIO

using Core: MethodInstance, MethodMatch
Expand Down