Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Mar 20, 2022
1 parent 626d97d commit e4d6541
Show file tree
Hide file tree
Showing 32 changed files with 325 additions and 332 deletions.
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ makedocs(;
repo="https://github.com/julia-vscode/LanguageServer.jl/blob/{commit}{path}#L{line}",
sitename="LanguageServer.jl",
format=Documenter.HTML(;
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true",
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true"
# canonical="https://www.julia-vscode.org/LanguageServer.jl",
# assets=String[],
),
pages=[
"Home" => "index.md",
"Syntax Reference" => "syntax.md",
],
]
)

deploydocs(;
repo="github.com/julia-vscode/LanguageServer.jl",
repo="github.com/julia-vscode/LanguageServer.jl"
)
24 changes: 12 additions & 12 deletions src/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function get_offset(doc::Document, line::Integer, character::Integer)
line_offsets = get_line_offsets(doc)
io = IOBuffer(get_text(doc))
try
seek(io, line_offsets[line + 1])
seek(io, line_offsets[line+1])
while character > 0
c = read(io, Char)
character -= 1
Expand All @@ -102,7 +102,7 @@ get_offset(doc, p::Position) = get_offset(doc, p.line, p.character)
get_offset(doc, r::Range) = get_offset(doc, r.start):get_offset(doc, r.stop)

