Skip to content

Commit

Permalink
Merge pull request #374 from julia-vscode/docformat
Browse files Browse the repository at this point in the history
add format option handlers
  • Loading branch information
davidanthoff authored Oct 30, 2019
2 parents f31248d + 8f69ebd commit 2a71d80
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ mutable struct LanguageServerInstance
env_path::String
depot_path::String
symbol_server::Union{Nothing,SymbolServer.SymbolServerProcess}
format_options::DocumentFormat.FormatOptions

function LanguageServerInstance(pipe_in, pipe_out, debug_mode::Bool = false, env_path = "", depot_path = "", packages = Dict())
new(pipe_in, pipe_out, Set{String}(), Dict{URI2,Document}(), debug_mode, true, Set{String}(), false, packages, env_path, depot_path, nothing)
new(pipe_in, pipe_out, Set{String}(), Dict{URI2,Document}(), debug_mode, true, Set{String}(), false, packages, env_path, depot_path, nothing, DocumentFormat.FormatOptions())
end
end

Expand Down Expand Up @@ -46,6 +47,14 @@ function Base.run(server::LanguageServerInstance)
# server.isrunning && serverbusy(server)
process(request, server)
# server.isrunning && serverready(server)
elseif get(message_dict, "id", 0) == -100 && haskey(message_dict, "result")
# set format options
if length(message_dict["result"]) == length(fieldnames(DocumentFormat.FormatOptions))
try
server.format_options = DocumentFormat.FormatOptions(message_dict["result"]...)
catch
end
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ function JSONRPC.parse_params(::Type{Val{Symbol("textDocument/formatting")}}, pa
return DocumentFormattingParams(params)
end

function process(r::JSONRPC.Request{Val{Symbol("textDocument/formatting")},DocumentFormattingParams}, server)
function process(r::JSONRPC.Request{Val{Symbol("textDocument/formatting")},DocumentFormattingParams}, server::LanguageServerInstance)
if !haskey(server.documents, URI2(r.params.textDocument.uri))
send(JSONRPC.Response(r.id, CancelParams(r.id)), server)
return
end
doc = server.documents[URI2(r.params.textDocument.uri)]
newcontent = DocumentFormat.format(doc._content)
newcontent = DocumentFormat.format(doc._content, server.format_options)
end_l, end_c = get_position_at(doc, sizeof(doc._content))
lsedits = TextEdit[TextEdit(Range(0, 0, end_l, end_c), newcontent)]

Expand Down
2 changes: 2 additions & 0 deletions src/requests/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ function process(r::JSONRPC.Request{Val{Symbol("initialized")}}, server)
load_folder(wkspc, server)
end
end
send(JSONRPC.Request{Val{Symbol("workspace/configuration")},ConfigurationParams}(-100, ConfigurationParams([
ConfigurationItem(nothing, "julia.format.$opt") for opt in fieldnames(DocumentFormat.FormatOptions)])), server)

write_transport_layer(server.pipe_out, JSON.json(Dict("jsonrpc" => "2.0", "id" => "278352324", "method" => "client/registerCapability", "params" => Dict("registrations" => [Dict("id"=>"28c6550c-bd7b-11e7-abc4-cec278b6b50a", "method"=>"workspace/didChangeWorkspaceFolders")]))), server.debug_mode)
end
Expand Down
8 changes: 6 additions & 2 deletions src/requests/workspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function JSONRPC.parse_params(::Type{Val{Symbol("workspace/didChangeConfiguratio
end


function process(r::JSONRPC.Request{Val{Symbol("workspace/didChangeConfiguration")},Dict{String,Any}}, server)
function process(r::JSONRPC.Request{Val{Symbol("workspace/didChangeConfiguration")},Dict{String,Any}}, server::LanguageServerInstance)
if r.params["settings"] isa Dict && haskey(r.params["settings"], "julia")
jsettings = r.params["settings"]["julia"]
if haskey(jsettings, "runLinter") && jsettings["runLinter"] != server.runlinter
Expand Down Expand Up @@ -58,7 +58,11 @@ function process(r::JSONRPC.Request{Val{Symbol("workspace/didChangeConfiguration
end
end
end

end
if haskey(jsettings, "format")
for (k,v) in jsettings["format"]
setproperty!(server.format_options, Symbol(k), v)
end
end
end
end
Expand Down

0 comments on commit 2a71d80

Please sign in to comment.