Skip to content

Commit 3dcac16

Browse files
authored
Format files using DocumentFormat
1 parent 01c2a85 commit 3dcac16

File tree

7 files changed

+118
-118
lines changed

7 files changed

+118
-118
lines changed

src/JuliaWorkspaces.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ function JuliaWorkspace(workspace_folders::Set{URI})
5656
text_documents = isempty(workspace_folders) ? Dict{URI,TextDocument}() : merge((read_path_into_textdocuments(path) for path in workspace_folders)...)
5757

5858
toml_syntax_trees = Dict{URI,Dict}()
59-
for (k,v) in pairs(text_documents)
59+
for (k, v) in pairs(text_documents)
6060
if endswith(lowercase(string(k)), ".toml")
6161
# try
62-
toml_syntax_trees[k] = parse_toml_file(get_text(v))
62+
toml_syntax_trees[k] = parse_toml_file(get_text(v))
6363
# catch err
64-
# TODO Add some diagnostics
64+
# TODO Add some diagnostics
6565
# end
6666
end
6767
end
@@ -78,13 +78,13 @@ end
7878
function is_path_project_file(path)
7979
basename_lower_case = basename(lowercase(path))
8080

81-
return basename_lower_case=="project.toml" || basename_lower_case=="juliaproject.toml"
81+
return basename_lower_case == "project.toml" || basename_lower_case == "juliaproject.toml"
8282
end
8383

8484
function is_path_manifest_file(path)
8585
basename_lower_case = basename(lowercase(path))
8686

87-
return basename_lower_case=="manifest.toml" || basename_lower_case=="juliamanifest.toml"
87+
return basename_lower_case == "manifest.toml" || basename_lower_case == "juliamanifest.toml"
8888
end
8989

9090
function read_textdocument_from_uri(uri::URI)
@@ -109,21 +109,21 @@ function read_path_into_textdocuments(uri::URI)
109109

110110
if true
111111
#T TODO Move this check into the LS logic
112-
# if load_rootpath(path)
113-
# TODO Think about this try catch block
112+
# if load_rootpath(path)
113+
# TODO Think about this try catch block
114114
# try
115-
for (root, _, files) in walkdir(path, onerror=x -> x)
116-
for file in files
117-
118-
filepath = joinpath(root, file)
119-
if is_path_project_file(filepath) || is_path_manifest_file(filepath)
120-
uri = filepath2uri(filepath)
121-
doc = read_textdocument_from_uri(uri)
122-
doc === nothing && continue
123-
result[uri] = doc
124-
end
115+
for (root, _, files) in walkdir(path, onerror=x -> x)
116+
for file in files
117+
118+
filepath = joinpath(root, file)
119+
if is_path_project_file(filepath) || is_path_manifest_file(filepath)
120+
uri = filepath2uri(filepath)
121+
doc = read_textdocument_from_uri(uri)
122+
doc === nothing && continue
123+
result[uri] = doc
125124
end
126125
end
126+
end
127127
# catch err
128128
# is_walkdir_error(err) || rethrow()
129129
# end
@@ -137,7 +137,7 @@ function add_workspace_folder(jw::JuliaWorkspace, folder::URI)
137137
new_toml_syntax_trees = copy(jw._toml_syntax_trees)
138138

139139
additional_documents = read_path_into_textdocuments(folder)
140-
for (k,v) in pairs(additional_documents)
140+
for (k, v) in pairs(additional_documents)
141141
if endswith(lowercase(string(k)), ".toml")
142142
try
143143
new_toml_syntax_trees[k] = parse_toml_file(get_text(v))
@@ -158,7 +158,7 @@ function remove_workspace_folder(jw::JuliaWorkspace, folder::URI)
158158

159159
new_text_documents = filter(jw._text_documents) do i
160160
# TODO Eventually use FilePathsBase functionality to properly test this
161-
return any(startswith(string(i.first), string(j)) for j in new_roots )
161+
return any(startswith(string(i.first), string(j)) for j in new_roots)
162162
end
163163

164164
new_toml_syntax_trees = filter(jw._toml_syntax_trees) do i
@@ -174,7 +174,7 @@ function add_file(jw::JuliaWorkspace, uri::URI)
174174

