cameron-martin / bazel-lsp

A language server implementation for Bazel
Apache License 2.0
36 stars 1 forks source link

Panic when rendering Label documentation #41

Closed hauserx closed 2 weeks ago

hauserx commented 3 weeks ago

Getting following stack trace in bazel-lsp, after some auto-completion suggestion are being loaded. Looks like the Label symbol is global and when documentation for it is being loaded the server fails.

Not sure why it does not occur for others though, for me it happens with each usage of bazel-lsp, making it unusable.

#7  0x0000555ebb0da226 in core::option::unwrap_failed () at library/core/src/option.rs:1978
#8  0x0000555ebb68d7bc in core::option::Option<&str>::unwrap<&str> (self=...) at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:931
#9  starlark::docs::markdown::render_function_parameters::{closure#2} (output="") at external/rules_rust~~crate~crates__starlark-0.12.0/src/docs/markdown.rs:151
#10 0x0000555ebb661dc2 in core::iter::adapters::filter_map::filter_map_fold::{closure#0}<&&starlark::docs::DocParam, (&alloc::string::String, &core::option::Option<starlark::docs::DocString>), alloc::string::String, starlark::docs::markdown::render_function_parameters::{closure_env#1}, starlark::docs::markdown::render_function_parameters::{closure_env#2}> (acc="", item=0x555ebdf10030) at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/iter/adapters/filter_map.rs:39
#11 0x0000555ebb8aa867 in core::slice::iter::{impl#181}::fold<&starlark::docs::DocParam, alloc::string::String, core::iter::adapters::filter_map::filter_map_fold::{closure_env#0}<&&starlark::docs::DocParam, (&alloc::string::String, &core::option::Option<starlark::docs::DocString>), alloc::string::String, starlark::docs::markdown::render_function_parameters::{closure_env#1}, starlark::docs::markdown::render_function_parameters::{closure_env#2}>> (self=..., init="", f=...)
    at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/slice/iter/macros.rs:232
#12 0x0000555ebb6582ec in core::iter::adapters::filter_map::{impl#2}::fold<(&alloc::string::String, &core::option::Option<starlark::docs::DocString>), core::slice::iter::Iter<&starlark::docs::DocParam>, starlark::docs::markdown::render_function_parameters::{closure_env#1}, alloc::string::String, starlark::docs::markdown::render_function_parameters::{closure_env#2}> (self=..., init=<error reading variable: Cannot access memory at address 0x0>, fold=...) at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/iter/adapters/filter_map.rs:148
#13 0x0000555ebb68d3ee in starlark::docs::markdown::render_function_parameters (params=&[starlark::docs::DocParam](size=1) = {...}) at external/rules_rust~~crate~crates__starlark-0.12.0/src/docs/markdown.rs:139
#14 0x0000555ebb68dfcc in starlark::docs::markdown::render_function (name="Label", function=0x7fff51bb61f8) at external/rules_rust~~crate~crates__starlark-0.12.0/src/docs/markdown.rs:175
#15 0x0000555ebb68f1bb in starlark::docs::markdown::render_doc_member (name="Label", item=0x7fff51bb61f8) at external/rules_rust~~crate~crates__starlark-0.12.0/src/docs/markdown.rs:265
#16 0x0000555ebb29933f in starlark_lsp::server::{impl#8}::get_global_symbol_completion_items::{closure#0}<bazel_lsp::bazel::BazelContext<bazel_lsp::client::BazelCli>> () at external/rules_rust~~crate~crates__starlark_lsp-0.12.0/src/server.rs:918

Created provisional fix:https://github.com/facebook/starlark-rust/pull/121

With the fix I get following documentation, note that input parameter has no documentation:

image

bazel version: 7.1.0, --noenable_bzlmod os: WSL2, Ubuntu 22.04 Using neovim lsp integration

cameron-martin commented 2 weeks ago

Although the problem is in starlark-rust, we can work around this by not generating empty documentation. I'll put up a fix for this.