Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Zentrik committed Jun 15, 2023
1 parent 4e86dd2 commit 5a14e88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion TypedSyntax/src/TypedSyntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using CodeTracking
export TypedSyntaxNode

include("node.jl")
include("show.jl")
include("vscode.jl")
include("show.jl")

end
22 changes: 4 additions & 18 deletions TypedSyntax/src/show.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
## Extensions of JuliaSyntax to cover TypedSyntaxNode

# Structs used when using VSCode
struct WarnUnstable
path::String
line::Int
severity::Int # 0: Error, 1: Warning, 2: Information, 3: Hint
end
struct InlayHint
line::Int
column::Int
label::String
kind::Union{Nothing, Int}
end

function Base.show(io::IO, ::MIME"text/plain", node::TypedSyntaxNode; show_byte_offsets=false)
println(io, "line:col│$(show_byte_offsets ? " byte_range │" : "") tree │ type")
JuliaSyntax._show_syntax_node(io, Ref{Union{Nothing,String}}(nothing), node, "", show_byte_offsets)
Expand Down Expand Up @@ -65,14 +52,13 @@ function _printstyled(io::IO, rootnode::MaybeTypedSyntaxNode,
catchup(io, rootnode, position, nd, idxend+1) # finish the node
return nothing
end
function Base.printstyled(io::IO, rootnode::MaybeTypedSyntaxNode;
function Base.printstyled(io::IO, rootnode::MaybeTypedSyntaxNode,
type_hints = Dict{String, Vector{InlayHint}}(),
warn_diagnostics = WarnUnstable[];
type_annotations::Bool=true, iswarn::Bool=true,
hide_type_stable::Bool=true, with_linenumber::Bool=true,
idxend = last_byte(rootnode), vscode_integration=true)
if vscode_integration && isdefined(Main, :VSCodeServer) && Main.VSCodeServer isa Module
type_hints = Dict{String, Vector{InlayHint}}()
warn_diagnostics = WarnUnstable[]

if vscode_integration && isvscode()
_printstyled(io, rootnode, type_hints, warn_diagnostics; type_annotations, iswarn, hide_type_stable, with_linenumber, idxend)

display(Main.VSCodeServer.InlineDisplay(false), warn_diagnostics)
Expand Down
15 changes: 14 additions & 1 deletion TypedSyntax/src/vscode.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
isvscode() = isdefined(Main, :VSCodeServer) && Main.VSCodeServer isa Module

struct WarnUnstable
path::String
line::Int
severity::Int # 0: Error, 1: Warning, 2: Information, 3: Hint
end
function Base.show(io::IO, ::MIME"application/vnd.julia-vscode.diagnostics", warn_diagnostics::AbstractVector{WarnUnstable})
return (
source = "Cthulhu",
Expand All @@ -15,8 +22,14 @@ const InlayHintKinds = (
Type = 1,
Parameter = 2
)
struct InlayHint
line::Int
column::Int
label::String
kind::Union{Nothing, Int}
end
function Base.show(io::IO, ::MIME"application/vnd.julia-vscode.inlayHints", type_hints_by_file::Dict{String, Vector{InlayHint}})
if isdefined(Main, :VSCodeServer) && Main.VSCodeServer isa Module && isdefined(Main.VSCodeServer, :INLAY_HINTS_ENABLED)
if isvscode() && isdefined(Main.VSCodeServer, :INLAY_HINTS_ENABLED)
return Dict(filepath => map(x -> (position=(x.line, x.column), label=x.label, kind=x.kind), type_hints) for (filepath, type_hints) in type_hints_by_file)
end
end
Expand Down

0 comments on commit 5a14e88

Please sign in to comment.