Skip to content

Commit

Permalink
documentation init
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jun 9, 2020
1 parent f9edb80 commit 78cf9cb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
35 changes: 18 additions & 17 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@ uuid = "2b0e0bc5-e4fd-59b4-8912-456d1b03d8d7"
version = "3.0.1-DEV"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
DocumentFormat = "ffa9a821-9c82-50df-894e-fbcef3ed31cd"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSONRPC = "b9b8584e-8fd3-41f9-ad0c-7255d428e418"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
StaticLint = "b3cc710f-9c33-5bdb-a03d-a94903873e97"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Tokenize = "0796e94c-ce3b-5d07-9a54-7f471281c624"
SymbolServer = "cf896787-08d5-524d-9de7-132aaa0cb996"
Tokenize = "0796e94c-ce3b-5d07-9a54-7f471281c624"
URIParser = "30578b45-9adc-5946-b283-645ec420af67"
JSONRPC = "b9b8584e-8fd3-41f9-ad0c-7255d428e418"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
JSON = "0.20, 0.21"
julia = "1"
CSTParser = "2.2"
DocumentFormat = "2.2"
JSON = "0.20, 0.21"
JSONRPC = "1"
StaticLint = "4.3"
Tokenize = "0.5.7"
SymbolServer = "4.2"
Tokenize = "0.5.7"
URIParser = "0.4.1"
JSONRPC = "1"
julia = "1"

[extras]
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Sockets", "Pkg", "LibGit2", "Serialization", "SHA"]
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
35 changes: 35 additions & 0 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,38 @@ function get_module_of(s::StaticLint.Scope, ms = [])
return isempty(ms) ? "Main" : join(ms, ".")
end
end

using Base.Docs, Markdown
using Markdown: MD, HorizontalRule

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))
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

0 comments on commit 78cf9cb

Please sign in to comment.