https://pantsbuild.org/ logo
#general
Title
# general
f

freezing-lamp-12123

08/02/2022, 3:06 PM
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

bitter-ability-32190

08/02/2022, 3:07 PM
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

freezing-lamp-12123

08/02/2022, 3:15 PM
yeah, i tried — didn’t really get any good results, mainly some discussion of auto complete of targets from the cli
b

busy-vase-39202

08/02/2022, 3:15 PM
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

bitter-ability-32190

08/02/2022, 3:17 PM
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

busy-vase-39202

08/02/2022, 3:18 PM
I stand corrected, in the happiest of ways! ❤️
❤️ 2
b

bitter-ability-32190

08/02/2022, 3:20 PM
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

freezing-lamp-12123

08/02/2022, 3:40 PM
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

bitter-ability-32190

08/02/2022, 3:41 PM
Yup!
To be very transparent. They are `exec`d with a set of
globals
f

freezing-lamp-12123

08/02/2022, 3:41 PM
what does that boilerplate look like?
b

bitter-ability-32190

08/02/2022, 3:45 PM
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

freezing-lamp-12123

08/02/2022, 3:59 PM
sounds reasonable — i’m also not very experienced with the innards of python packaging/library management 😁
thank you very much for the pointers!
b

bitter-ability-32190

08/02/2022, 4:16 PM
Always ❤️
f

fresh-cat-90827

08/02/2022, 4:52 PM
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

bitter-ability-32190

08/02/2022, 5:15 PM
@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

fresh-cat-90827

08/02/2022, 5:22 PM
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

bitter-ability-32190

08/02/2022, 5:23 PM
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

fresh-cat-90827

08/02/2022, 5:24 PM
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

bitter-ability-32190

08/02/2022, 5:25 PM
Well, taking
BUILD
files at face-value. They aren't Starlark, they ARE Python, just with a different set of
builtins
.
f

fresh-cat-90827

08/02/2022, 5:25 PM
I see what you mean
b

bitter-ability-32190

08/02/2022, 5:25 PM
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

freezing-lamp-12123

08/02/2022, 5:51 PM
i’ll happily sponsor that 🍻
unless you’re only into crazy rare investment kinds 😂
b

bitter-ability-32190

08/02/2022, 5:55 PM
The craziest in my palette are Trappist beers 🍺
And my unpopular opinion is Rochefort 8 is better than 10 😂
👌 1
h

happy-kitchen-89482

08/02/2022, 7:26 PM
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

bitter-ability-32190

08/02/2022, 7:27 PM
I'm guessing it won't include parameter and type info, or objects and CAOFs
w

wide-midnight-78598

08/02/2022, 7:36 PM
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

bitter-ability-32190

08/02/2022, 7:37 PM
I think at least
BUILD
and
pants.toml
wouldn't be BSP, but closer to LSP or just a dedicated extension
f

fast-nail-55400

08/02/2022, 9:17 PM
the communication layer of the Pants BSP support could be leveraged to allow Pants to answer LSP queries though.
🤔 1
b

bitter-ability-32190

08/11/2022, 4:52 PM
f

freezing-lamp-12123

08/11/2022, 4:56 PM
:hide:
😆
it sounds soooooper awesome!
b

bitter-ability-32190

08/11/2022, 5:29 PM
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

freezing-lamp-12123

08/11/2022, 5:56 PM
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

fresh-cat-90827

08/11/2022, 5:58 PM
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

freezing-lamp-12123

08/11/2022, 6:01 PM
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

fresh-cat-90827

08/11/2022, 6:02 PM
agree 100%. It never worked for me trying to do an hour here and there. I had to do half a day blocks.
f

freezing-lamp-12123

08/11/2022, 6:04 PM
yeah, hoping to find more time to dedicate toward my experiments