# 1-based. Basically the index at which (line, character) can be found in the document.
get_offset2(doc::Document, p::Position, forgiving_mode=false) = get_offset2(doc, p.line, p.character, forgiving_mode)
get_offset2(doc::Document, p::Position, forgiving_mode=false) = get_offset2(doc, p.line, p.character, forgiving_mode)
function get_offset2(doc::Document, line::Integer, character::Integer, forgiving_mode=false)
line_offsets = get_line_offsets2!(doc)
text = get_text(doc)
Expand All @@ -114,9 +114,9 @@ function get_offset2(doc::Document, line::Integer, character::Integer, forgiving
throw(LSOffsetError("get_offset2 crashed. More diagnostics:\nline=$line\nline_offsets='$line_offsets'"))
end

line_offset = line_offsets[line + 1]
line_offset = line_offsets[line+1]

next_line_offset = line + 1 < length(line_offsets) ? line_offsets[line + 2] : nextind(text, lastindex(text))
next_line_offset = line + 1 < length(line_offsets) ? line_offsets[line+2] : nextind(text, lastindex(text))

pos = line_offset

Expand Down Expand Up @@ -177,16 +177,16 @@ function get_line_offsets(doc::Document, force=false)
doc._line_offsets = Int[0]
text = get_text(doc)
ind = firstindex(text)
while ind <= lastindex(text)
while ind <= lastindex(text)
c = text[ind]
nl = c == '\n' || c == '\r'
if c == '\r' && ind + 1 <= lastindex(text) && text[ind + 1] == '\n'
if c == '\r' && ind + 1 <= lastindex(text) && text[ind+1] == '\n'
ind += 1
end
nl && push!(doc._line_offsets, ind)
ind = nextind(text, ind)
end
end
end
return doc._line_offsets
end

Expand All @@ -195,10 +195,10 @@ function get_line_offsets2!(doc::Document, force=false)
doc._line_offsets2 = Int[1]
text = get_text(doc)
ind = firstindex(text)
while ind <= lastindex(text)
while ind <= lastindex(text)
c = text[ind]
if c == '\n' || c == '\r'
if c == '\r' && ind + 1 <= lastindex(text) && text[ind + 1] == '\n'
if c == '\r' && ind + 1 <= lastindex(text) && text[ind+1] == '\n'
ind += 1
end
push!(doc._line_offsets2, ind + 1)
Expand All @@ -218,12 +218,12 @@ function get_line_of(line_offsets::Vector{Int}, offset::Integer)
else
line = 1
while line < nlines
if line_offsets[line] <= offset < line_offsets[line + 1]
if line_offsets[line] <= offset < line_offsets[line+1]
break
end
line += 1
end
end
end
return line, line_offsets[line]
end

Expand All @@ -244,7 +244,7 @@ function get_position_at(doc::Document, offset::Integer)
c = read(io, Char)
character += 1
if UInt32(c) >= 0x010000
character += 1
character += 1
end
end
close(io)
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/messagedefs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const julia_getModuleAt_request_type = JSONRPC.RequestType("julia/getModuleAt", VersionedTextDocumentPositionParams, String)
const julia_getCurrentBlockRange_request_type = JSONRPC.RequestType("julia/getCurrentBlockRange", VersionedTextDocumentPositionParams, Tuple{Position, Position, Position})
const julia_getCurrentBlockRange_request_type = JSONRPC.RequestType("julia/getCurrentBlockRange", VersionedTextDocumentPositionParams, Tuple{Position,Position,Position})
const julia_getDocAt_request_type = JSONRPC.RequestType("julia/getDocAt", VersionedTextDocumentPositionParams, String)
const julia_getDocFromWord_request_type = JSONRPC.RequestType("julia/getDocFromWord", NamedTuple{(:word,),Tuple{String}}, String)
16 changes: 8 additions & 8 deletions src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ mutable struct LanguageServerInstance

shutdown_requested::Bool

function LanguageServerInstance(pipe_in, pipe_out, env_path="", depot_path="", err_handler=nothing, symserver_store_path=nothing, download=true, symbolcache_upstream = nothing)
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{URI2,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(),
Expand Down Expand Up @@ -179,7 +179,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(
Expand All @@ -193,7 +193,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
Expand Down Expand Up @@ -269,7 +269,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()
Expand All @@ -282,7 +282,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."
Expand All @@ -292,7 +292,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()
Expand All @@ -305,7 +305,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."
Expand Down
8 changes: 4 additions & 4 deletions src/multienv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const project_names = ("JuliaProject.toml", "Project.toml")
const manifest_names = ("JuliaManifest.toml", "Manifest.toml")

# return nothing or the project file at env
function env_file(env::String, names = project_names)::Union{Nothing,String}
function env_file(env::String, names=project_names)::Union{Nothing,String}
if isdir(env)
for proj in names
project_file = joinpath(env, proj)
Expand Down Expand Up @@ -49,7 +49,7 @@ function get_env_for_root(doc::Document, server::LanguageServerInstance)
(safe_isfile(env_proj_file) && safe_isfile(env_manifest_file)) || return

# Find which workspace folder the doc is in.
parent_workspaceFolders = sort(filter(f->startswith(doc._path, f), collect(server.workspaceFolders)), by = length, rev = true)
parent_workspaceFolders = sort(filter(f -> startswith(doc._path, f), collect(server.workspaceFolders)), by=length, rev=true)

isempty(parent_workspaceFolders) && return
# arbitrarily pick one
Expand Down Expand Up @@ -94,11 +94,11 @@ function get_env_for_root(doc::Document, server::LanguageServerInstance)
msg
))
end
@error msg exception=(err, catch_backtrace())
@error msg exception = (err, catch_backtrace())
end
end

function complete_dep_tree(uuid, env_manifest, alldeps = Dict{Base.UUID,Pkg.Types.PackageEntry}())
function complete_dep_tree(uuid, env_manifest, alldeps=Dict{Base.UUID,Pkg.Types.PackageEntry}())
haskey(alldeps, uuid) && return alldeps
alldeps[uuid] = env_manifest[uuid]
for dep_uuid in values(alldeps[uuid].deps)
Expand Down
24 changes: 12 additions & 12 deletions src/protocol/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ end
##############################################################################
# Diagnostics
const DiagnosticSeverity = Int
const DiagnosticSeverities = (Error = 1,
Warning = 2,
Information = 3,
Hint = 4)
const DiagnosticSeverities = (Error=1,
Warning=2,
Information=3,
Hint=4)

const DiagnosticTag = Int
const DiagnosticTags = (Unnecessary = 1,
Deprecated = 2)
const DiagnosticTags = (Unnecessary=1,
Deprecated=2)

@dict_readable struct DiagnosticRelatedInformation
location::Location
Expand Down Expand Up @@ -104,8 +104,8 @@ end
##############################################################################
# Markup
const MarkupKind = String
const MarkupKinds = (PlainText = "plaintext",
Markdown = "markdown")
const MarkupKinds = (PlainText="plaintext",
Markdown="markdown")

mutable struct MarkupContent
kind::MarkupKind
Expand All @@ -126,10 +126,10 @@ Base.hash(x::MarkedString) = hash(x.value) # for unique
##############################################################################
# Window
const MessageType = Int
const MessageTypes = (Error = 1,
Warning = 2,
Info = 3,
Log = 4)
const MessageTypes = (Error=1,
Warning=2,
Info=3,
Log=4)

struct ShowMessageParams <: Outbound
type::MessageType
Expand Down
60 changes: 30 additions & 30 deletions src/protocol/completion.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
const CompletionItemKind = Int
const CompletionItemKinds = (Text = 1,
Method = 2,
Function = 3,
Constructor = 4,
Field = 5,
Variable = 6,
Class = 7,
Interface = 8,
Module = 9,
Property = 10,
Unit = 11,
Value = 12,
Enum = 13,
Keyword = 14,
Snippet = 15,
Color = 16,
File = 17,
Reference = 18,
Folder = 19,
EnumMember = 20,
Constant = 21,
Struct = 22,
Event = 23,
Operator = 24,
TypeParameter = 25)
const CompletionItemKinds = (Text=1,
Method=2,
Function=3,
Constructor=4,
Field=5,
Variable=6,
Class=7,
Interface=8,
Module=9,
Property=10,
Unit=11,
Value=12,
Enum=13,
Keyword=14,
Snippet=15,
Color=16,
File=17,
Reference=18,
Folder=19,
EnumMember=20,
Constant=21,
Struct=22,
Event=23,
Operator=24,
TypeParameter=25)

const CompletionItemTag = Int
const CompletionItemTags = (Deprecated = 1)

const CompletionTriggerKind = Int
const CompletionTriggerKinds = (Invoked = 1,
TriggerCharacter = 2,
TriggerForIncompleteCompletion = 3)
const CompletionTriggerKinds = (Invoked=1,
TriggerCharacter=2,
TriggerForIncompleteCompletion=3)

const InsertTextFormat = Int
const InsertTextFormats = (PlainText = 1,
Snippet = 2)
const InsertTextFormats = (PlainText=1,
Snippet=2)

@dict_readable struct CompletionTagClientCapabilities
valueSet::Vector{CompletionItemTag}
Expand Down
12 changes: 6 additions & 6 deletions src/protocol/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ end
##############################################################################
# File watching
const FileChangeType = Int
const FileChangeTypes = (Created = 1,
Changed = 2,
Deleted = 3)
const FileChangeTypes = (Created=1,
Changed=2,
Deleted=3)

const WatchKind = Int
const WatchKinds = (Create = 1,
Change = 2,
Delete = 4)
const WatchKinds = (Create=1,
Change=2,
Delete=4)


@dict_readable struct FileEvent
Expand Down
8 changes: 4 additions & 4 deletions src/protocol/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end
textDocument::TextDocumentItem
end

@dict_readable struct TextDocumentContentChangeEvent <: Outbound
@dict_readable struct TextDocumentContentChangeEvent <: Outbound
range::Union{Range,Missing}
rangeLength::Union{Int,Missing}
text::String
Expand All @@ -97,9 +97,9 @@ end
end

const TextDocumentSaveReason = Int
const TextDocumentSaveReasons = (Manual = 1,
AfterDelay = 2,
FocusOut = 3)
const TextDocumentSaveReasons = (Manual=1,
AfterDelay=2,
FocusOut=3)

@dict_readable struct WillSaveTextDocumentParams
textDocument::TextDocumentIdentifier
Expand Down
Loading

0 comments on commit e4d6541

Please # to comment.