is it possible to get intellisense going for `BUIL...
# general
f
is it possible to get intellisense going for
BUILD
files via vscode (i.e. autocomplete of target documentation and such, as if it was an actual python file with some globals in scope) ? and if so, how would one go about that? .. 🙏
b
I think it's been brought up before. Might try searching Slack history (although the Free tier only allows looking about 3 months back)
f
yeah, i tried — didn’t really get any good results, mainly some discussion of auto complete of targets from the cli
b
Unfortunately, none of the current maintainers uses VSCode so our collective knowledge of issues related to it is relatively limited. We'd love to get better at VSCode support, and have a goal of adding VS Code enthusiasts to the core team. So anyone interested in getting involved with that, please do ping me. We collaborate and mentor, as needed!
b
FWIW I use VS Code religiously, and some point in a past life wrote an extension. Just never felt driven to pick up this specific task 😅 The landscape of this kinda thing has such a learning curve IMO it's hard to want to ramp up 😞
b
I stand corrected, in the happiest of ways! ❤️
❤️ 2
b
Better Editor support is always a goal of the team's but also very intricate/expensive. I know I'd LOVE it for my org. @freezing-lamp-12123 if you find yourself wanting to do something cool like this, don't hesitate to reach out. 🙂
f
i would love to see it happen — i’m not a vscode extension developer myself, and neither lsp/bsp is something i’m experienced with — would not mind learning more about it though, and pointers on what first steps could be
BUILD files are python — with some boilerplate setup “hidden” is that right?
b
Yup!
To be very transparent. They are `exec`d with a set of
globals
f
what does that boilerplate look like?
b
That... is an excellent question 🙂 There's basically three layers, the last make this a little challenging (but maybe I'm not being imaginative) The first is all the "symbols" collected that are just Pants targets. Like
python_sources
and
pex_binary
. The second are "objects" and "CAOF"s exposed. They're "baked-in" like Targets, but don't have any magic. A good example is
http_source
which can be used as the value of a
file
/`resource`
source
field. See https://www.pantsbuild.org/v2.13/docs/reference-file as an example The last is user-defined macros. Basically "anything goes" preamble used for every
BUILD
file.
So I think (and not too hard) maybe it'd be feasible to autogen a
.pyi
file describing all targets/objects/COAFs/macros and then somehow plug into the Python support to tell it to always prentend the definitions in this
.pyi
are globally defined 🤔
f
sounds reasonable — i’m also not very experienced with the innards of python packaging/library management 😁
thank you very much for the pointers!
b
Always ❤️
f
Many IDEs and text editors support syntax highlighting for
BUILD
files. There is some limited support for code navigation and interaction as well such as reporting syntax errors, ability to comment/uncomment blocks of code, and collapse/expand code sections. • PyCharm users need to install the Bazel plugin and add the
BUILD
file name pattern to the
Bazel BUILD language
in the
Recognized File Types
section. See Change filename patterns associated with file type to learn more. • VSCode users only need to install the Bazel plugin.
this is what my devs are used as a temporary solution — works quite well actually
The
.pyi
idea won’t work, after my experiments, it seems, because the stubs are used when you import that module in another module, but you want the stubs to apply to the module currently being edited
b
@fresh-cat-90827, where's your sense of adventure?
Copy code
# __builtins__.pyi
def shell_sources(name: str) -> None: ...
🤣 1
So really this would apply to all Python files, which isn't ideal. Would be nice to "extend" the Python support for Pants, and then use this trick 🙂
You've got me dangerously close to just trying this out myself 👀
🙏 1
f
that’s very cool 🙂 I think we should try to do the “right thing” though 😛 we have https://github.com/JetBrains/bazel-bsp, we have https://github.com/zchee/starlark-language-server and some discussions https://github.com/pantsbuild/pants/issues/10920 🙂
1
b
Right, a "right" solution would have layers. I think leveraging `pyright`/`pylance` fits in well with a larger extension. Otherwise the alternative is providing full Python LSP support which is folly.
f
potentially, I didn’t have time to explore I am afraid 😞
I was thinking maybe we could piggy back on Starlark language server and extend the grammar with the Pants specific semantics
b
Well, taking
BUILD
files at face-value. They aren't Starlark, they ARE Python, just with a different set of
builtins
.
f
I see what you mean
b
Also https://github.com/zchee/starlark-language-server hasn't seen action in 3 years 😮
It must've gotten COVID early
😂 1
There should be a way to sign up for beer bribery. I'm a 6-pack of a porter from most of these fun Pants features 😅
f
i’ll happily sponsor that 🍻
unless you’re only into crazy rare investment kinds 😂
b
The craziest in my palette are Trappist beers 🍺
And my unpopular opinion is Rochefort 8 is better than 10 😂
👌 1
h
FWIW the data in
./pants help-all
may be of use. For example, it'll tell you what all the registered target types are, I think
b
I'm guessing it won't include parameter and type info, or objects and CAOFs
w
I feel like between shell completions,
pants.toml
completions (https://pantsbuild.slack.com/archives/C046T6T9U/p1659243255507499), and this - we have some big ticket items surrounding developer experience. Would these get lumped in as part of the experimental-bsp? Or separate? I'm happy to help out, as I'm a long-time VSCode convert for almost everything I do.
b
I think at least
BUILD
and
pants.toml
wouldn't be BSP, but closer to LSP or just a dedicated extension
f
the communication layer of the Pants BSP support could be leveraged to allow Pants to answer LSP queries though.
🤔 1
b
f
:hide:
😆
it sounds soooooper awesome!
b
The neat thing is its very small server boilerplate, and is implemented as an LSP, so conceivably would work for JetBrains IDEs too (or any, with the right client)
f
i wish my python would be better, so i didn’t feel like things take forever in getting any progress when building a pants plugin
f
I wouldn’t worry about knowledge of Python language per se, David. I think to be able to write a plugin, you need to have a focused, dedicated time so that you can get familiar with the codebase and understand the movings parts. I remember that it never worked trying to write a plugin and jump between various small work parts that caused interruptions.
1
However, once you become more familiar with the code, you’ll be able to switch context without losing the velocity and feeling lost again 😄 at least that’s how it worked with me
but I do appreciate that number of moving parts — feel free to ask in the #development, it’s incredible how helpful everyone is
👌 1
f
i think i’m also still unsure about how some of the innards interact — but it’s primarily because my memory is so poor that i forget about concepts i’ve read about previously but never really clicked in actual usage of it
f
agree 100%. It never worked for me trying to do an hour here and there. I had to do half a day blocks.
f
yeah, hoping to find more time to dedicate toward my experiments