Skip to content

Commit 70437bc

Browse files
authored
Merge pull request #270 from julia-vscode/tidy
Tidy
2 parents 35db0e3 + f1af5a0 commit 70437bc

File tree

1 file changed

+12
-50
lines changed

1 file changed

+12
-50
lines changed

src/references.jl

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ function resolve_ref(x::EXPR, scope::Scope, state::State)::Bool
5555
setref!(x, Binding(noname, nothing, nothing, []))
5656
return true
5757
end
58-
x1, mn = nameof_expr_to_resolve(x)
59-
mn == true && return true
58+
mn = nameof_expr_to_resolve(x)
59+
mn === nothing && return true
6060

6161
if scopehasbinding(scope, mn)
62-
setref!(x1, scope.names[mn])
62+
setref!(x, scope.names[mn])
6363
resolved = true
6464
elseif scope.modules isa Dict && length(scope.modules) > 0
6565
for m in values(scope.modules)
@@ -107,11 +107,11 @@ function resolve_ref_from_module(x::EXPR, scope::Scope, state::State)::Bool
107107
hasref(x) && return true
108108
resolved = false
109109

110-
x1, mn = nameof_expr_to_resolve(x)
111-
mn == true && return true
110+
mn = nameof_expr_to_resolve(x)
111+
mn === nothing && return true
112112

113113
if scope_exports(scope, mn, state)
114-
setref!(x1, scope.names[mn])
114+
setref!(x, scope.names[mn])
115115
resolved = true
116116
end
117117
return resolved
@@ -144,10 +144,8 @@ function initial_pass_on_exports(x::EXPR, name, server)
144144
for a in x.args[3] # module block expressions
145145
if headof(a) === :export
146146
for i = 1:length(a.args)
147-
if isidentifier(a.args[i]) && valof(a.args[i]) == name
148-
if !hasref(a.args[i])
149-
Delayed(scopeof(x), server)(a.args[i])
150-
end
147+
if isidentifier(a.args[i]) && valof(a.args[i]) == name && !hasref(a.args[i])
148+
Delayed(scopeof(x), server)(a.args[i])
151149
end
152150
end
153151
end
@@ -220,12 +218,11 @@ function resolve_getfield(x::EXPR, b::Binding, state::State)::Bool
220218
end
221219

222220
function resolve_getfield(x::EXPR, parent_type, state::State)::Bool
223-
hasref(x) && return true
224-
return false
221+
hasref(x)
225222
end
226223

227224
function is_overloaded(val::SymbolServer.SymStore, scope::Scope)
228-
(vr = val.name isa SymbolServer.FakeTypeName ? val.name.name : val.name)
225+
vr = val.name isa SymbolServer.FakeTypeName ? val.name.name : val.name
229226
haskey(scope.overloaded, vr)
230227
end
231228

@@ -257,15 +254,6 @@ function resolve_getfield(x::EXPR, m::SymbolServer.ModuleStore, state::State)::B
257254
return resolved
258255
end
259256

260-
# function is_overloaded1(x, tls, val)
261-
# vr = val.name isa SymbolServer.FakeTypeName ? val.name.name : val.name
262-
# if haskey(tls.names, valof(x)) && tls.names[valof(x)] isa Binding && first(tls.names[valof(x)]) isa SymbolServer.FunctionStore
263-
264-
# end
265-
# haskey(tls.overloaded, vr)
266-
267-
# end
268-
269257
function resolve_getfield(x::EXPR, parent::SymbolServer.DataTypeStore, state::State)::Bool
270258
hasref(x) && return true
271259
resolved = false
@@ -282,33 +270,7 @@ end
282270

283271
resolvable_macroname(x::EXPR) = isidentifier(x) && CSTParser.ismacroname(x) && refof(x) === nothing
284272

285-
"""
286-
module_safety_trip(scope::Scope, visited_scopes)
287-
288-
Checks whether the scope is a module and we've visited it before,
289-
otherwise adds the module to the list.
290-
"""
291-
function module_safety_trip(scope::Scope, visited_scopes)
292-
if CSTParser.defines_module(scope.expr) && length(scope.expr.args) > 1 && isidentifier(scope.expr.args[2])
293-
s_m_name = valofid(scope.expr.args[2])
294-
if s_m_name in visited_scopes
295-
return true
296-
else
297-
push!(visited_scopes, s_m_name)
298-
end
299-
end
300-
return false
301-
end
302-
303-
304-
function nameof_expr_to_resolve(x)
305-
if isidentifier(x)
306-
mn = valofid(x)
307-
else
308-
return x, true
309-
end
310-
x, mn
311-
end
273+
nameof_expr_to_resolve(x) = isidentifier(x) ? valofid(x) : nothing
312274

313275
"""
314276
valofid(x)
@@ -324,4 +286,4 @@ new_within_struct(x::EXPR)
324286
Checks whether x is a reference to `new` within a datatype constructor.
325287
"""
326288
new_within_struct(x::EXPR) = isidentifier(x) && valofid(x) == "new" && is_in_fexpr(x, CSTParser.defines_struct)
327-
is_special_macro_term(x::EXPR) = isidentifier(x) && (valofid(x) == "__source__" || valofid(x) == "__module__") && is_in_fexpr(x, CSTParser.defines_macro)
289+
is_special_macro_term(x::EXPR) = isidentifier(x) && (valofid(x) == "__source__" || valofid(x) == "__module__") && is_in_fexpr(x, CSTParser.defines_macro)

0 commit comments

Comments
 (0)