-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support document formatting #26
Comments
I would love to support this at some point. It's unfortunately a bit more complicated than you might think, or at least my past attempts have run into issues pretty quickly. But this would be a great feature to have. |
I totally understand it! 🙂 Something you probably thought about already, but just in case:
|
That's great info! I'll definitely take a look at that stuff as a starting point, whenever I get to this. |
Or if you want to take a crack at it, feel free! I'm happy to provide help getting set up for developing this extension, as well as for figuring out how to set up the formatter and adapt it to PICO-8 syntax. |
@japhib I might try. Not promising anything, since I my lose motivation on a first obstacle, especially with very little time left after hours for such topics 😅 But definitely if you are able to provide me with some good YT video or article or just short set of instructions on how to develop a VS Code plugin, it would help me a ton (I mean stuff like "I have pico8-ls from the official source installed, but how do I tell VS Code that I want to use me locally checked out fork instead" and "how do I tell VS Code to load most recent changes of that locally developed plugin?") In case you find it easier, you can DM me on Discord. Same username as here, active a little bit on PICO-8 server among others. |
I think I managed to setup it:
|
one more piece of info: chain of dependencies is longer, but at least one of them seems partially covered: https://github.com/PictElm/pico8parse is a PICO-8 flavour of luaparse. I didn't manage to use it out of the box (it expects a p8 cart with all its sections instead of solely a Lua file), but it is really promising I managed to chain most of dependencies together and see some how code format got affected by some changes I made locally. No more updates for now, will let you know if I achieve anything Proof-of-Concept-and-git-commit worthy 🙂 |
Sounds like some good progress! Just a note -- Ultimately, I'd like to have the formatter use |
That sounds great! One of my biggest concerns from yesterday night experimenting was that it might end up with N independent tools, each one creating AST on its own way, with different set of features 😅 |
|
A few things on 3:
|
Actually, I think I found the issue. This is what Since the dependency on It looks like the latest version of So now the issue is to update the version of lustils that Another note: on your branch it looks like you added the dependencies on |
thanks for your answers, they already provide me with a lot of info! Regarding a proper setup and inlining files: to not get overwhelmed in a limited time, I approach this in a veeery step-by-step way. So yes, please keep that feedback coming! I hope after some time it will all converge into a proper final solution! 🙂 I will come back with specific questions later, after I will get a chance to have another moment on this 🙂 |
Update: I just found https://code.visualstudio.com/api/language-extensions/language-server-extension-guide and it clarifies things even more for me. You know, VS Code extension dev is totally new for me, so that guide helped to understand where to run that "Launch Client" task 😄 Right now might MVP goal is to implement I also wonder what issues did you have with your What do you think in general @japhib ? |
To be honest, it's been long enough that I don't remember the specific issues. I think in general there were just a lot of little issues, and it was lower priority for me at the time, so I decided to put it off. I think in general basing it off of the existing The |
quick thought: would it be wrong to include comments in parsed AST so they could be inserted as any other statement with let's say (update: I read somewhere that it is then no longer AST, but FST – Full Syntax Tree. Not sure if such approach is fundamentally different for this extension, just thinking loudly) |
I had some time today so I went ahead and took a stab at some of the problems you're facing. I'm not sure how best to commit exactly to your branch, since your branch is a fork of mine, so for now I figure we can just cherry-pick commits back and forth as needed. My branch is called Note that a bunch of the changes are just formatter changes. I have my editor format on save so it's semi-unavoidable. If you want the same behavior you can install the Here's my progress:
Still needs work:
long_fun(
-- first arg
abc,
-- second arg
def
) gets transformed to this: long_fun(abc, def)
-- first arg
-- second arg So, that definitely needs some work. Anyways, try it out and let me know what you think! Please continue to point out any specific cases where it does weird things, and I'll be sure to fix those and include them in testing. (Btw, you don't have to ping me on each comment - I receive a notification for every comment on this thread anyway, I believe because I commented once and now GitHub knows I'm following it. 🙂) |
I also eventually want the formatter to be smart about preserving the original author's style. Part of that would be the ability to customize how the formatter works, i.e. specifying an option of whether you prefer spaces around your arithmetic operators like Another part of that would be detecting when something like a table literal is in one single line and not expanding it to multiple lines. For example, this: this.dash_target={x=0,y=0}
this.dash_accel={x=0,y=0}
this.hitbox = {x=1,y=3,w=6,h=5} gets expanded to this: this.dash_target = {
x = 0,
y = 0
}
this.dash_accel = {
x = 0,
y = 0
}
this.hitbox = {
x = 1,
y = 3,
w = 6,
h = 5
} which reads totally different and feels like it shouldn't have been changed so drastically. Anyways, not totally sure how I want to approach that yet, but something to keep in mind. |
(answered in PR since the previous intention to move discussion there didn't really happen 😄 👉 #27 (comment) ) (but if you prefer to discuss here in the issues, just let me know 🙂 I just assumed it is more native to GitHub's design to discuss implementation detail in PR, but I have no real open source experience, just commercial ones, where discussion usually happens elsewhere outside GitHub) |
Separate but related question: what do you think about externalising parser and formatter to their own packages at some point in the future? Why am I asking? Because now, when I started to believe my transition to VS Code for PICO-8 code might really happen (due to ongoing work on formatter), I realised there is one more piece of this puzzle for me to transition completely. And that is… minifier. Right now I use https://github.com/beetrootpaul/luamin (my slightly modified fork of Therefore why I think having an access to pico8-ls parser could help to build other tools using it, for example a custom minifier 🙂 |
I would support that. I was mainly waiting for a legitimate use case (such as the minifier, as you mention) to come along. Do you mind opening another issue to track work on that? Go ahead and include all the info/suggestions/use cases from this comment. |
OK 🙂 👉 #29 |
Already fixed with 0.5.0 |
(Disclaimer: Maybe it's just me not familiar with VS Code, since I do not use it on a daily basis 🙂 )
When I run
Format Document
VS Code action on a Lua file (which I#include
in my p8 cart), VS Code shows me "There is no formatter for 'pico-8-lua' files installed." prompt and no formatting happens 🙁For me, lack of document formatting is one of last reasons why I do code for PICO-8 in another IDE I am used to, even though there is no dedicated PICO-8 plugin for that IDE (which means I have to write vanilla Lua instead of the PICO-8 flavour).
pico8-ls
only (I don't know how to check its version, but its README embedded in VS Code has "0.4.8 (9/23/2022)" as the most recent entry in the changelog)The text was updated successfully, but these errors were encountered: