Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LanguageServer.jl/SymbolServer.jl fails to index this package #127

Closed
rossviljoen opened this issue Feb 3, 2025 · 6 comments
Closed

LanguageServer.jl/SymbolServer.jl fails to index this package #127

rossviljoen opened this issue Feb 3, 2025 · 6 comments

Comments

@rossviljoen
Copy link

When trying to run LanguageServer.jl in an environment containing this package, the following error occurs:

ERROR: LoadError: Failure to obtain a bits-type
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] bitstype(::Type{CBinding.libclang.var"c\"struct CXVirtualFileOverlayImpl\""})
    @ CBinding ~/.julia/packages/CBinding/pvfFX/src/CBinding.jl:93
  [3] fields(::Type{CBinding.libclang.var"c\"struct CXVirtualFileOverlayImpl\""})
    @ CBinding ~/.julia/packages/CBinding/pvfFX/src/CBinding.jl:99
  [4] fieldnames(::Type{CBinding.libclang.var"c\"struct CXVirtualFileOverlayImpl\""})
    @ CBinding ~/.julia/packages/CBinding/pvfFX/src/aggregates.jl:34
  [5] fieldcount(::Type{CBinding.libclang.var"c\"struct CXVirtualFileOverlayImpl\""})
    @ CBinding ~/.julia/packages/CBinding/pvfFX/src/aggregates.jl:32
  [6] fieldcount(::Type{CBinding.Cptr{CBinding.libclang.var"c\"struct CXVirtualFileOverlayImpl\""}})
    @ CBinding ~/.julia/packages/CBinding/pvfFX/src/pointers.jl:64
  [7] Main.SymbolServer.DataTypeStore(t::Any, symbol::Symbol, parent_mod::Module, exported::Bool)
    @ Main.SymbolServer ~/.julia/packages/SymbolServer/2jiVV/src/symbols.jl:77
  [8] symbols(env::Dict{Symbol, Main.SymbolServer.ModuleStore}, m::Module, allnames::Base.IdSet{Symbol}, visited::Base.IdSet{Module}; get_return_type::Bool)
    @ Main.SymbolServer ~/.julia/packages/SymbolServer/2jiVV/src/symbols.jl:430
  [9] symbols
    @ ~/.julia/packages/SymbolServer/2jiVV/src/symbols.jl:419 [inlined]
 [10] symbols(env::Dict{Symbol, Main.SymbolServer.ModuleStore}, m::Nothing, allnames::Base.IdSet{Symbol}, visited::Base.IdSet{Module}; get_return_type::Bool)
    @ Main.SymbolServer ~/.julia/packages/SymbolServer/2jiVV/src/symbols.jl:479
 [11] symbols(env::Dict{Symbol, Main.SymbolServer.ModuleStore}, m::Nothing, allnames::Base.IdSet{Symbol}, visited::Base.IdSet{Module})
    @ Main.SymbolServer ~/.julia/packages/SymbolServer/2jiVV/src/symbols.jl:419
 [12] top-level scope
    @ ~/.julia/packages/SymbolServer/2jiVV/src/server.jl:119
in expression starting at /home/rviljoen/.julia/packages/SymbolServer/2jiVV/src/server.jl:1

failing because fieldcount(::Type{CBinding.Cptr{CBinding.libclang.var"c\"struct CXVirtualFileOverlayImpl\""}}) errors.

It's not clear to me if this is something that should be fixed in SymbolServer.jl or here

@rossviljoen
Copy link
Author

Corresponding issue for the language server: julia-vscode/LanguageServer.jl#1095

@krrutkow
Copy link
Member

krrutkow commented Feb 4, 2025

This error occurs because in C, it is possible to have a pointer to an opaque struct or union where it doesn't have its fields defined (yet). So attempting to count/enumerate its fields results in an error until the type is fully defined. How does your package currently handle abstract types? Where fieldcount(...) usage errors with:

ERROR: ArgumentError: type does not have a definite number of fields

This scenario would be fairly similar to that one, I think.

@rossviljoen
Copy link
Author

Thanks for the quick reply. The relevant expression in that package is:
isconcretetype(ur_t) && fieldcount(ur_t) > 0 ? collect(fieldnames(ur_t)) : Symbol[]

So, it assumes that a concrete type has fieldcount and fieldnames defined.
Would it be reasonable to have fieldcount return 0 until the fields are actually defined?

@krrutkow
Copy link
Member

krrutkow commented Feb 4, 2025

Yeah, that solution seems to work fine. I doubt there are any users relying on the error being thrown, so the change in behavior shouldn't be an issue.

@krrutkow
Copy link
Member

@rossviljoen CBinding v1.1 was released with the fix, could you please see if it resolves this issue?

@rossviljoen
Copy link
Author

That seems to have fixed it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants