withered-magic / starpls

An LSP implementation for Starlark, the configuration language used by Bazel and Buck2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Bazel prelude

Strum355 opened this issue · comments

Currently, starpls will error when you try to reference something that is coming from the prelude file. Our use case is having a set of global variables teams can use to tag targets with e.g. tags = [TAG_TEAMXYZ]

References:
bazelbuild/bazel#11940
bazelbuild/bazel#1674
https://stackoverflow.com/questions/61168219/is-there-a-way-to-add-native-rules-to-bazel

Interesting, I actually wasn't aware of this feature at all! I'll take a look, should be fairly straightforward

Actually, a quick question: It says that the actual implementation of the prelude file works by prepending its contents to all BUILD files, but is it fine for your use case if starpls doesn't follow those exact semantics and instead treats it as a file that's implicitly loaded? I'd imagine that it would functionally look the same from an IDE perspective but maybe there's a few edge cases I'm not considering?

Edit: Actually nvm, I just saw in the more recent issue that it actually is implicitly loaded now!

Was about to send this here, but I see you found it so ill drop it for prosperity anyway 😊 bazelbuild/bazel@2a73a73

Landed this on main! Note that you might have to configure whatever editor you're on to recognize the prelude_bazel file as a Starlark file as well