175175
new_jw = jw
176176

177-
if new_doc!==nothing
177+
if new_doc !== nothing
178178
new_text_documents = copy(jw._text_documents)
179179
new_text_documents[uri] = new_doc
180180

@@ -189,7 +189,7 @@ function add_file(jw::JuliaWorkspace, uri::URI)
189189
nothing
190190
end
191191

192-
new_jw = JuliaWorkspace(jw._workspace_folders, new_text_documents, new_toml_syntax_trees, semantic_pass_toml_files(new_toml_syntax_trees)...)
192+
new_jw = JuliaWorkspace(jw._workspace_folders, new_text_documents, new_toml_syntax_trees, semantic_pass_toml_files(new_toml_syntax_trees)...)
193193
end
194194

195195
return new_jw
@@ -200,7 +200,7 @@ function update_file(jw::JuliaWorkspace, uri::URI)
200200

201201
new_jw = jw
202202

203-
if new_doc!==nothing
203+
if new_doc !== nothing
204204
new_text_documents = copy(jw._text_documents)
205205
new_text_documents[uri] = new_doc
206206

@@ -240,11 +240,11 @@ function semantic_pass_toml_files(toml_syntax_trees)
240240
# Extract all packages & paths with a manifest
241241
packages = Dict{URI,JuliaPackage}()
242242
paths_with_manifest = Dict{String,Dict}()
243-
for (k,v) in pairs(toml_syntax_trees)
243+
for (k, v) in pairs(toml_syntax_trees)
244244
# TODO Maybe also check the filename here and only do the package detection for Project.toml and JuliaProject.toml
245245
if haskey(v, "name") && haskey(v, "uuid") && haskey(v, "version")
246246
parsed_uuid = tryparse(UUID, v["uuid"])
247-
if parsed_uuid!==nothing
247+
if parsed_uuid !== nothing
248248
folder_uri = k |> uri2filepath |> dirname |> filepath2uri
249249
packages[folder_uri] = JuliaPackage(k, v["name"], parsed_uuid)
250250
end
@@ -261,29 +261,29 @@ function semantic_pass_toml_files(toml_syntax_trees)
261261

262262
# Extract all projects
263263
projects = Dict{URI,JuliaProject}()
264-
for (k,_) in pairs(toml_syntax_trees)
264+
for (k, _) in pairs(toml_syntax_trees)
265265
path = uri2filepath(k)
266266
dname = dirname(path)
267267
filename = basename(path)
268268
filename_lc = lowercase(filename)
269269

270-
if (filename_lc=="project.toml" || filename_lc=="juliaproject.toml" ) && haskey(paths_with_manifest, dname)
270+
if (filename_lc == "project.toml" || filename_lc == "juliaproject.toml") && haskey(paths_with_manifest, dname)
271271
manifest_content = paths_with_manifest[dname]
272272
manifest_content isa Dict || continue
273273
deved_packages = Dict{URI,JuliaDevedPackage}()
274274
manifest_version = get(manifest_content, "manifest_format", "1.0")
275275

276-
manifest_deps = if manifest_version=="1.0"
276+
manifest_deps = if manifest_version == "1.0"
277277
manifest_content
278-
elseif manifest_version=="2.0" && haskey(manifest_content, "deps") && manifest_content["deps"] isa Dict
278+
elseif manifest_version == "2.0" && haskey(manifest_content, "deps") && manifest_content["deps"] isa Dict
279279
manifest_content["deps"]
280280
else
281281
continue
282282
end
283283

284284
for (k_entry, v_entry) in pairs(manifest_deps)
285285
v_entry isa Vector || continue
286-
length(v_entry)==1 || continue
286+
length(v_entry) == 1 || continue
287287
v_entry[1] isa Dict || continue
288288
haskey(v_entry[1], "path") || continue
289289
haskey(v_entry[1], "uuid") || continue

src/URIs2/URIs2.jl

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ end
1414

1515
@static if Sys.iswindows()
1616
function Base.:(==)(a::URI, b::URI)
17-
if a.scheme=="file" && b.scheme=="file"
17+
if a.scheme == "file" && b.scheme == "file"
1818
a_path_norm = lowercase(a.path)
1919
b_path_norm = lowercase(b.path)
2020

