Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Tokenize = "0796e94c-ce3b-5d07-9a54-7f471281c624"
JSONRPC = "b9b8584e-8fd3-41f9-ad0c-7255d428e418"
SymbolServer = "cf896787-08d5-524d-9de7-132aaa0cb996"
URIParser = "30578b45-9adc-5946-b283-645ec420af67"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand Down
1 change: 1 addition & 0 deletions src/LanguageServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using JSON, REPL, CSTParser, DocumentFormat, SymbolServer, StaticLint
using CSTParser: EXPR, Tokenize.Tokens, typof, kindof, parentof, valof
using StaticLint: refof, scopeof, bindingof
using UUIDs
using Base.Docs, Markdown
import JSONRPC
using JSONRPC: Outbound, @dict_readable

Expand Down
3 changes: 1 addition & 2 deletions src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ function Base.run(server::LanguageServerInstance)
msg_dispatcher[textDocument_rename_request_type] = (conn, params)->textDocument_rename_request(params, server, conn)
msg_dispatcher[textDocument_documentSymbol_request_type] = (conn, params)->textDocument_documentSymbol_request(params, server, conn)
msg_dispatcher[julia_getModuleAt_request_type] = (conn, params)->julia_getModuleAt_request(params, server, conn)
msg_dispatcher[julia_getDocAt_request_type] = (conn, params)->julia_getDocAt_request(params, server, conn)
msg_dispatcher[textDocument_hover_request_type] = (conn, params)->textDocument_hover_request(params, server, conn)
msg_dispatcher[initialize_request_type] = (conn, params)->initialize_request(params, server, conn)
msg_dispatcher[initialized_notification_type] = (conn, params)->initialized_notification(params, server, conn)
Expand Down Expand Up @@ -323,5 +324,3 @@ function Base.run(server::LanguageServerInstance)
end
end
end


1 change: 1 addition & 0 deletions src/protocol/messagedefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const workspace_applyEdit_request_type = JSONRPC.RequestType("workspace/applyEdi
const workspace_configuration_request_type = JSONRPC.RequestType("workspace/configuration", ConfigurationParams, Vector{Any})

const julia_getModuleAt_request_type = JSONRPC.RequestType("julia/getModuleAt", TextDocumentPositionParams, String)
const julia_getDocAt_request_type = JSONRPC.RequestType("julia/getDocAt", TextDocumentPositionParams, String)
const julia_getCurrentBlockRange_request_type = JSONRPC.RequestType("julia/getCurrentBlockRange", TextDocumentPositionParams, Position)
const julia_activateenvironment_notification_type = JSONRPC.NotificationType("julia/activateenvironment", String)

Expand Down
34 changes: 34 additions & 0 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,37 @@ function get_module_of(s::StaticLint.Scope, ms = [])
return isempty(ms) ? "Main" : join(ms, ".")
end
end

using Base.Docs, Markdown

function julia_getDocAt_request(params::TextDocumentPositionParams, server::LanguageServerInstance, conn)
doc = getdocument(server, URI2(params.textDocument.uri))
x = get_expr1(getcst(doc), get_offset(doc, params.position))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be get_expr?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, why do you think so ?
I adapted code from this line, and not so sure about the difference between get_expr and get_expr1...
Maybe @ZacLN could you explain this to me ?

x isa EXPR && typof(x) === CSTParser.OPERATOR && resolve_op_ref(x, server)
documentation = get_hover(x, "", server)
md = Markdown.parse(documentation)
return webview_html(md)
end

const CODE_LANG_REGEX = r"\<code class\=\"language-(?<lang>(?!\>).+)\"\>"

function webview_html(md)
# HACK goes on ...
s = html(md)
if haskey(md.meta, :module)
mod = md.meta[:module]
newhref = string("julia-vscode", '/', mod)
s = replace(s, "<a href=\"@ref\"" => "<a href=\"$newhref\"")
end
s = replace(s, CODE_LANG_REGEX => annotate_highlight_js)
return s
end

function annotate_highlight_js(s)
m::RegexMatch = match(CODE_LANG_REGEX, s)
lang = m[:lang]
if lang == "jldoctest"
lang = "julia-repl"
end
return "<code class=\"language-$(lang) hljs\">"
end