diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 751e9e38..9d12d37c 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -66,14 +66,16 @@ mutable struct LanguageServerInstance workspace::JuliaWorkspace - function LanguageServerInstance(pipe_in, pipe_out, env_path="", depot_path="", err_handler=nothing, symserver_store_path=nothing, download=true, symbolcache_upstream = nothing) + howtotype_cache::Union{Nothing,Dict{String,String}} + + function LanguageServerInstance(pipe_in, pipe_out, env_path="", depot_path="", err_handler=nothing, symserver_store_path=nothing, download=true, symbolcache_upstream=nothing) new( JSONRPC.JSONRPCEndpoint(pipe_in, pipe_out, err_handler), Set{String}(), Dict{URI,Document}(), env_path, depot_path, - SymbolServer.SymbolServerInstance(depot_path, symserver_store_path; symbolcache_upstream = symbolcache_upstream), + SymbolServer.SymbolServerInstance(depot_path, symserver_store_path; symbolcache_upstream=symbolcache_upstream), Channel(Inf), StaticLint.ExternalEnv(deepcopy(SymbolServer.stdlibs), SymbolServer.collect_extended_methods(SymbolServer.stdlibs), collect(keys(SymbolServer.stdlibs))), Dict(), @@ -95,7 +97,8 @@ mutable struct LanguageServerInstance missing, missing, false, - JuliaWorkspace() + JuliaWorkspace(), + nothing, ) end end @@ -184,7 +187,7 @@ function trigger_symbolstore_reload(server::LanguageServerInstance) ssi_ret, payload = SymbolServer.getstore( server.symbol_server, server.env_path, - function (msg, percentage = missing) + function (msg, percentage=missing) if server.clientcapability_window_workdoneprogress && server.current_symserver_progress_token !== nothing msg = ismissing(percentage) ? msg : string(msg, " ($percentage%)") JSONRPC.send( @@ -198,7 +201,7 @@ function trigger_symbolstore_reload(server::LanguageServerInstance) end end, server.err_handler, - download = server.symserver_use_download + download=server.symserver_use_download ) server.number_of_outstanding_symserver_requests -= 1 @@ -286,7 +289,7 @@ function Base.run(server::LanguageServerInstance) @debug "LS: Starting client listener task." while true msg = JSONRPC.get_next_message(server.jr_endpoint) - put!(server.combined_msg_queue, (type = :clientmsg, msg = msg)) + put!(server.combined_msg_queue, (type=:clientmsg, msg=msg)) end catch err bt = catch_backtrace() @@ -299,7 +302,7 @@ function Base.run(server::LanguageServerInstance) end finally if isopen(server.combined_msg_queue) - put!(server.combined_msg_queue, (type = :close,)) + put!(server.combined_msg_queue, (type=:close,)) close(server.combined_msg_queue) end @debug "LS: Client listener task done." @@ -309,7 +312,7 @@ function Base.run(server::LanguageServerInstance) @debug "LS: Starting symbol server listener task." while true msg = take!(server.symbol_results_channel) - put!(server.combined_msg_queue, (type = :symservmsg, msg = msg)) + put!(server.combined_msg_queue, (type=:symservmsg, msg=msg)) end catch err bt = catch_backtrace() @@ -322,7 +325,7 @@ function Base.run(server::LanguageServerInstance) end finally if isopen(server.combined_msg_queue) - put!(server.combined_msg_queue, (type = :close,)) + put!(server.combined_msg_queue, (type=:close,)) close(server.combined_msg_queue) end @debug "LS: Symbol server listener task done." @@ -430,3 +433,30 @@ function relintserver(server) lint!(doc, server) end end + +function howtotypeCache() + tcache = Dict{String,String}() + for (k, v) in REPL.REPLCompletions.latex_symbols + tcache[v] = k + end + for (k, v) in REPL.REPLCompletions.emoji_symbols + tcache[v] = k + end + if isdefined(REPL.REPLCompletions, :symbols_latex_canonical) + for (k, v) in REPL.REPLCompletions.symbols_latex_canonical + tcache[k] = v + end + end + tcache +end + +function findHowtotype(server::LanguageServerInstance, estr::String) + if isnothing(server.howtotype_cache) + server.howtotype_cache = howtotypeCache() + end + if haskey(server.howtotype_cache, estr) + return server.howtotype_cache[estr] + else + return nothing + end +end \ No newline at end of file diff --git a/src/requests/hover.jl b/src/requests/hover.jl index ac73626a..807e6fc2 100644 --- a/src/requests/hover.jl +++ b/src/requests/hover.jl @@ -23,11 +23,20 @@ function get_hover(x::EXPR, documentation::String, server) else documentation end + if !isnothing(x.val) + estr = string(x.val) + if length(estr) == 1 + howtotype = findHowtotype(server, estr) + if !isnothing(howtotype) + documentation *= "\nHow to type $estr: $howtotype" + end + end + end end return documentation end -function get_tooltip(b::StaticLint.Binding, documentation::String, server; show_definition = false) +function get_tooltip(b::StaticLint.Binding, documentation::String, server; show_definition=false) if b.val isa StaticLint.Binding documentation = get_hover(b.val, documentation, server) elseif b.val isa EXPR @@ -75,7 +84,7 @@ function get_tooltip(b::StaticLint.Binding, documentation::String, server; show_ return documentation end -get_hover(b::StaticLint.Binding, documentation::String, server) = get_tooltip(b, documentation, server; show_definition = true) +get_hover(b::StaticLint.Binding, documentation::String, server) = get_tooltip(b, documentation, server; show_definition=true) get_typed_definition(b) = _completion_type(b) get_typed_definition(b::StaticLint.Binding) = @@ -194,7 +203,7 @@ function get_preceding_docs(expr::EXPR, documentation) end end -ensure_ends_with(s, c = "\n") = endswith(s, c) ? s : string(s, c) +ensure_ends_with(s, c="\n") = endswith(s, c) ? s : string(s, c) binding_has_preceding_docs(b::StaticLint.Binding) = expr_has_preceding_docs(b.val)