2121
return a.scheme == b.scheme &&
22-
a.authority == b.authority &&
23-
a_path_norm == b_path_norm &&
24-
a.query == b.query &&
25-
a.fragment == b.fragment
22+
a.authority == b.authority &&
23+
a_path_norm == b_path_norm &&
24+
a.query == b.query &&
25+
a.fragment == b.fragment
2626
else
2727
return a.scheme == b.scheme &&
28-
a.authority == b.authority &&
29-
a.path == b.path &&
30-
a.query == b.query &&
31-
a.fragment == b.fragment
28+
a.authority == b.authority &&
29+
a.path == b.path &&
30+
a.query == b.query &&
31+
a.fragment == b.fragment
3232
end
3333
end
3434

3535
function Base.hash(a::URI, h::UInt)
36-
if a.scheme=="file"
36+
if a.scheme == "file"
3737
path_norm = lowercase(a.path)
3838
return hash((a.scheme, a.authority, path_norm, a.query, a.fragment), h)
3939
else
@@ -49,14 +49,14 @@ end
4949
function URI(value::AbstractString)
5050
m = match(r"^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", value)
5151

52-
m===nothing && error("Invalid argument.")
52+
m === nothing && error("Invalid argument.")
5353

5454
return URI(
5555
m.captures[2],
56-
m.captures[4]===nothing ? nothing : percent_decode(m.captures[4]),
57-
m.captures[5]===nothing ? nothing : percent_decode(m.captures[5]),
58-
m.captures[7]===nothing ? nothing : percent_decode(m.captures[7]),
59-
m.captures[9]===nothing ? nothing : percent_decode(m.captures[9])
56+
m.captures[4] === nothing ? nothing : percent_decode(m.captures[4]),
57+
m.captures[5] === nothing ? nothing : percent_decode(m.captures[5]),
58+
m.captures[7] === nothing ? nothing : percent_decode(m.captures[7]),
59+
m.captures[9] === nothing ? nothing : percent_decode(m.captures[9])
6060
)
6161
end
6262

@@ -68,58 +68,58 @@ function URI(;
6868
path::AbstractString="",
6969
query::Union{AbstractString,Nothing}=nothing,
7070
fragment::Union{AbstractString,Nothing}=nothing
71-
)
71+
)
7272
return URI(scheme, authority, path, query, fragment)
7373
end
7474

7575
@inline function is_rfc3986_unreserved(c::Char)
7676
return 'A' <= c <= 'Z' ||
77-
'a' <= c <= 'z' ||
78-
'0' <= c <= '9' ||
79-
c == '-' ||
80-
c == '.' ||
81-
c == '_' ||
82-
c == '~'
77+
'a' <= c <= 'z' ||
78+
'0' <= c <= '9' ||
79+
c == '-' ||
80+
c == '.' ||
81+
c == '_' ||
82+
c == '~'
8383
end
8484

8585
@inline function is_rfc3986_sub_delim(c::Char)
8686
return c == '!' ||
87-
c == '$' ||
88-
c == '&' ||
89-
c == '\'' ||
90-
c == '(' ||
91-
c == ')' ||
92-
c == '*' ||
93-
c == '+' ||
94-
c == ',' ||
95-
c == ';' ||
96-
c == '='
87+
c == '$' ||
88+
c == '&' ||
89+
c == '\'' ||
90+
c == '(' ||
91+
c == ')' ||
92+
c == '*' ||
93+
c == '+' ||
94+
c == ',' ||
95+
c == ';' ||
96+
c == '='
9797
end
9898

9999
@inline function is_rfc3986_pchar(c::Char)
100100
return is_rfc3986_unreserved(c) ||
101-
is_rfc3986_sub_delim(c) ||
102-
c == ':' ||
103-
c == '@'
101+
is_rfc3986_sub_delim(c) ||
102+
c == ':' ||
103+
c == '@'
104104
end
105105

106106
@inline function is_rfc3986_query(c::Char)
107-
return is_rfc3986_pchar(c) || c=='/' || c=='?'
107+
return is_rfc3986_pchar(c) || c == '/' || c == '?'
108108
end
109109

