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 May 5, 2022
1 parent 0955a4d commit 6081535
Show file tree
Hide file tree
Showing 36 changed files with 355 additions and 362 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"
)
112 changes: 56 additions & 56 deletions src/URIs2/URIs2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ end
function URI(value::AbstractString)
m = match(r"^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", value)

m===nothing && error("Invalid argument.")
m === nothing && error("Invalid argument.")

return URI(
m.captures[2],
m.captures[4]===nothing ? nothing : percent_decode(m.captures[4]),
m.captures[5]===nothing ? nothing : percent_decode(m.captures[5]),
m.captures[7]===nothing ? nothing : percent_decode(m.captures[7]),
m.captures[9]===nothing ? nothing : percent_decode(m.captures[9])
m.captures[4] === nothing ? nothing : percent_decode(m.captures[4]),
m.captures[5] === nothing ? nothing : percent_decode(m.captures[5]),
m.captures[7] === nothing ? nothing : percent_decode(m.captures[7]),
m.captures[9] === nothing ? nothing : percent_decode(m.captures[9])
)
end

Expand All @@ -36,58 +36,58 @@ function URI(;
path::AbstractString="",
query::Union{AbstractString,Nothing}=nothing,
fragment::Union{AbstractString,Nothing}=nothing
)
)
return URI(scheme, authority, path, query, fragment)
end

@inline function is_rfc3986_unreserved(c::Char)
return 'A' <= c <= 'Z' ||
'a' <= c <= 'z' ||
'0' <= c <= '9' ||
c == '-' ||
c == '.' ||
c == '_' ||
c == '~'
'a' <= c <= 'z' ||
'0' <= c <= '9' ||
c == '-' ||
c == '.' ||
c == '_' ||
c == '~'
end

@inline function is_rfc3986_sub_delim(c::Char)
return c == '!' ||
c == '$' ||
c == '&' ||
c == '\'' ||
c == '(' ||
c == ')' ||
c == '*' ||
c == '+' ||
c == ',' ||
c == ';' ||
c == '='
c == '$' ||
c == '&' ||
c == '\'' ||
c == '(' ||
c == ')' ||
c == '*' ||
c == '+' ||
c == ',' ||
c == ';' ||
c == '='
end

@inline function is_rfc3986_pchar(c::Char)
return is_rfc3986_unreserved(c) ||
is_rfc3986_sub_delim(c) ||
c == ':' ||
c == '@'
is_rfc3986_sub_delim(c) ||
c == ':' ||
c == '@'
end

@inline function is_rfc3986_query(c::Char)
return is_rfc3986_pchar(c) || c=='/' || c=='?'
return is_rfc3986_pchar(c) || c == '/' || c == '?'
end

@inline function is_rfc3986_fragment(c::Char)
return is_rfc3986_pchar(c) || c=='/' || c=='?'
return is_rfc3986_pchar(c) || c == '/' || c == '?'
end

@inline function is_rfc3986_userinfo(c::Char)
return is_rfc3986_unreserved(c) ||
is_rfc3986_sub_delim(c) ||
c == ':'
is_rfc3986_sub_delim(c) ||
c == ':'
end

@inline function is_rfc3986_reg_name(c::Char)
return is_rfc3986_unreserved(c) ||
is_rfc3986_sub_delim(c)
is_rfc3986_sub_delim(c)
end

function encode(io::IO, s::AbstractString, issafe::Function)
Expand All @@ -102,14 +102,14 @@ function encode(io::IO, s::AbstractString, issafe::Function)
end

@inline function is_ipv4address(s::AbstractString)
if length(s)==1
if length(s) == 1
return '0' <= s[1] <= '9'
elseif length(s)==2
elseif length(s) == 2
return '1' <= s[1] <= '9' && '0' <= s[2] <= '9'
elseif length(s)==3
return (s[1]=='1' && '0' <= s[2] <= '9' && '0' <= s[3] <= '9') ||
(s[1]=='2' && '0' <= s[2] <= '4' && '0' <= s[3] <= '9') ||
(s[1]=='2' && s[2] == '5' && '0' <= s[3] <= '5')
elseif length(s) == 3
return (s[1] == '1' && '0' <= s[2] <= '9' && '0' <= s[3] <= '9') ||
(s[1] == '2' && '0' <= s[2] <= '4' && '0' <= s[3] <= '9') ||
(s[1] == '2' && s[2] == '5' && '0' <= s[3] <= '5')
else
return false
end
Expand Down Expand Up @@ -141,44 +141,44 @@ function Base.print(io::IO, uri::URI)
query = uri.query
fragment = uri.fragment

if scheme!==nothing
if scheme !== nothing
print(io, scheme)
print(io, ':')
end
end

if authority!==nothing
if authority !== nothing
print(io, "//")

idx = findfirst("@", authority)
if idx !== nothing
# <user>@<auth>
userinfo = SubString(authority, 1:idx.start-1)
host_and_port = SubString(authority, idx.start + 1)
encode(io, userinfo, is_rfc3986_userinfo)
idx = findfirst("@", authority)
if idx !== nothing
# <user>@<auth>
userinfo = SubString(authority, 1:idx.start-1)
host_and_port = SubString(authority, idx.start + 1)
encode(io, userinfo, is_rfc3986_userinfo)
print(io, '@')
else
host_and_port = SubString(authority, 1)
end
end

idx3 = findfirst(":", host_and_port)
if idx3 === nothing
idx3 = findfirst(":", host_and_port)
if idx3 === nothing
encode_host(io, host_and_port)
else
# <auth>:<port>
else
# <auth>:<port>
encode_host(io, SubString(host_and_port, 1:idx3.start-1))
print(io, SubString(host_and_port, idx3.start))
print(io, SubString(host_and_port, idx3.start))
end
end
end

# Append path
encode_path(io, path)
# Append path
encode_path(io, path)

if query!==nothing
if query !== nothing
print(io, '?')
encode(io, query, is_rfc3986_query)
end

if fragment!==nothing
if fragment !== nothing
print(io, '#')
encode(io, fragment, is_rfc3986_fragment)
end
Expand Down
12 changes: 6 additions & 6 deletions src/URIs2/uri_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ function uri2filepath(uri::URI)
path = uri.path
host = uri.authority

if host!==nothing && host != "" && length(path) > 1
if host !== nothing && host != "" && length(path) > 1
# unc path: file://shares/c$/far/boo
value = "//$host$path"
elseif length(path) >= 3 &&
path[1] == '/' &&
isascii(path[2]) && isletter(path[2]) &&
path[3] == ':'
path[1] == '/' &&
isascii(path[2]) && isletter(path[2]) &&
path[3] == ':'
# windows drive letter: file:///c:/far/boo
value = lowercase(path[2]) * path[3:end]
else
Expand Down Expand Up @@ -42,14 +42,14 @@ function filepath2uri(path::String)
if startswith(path, "//")
# UNC path //foo/bar/foobar
idx = findnext("/", path, 3)
if idx===nothing
if idx === nothing
authority = path[3:end]
path = "/"
else
authority = path[3:idx.start-1]
path = path[idx.start:end]
end
elseif length(path)>=2 && isascii(path[1]) && isletter(path[1]) && path[2]==':'
elseif length(path) >= 2 && isascii(path[1]) && isletter(path[1]) && path[2] == ':'
path = string('/', lowercase(path[1]), SubString(path, 2))
end

Expand Down
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)
Loading

0 comments on commit 6081535

Please sign in to comment.