Skip to content

Commit 5740afa

Browse files
authored
Merge pull request #302 from julia-vscode/sp/tolerate-binding-errors
fix: tolerate binding errors
2 parents 1f71596 + 1225af3 commit 5740afa

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/symbols.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct ModuleStore <: SymStore
1616
used_modules::Vector{Symbol}
1717
end
1818

19-
ModuleStore(m) = ModuleStore(VarRef(m), Dict{Symbol,Any}(), _doc(Base.Docs.Binding(m, nameof(m))), true, unsorted_names(m), Symbol[])
19+
ModuleStore(m) = ModuleStore(VarRef(m), Dict{Symbol,Any}(), _doc(m, nameof(m)), true, unsorted_names(m), Symbol[])
2020
Base.getindex(m::ModuleStore, k) = m.vals[k]
2121
Base.setindex!(m::ModuleStore, v, k) = (m.vals[k] = v)
2222
Base.haskey(m::ModuleStore, k) = haskey(m.vals, k)
@@ -84,7 +84,7 @@ function DataTypeStore(@nospecialize(t), symbol, parent_mod, exported)
8484
else
8585
[]
8686
end
87-
DataTypeStore(FakeTypeName(ur_t), FakeTypeName(ur_t.super), parameters, types, isconcretetype(ur_t) && fieldcount(ur_t) > 0 ? collect(fieldnames(ur_t)) : Symbol[], MethodStore[], _doc(Base.Docs.Binding(parent_mod, symbol)), exported)
87+
DataTypeStore(FakeTypeName(ur_t), FakeTypeName(ur_t.super), parameters, types, isconcretetype(ur_t) && fieldcount(ur_t) > 0 ? collect(fieldnames(ur_t)) : Symbol[], MethodStore[], _doc(parent_mod, symbol), exported)
8888
end
8989

9090
function Base.show(io::IO, dts::DataTypeStore)
@@ -101,9 +101,9 @@ end
101101

102102
function FunctionStore(@nospecialize(f), symbol, parent_mod, exported)
103103
if f isa Core.IntrinsicFunction
104-
FunctionStore(VarRef(VarRef(Core.Intrinsics), nameof(f)), MethodStore[], _doc(Base.Docs.Binding(parent_mod, symbol)), VarRef(VarRef(parentmodule(f)), nameof(f)), exported)
104+
FunctionStore(VarRef(VarRef(Core.Intrinsics), nameof(f)), MethodStore[], _doc(parent_mod, symbol), VarRef(VarRef(parentmodule(f)), nameof(f)), exported)
105105
else
106-
FunctionStore(VarRef(VarRef(parent_mod), nameof(f)), MethodStore[], _doc(Base.Docs.Binding(parent_mod, symbol)), VarRef(VarRef(parentmodule(f)), nameof(f)), exported)
106+
FunctionStore(VarRef(VarRef(parent_mod), nameof(f)), MethodStore[], _doc(parent_mod, symbol), VarRef(VarRef(parentmodule(f)), nameof(f)), exported)
107107
end
108108
end
109109

@@ -501,7 +501,7 @@ function symbols(env::EnvStore, m::Union{Module,Nothing} = nothing, allnames::Ba
501501
cache[s] = VarRef(x)
502502
end
503503
else
504-
cache[s] = GenericStore(VarRef(VarRef(m), s), FakeTypeName(typeof(x)), _doc(Base.Docs.Binding(m, s)), s in getnames(m))
504+
cache[s] = GenericStore(VarRef(VarRef(m), s), FakeTypeName(typeof(x)), _doc(m, s), s in getnames(m))
505505
end
506506
end
507507
else
@@ -540,7 +540,7 @@ function load_core(; get_return_type = false)
540540
end
541541

542542
cache[:Base][Symbol("@.")] = cache[:Base][Symbol("@__dot__")]
543-
cache[:Core][:Main] = GenericStore(VarRef(nothing, :Main), FakeTypeName(Module), _doc(Base.Docs.Binding(Main, :Main)), true)
543+
cache[:Core][:Main] = GenericStore(VarRef(nothing, :Main), FakeTypeName(Module), _doc(Main, :Main), true)
544544
# Add built-ins
545545
builtins = Symbol[nameof(getfield(Core, n).instance) for n in unsorted_names(Core, all = true) if isdefined(Core, n) && getfield(Core, n) isa DataType && isdefined(getfield(Core, n), :instance) && getfield(Core, n).instance isa Core.Builtin]
546546
cnames = unsorted_names(Core)

src/utils.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ function sha_pkg(manifest_dir::AbstractString, pe::PackageEntry)
196196
return isdir(src_path) ? sha2_256_dir(src_path) : nothing
197197
end
198198

199+
function _doc(mod::Module, sym::Symbol)
200+
try
201+
# constructing the binding may fail with e.g. "Constant binding was imported from multiple modules",
202+
# so we just wrap this in yet another try-catch
203+
_doc(Base.Docs.Binding(mod, sym))
204+
catch err
205+
@debug "Error computing docs for binding ($mod, $sym)" ex=(err, catch_backtrace())
206+
return ""
207+
end
208+
end
209+
199210
function _doc(binding::Base.Docs.Binding)
200211
try
201212
sig = Union{}
@@ -204,7 +215,7 @@ function _doc(binding::Base.Docs.Binding)
204215
result === nothing || return string(result)
205216
end
206217
results, groups = Base.Docs.DocStr[], Base.Docs.MultiDoc[]
207-
# Lookup `binding` and `sig` for matches in all modules of the docsystem.
218+
# Lookup `binding` and `sig` for matches in all modules of the docsystem.
208219
for mod in Base.Docs.modules
209220
dict = Base.Docs.meta(mod)::IdDict{Any,Any}
210221
if haskey(dict, binding)

0 commit comments

Comments
 (0)