110110
@inline function is_rfc3986_fragment(c::Char)
111-
return is_rfc3986_pchar(c) || c=='/' || c=='?'
111+
return is_rfc3986_pchar(c) || c == '/' || c == '?'
112112
end
113113

114114
@inline function is_rfc3986_userinfo(c::Char)
115115
return is_rfc3986_unreserved(c) ||
116-
is_rfc3986_sub_delim(c) ||
117-
c == ':'
116+
is_rfc3986_sub_delim(c) ||
117+
c == ':'
118118
end
119119

120120
@inline function is_rfc3986_reg_name(c::Char)
121121
return is_rfc3986_unreserved(c) ||
122-
is_rfc3986_sub_delim(c)
122+
is_rfc3986_sub_delim(c)
123123
end
124124

125125
function encode(io::IO, s::AbstractString, issafe::Function)
@@ -134,14 +134,14 @@ function encode(io::IO, s::AbstractString, issafe::Function)
134134
end
135135

136136
@inline function is_ipv4address(s::AbstractString)
137-
if length(s)==1
137+
if length(s) == 1
138138
return '0' <= s[1] <= '9'
139-
elseif length(s)==2
139+
elseif length(s) == 2
140140
return '1' <= s[1] <= '9' && '0' <= s[2] <= '9'
141-
elseif length(s)==3
142-
return (s[1]=='1' && '0' <= s[2] <= '9' && '0' <= s[3] <= '9') ||
143-
(s[1]=='2' && '0' <= s[2] <= '4' && '0' <= s[3] <= '9') ||
144-
(s[1]=='2' && s[2] == '5' && '0' <= s[3] <= '5')
141+
elseif length(s) == 3
142+
return (s[1] == '1' && '0' <= s[2] <= '9' && '0' <= s[3] <= '9') ||
143+
(s[1] == '2' && '0' <= s[2] <= '4' && '0' <= s[3] <= '9') ||
144+
(s[1] == '2' && s[2] == '5' && '0' <= s[3] <= '5')
145145
else
146146
return false
147147
end
@@ -173,44 +173,44 @@ function Base.print(io::IO, uri::URI)
173173
query = uri.query
174174
fragment = uri.fragment
175175

176-
if scheme!==nothing
176+
if scheme !== nothing
177177
print(io, scheme)
178178
print(io, ':')
179-
end
179+
end
180180

181-
if authority!==nothing
181+
if authority !== nothing
182182
print(io, "//")
183183

184-
idx = findfirst("@", authority)
185-
if idx !== nothing
186-
# <user>@<auth>
187-
userinfo = SubString(authority, 1:idx.start-1)
188-
host_and_port = SubString(authority, idx.start + 1)
189-
encode(io, userinfo, is_rfc3986_userinfo)
184+
idx = findfirst("@", authority)
185+
if idx !== nothing
186+
# <user>@<auth>
187+
userinfo = SubString(authority, 1:idx.start-1)
188+
host_and_port = SubString(authority, idx.start + 1)
189+
encode(io, userinfo, is_rfc3986_userinfo)
190190
print(io, '@')
191191
else
192192
host_and_port = SubString(authority, 1)
193-
end
193+
end
194194

195-
idx3 = findfirst(":", host_and_port)
196-
if idx3 === nothing
195+
idx3 = findfirst(":", host_and_port)
196+
if idx3 === nothing
197197
encode_host(io, host_and_port)
198-
else
199-
# <auth>:<port>
198+
else
199+
# <auth>:<port>
200200
encode_host(io, SubString(host_and_port, 1:idx3.start-1))
201-
print(io, SubString(host_and_port, idx3.start))
201+
print(io, SubString(host_and_port, idx3.start))
202202
end
203-
end
203+
end
204204

205-
# Append path
206-
encode_path(io, path)
205+
# Append path
206+
encode_path(io, path)
207207

208-
if query!==nothing
208+
if query !== nothing
209209
print(io, '?')
210210
encode(io, query, is_rfc3986_query)
211211
end
212212

213-
if fragment!==nothing
213+
if fragment !== nothing
214214
print(io, '#')
215215
encode(io, fragment, is_rfc3986_fragment)
216216
end

0 commit comments

Comments
 (0)