Just released a new feature for my VSCode plugin PICO-8 LS: Code formatting! (Link to install VSCode extension)
IMO it's most useful for making minified code from e.g. a tweetcart more readable. Example:
(The code snippet above is the excellent TweetTweetJam entry XTRIS, by Fletch: https://fletchmakesstuff.itch.io/xtris)
Note that it's accessible in multiple ways:
- The regular
Format Document
command in VSCode (alt+shift+F is the default keyboard shortcut) Command Palette
->PICO-8 LS: Format File
for regular code formattingCommand Palette
->PICO-8 LS: Format File: Each Statement on Separate Line
which will put each statement on a separate line. (By default, the formatter lets multiple statements be on the same line, preserving your cart structure.) This is the command used in the GIF above.
Please be careful when using this tool, and save a backup of your cart before formatting it! Since this is the first time it's being released, there may still be issues to work through.
Big thanks to beetrootpaul for help implementing this feature!
Report any issues here: https://github.com/japhib/pico8-ls/issues
Thanks for your work!
There's an issue with format and export.
When exporting to png file, the very first 2 lines of comment are displayed on the cover of the cart.
But the formatting will leave an empty line after __lua__
which makes the cover only displays the first 1 line on it.
Edit: I am leaving all these many, many words here because there's still something weird going on, but see my other edit at the bottom of this post for my latest findings.
Hi. This isn't about the code formatting feature, but this seems to be the most recent post you've made about your extension.
I used this extension for a couple of days, and it seemed to be working OK. Then I broke up my project into multiple Lua files, and now code navigation seems to be completely borked. The tool tips I get on hover are also really weird.
For example, in my _update()
function, which is in the main .p8
file, I call init_tiles()
. CTRL+hovering over init_tiles()
sometimes shows the tool tip Click to show 2 definitions
, and sometimes shows a seemingly random variable name from somewhere in the code, such as gp
, x
, or y
. CTRL+clicking on it actually takes me to the correct place in the correct file on the first try, but if I CTRL+tab back to the .p8
file and CTRL+click again, it takes me to this seemingly random chunk of code.
ist={ -- grid position of selector gp={x=1,y=1}, focus="grid" } |
This code is in input_management.lua
. It is outside the scope of any functions. The actual init_tiles()
function is in tiles.lua
. Notice that gp
is one of the things that sometimes shows up when I CTRL+hover over init_tiles()
in the .p8
file. It's worth noting that gp
showing up when I CTRL+hover doesn't mean it will actually jump to gp
when I click. Sometimes it will jump to the correct place when it says gp
. Also, occasionally, with no rhyme or reason that I can ascertain, CTRL+clicking will bring up that little VSCode picture-in-picture view of the code that you can look at before jumping there. The preview usually shows the wrong place in the code.
Before init_tiles()
is configure_keys()
, which, like init_tiles()
, takes no arguments. Unlike init_tiles()
, configure_keys()
has its return value assigned to a variable.
kcfg=configure_keys() |
CTRL+clicking configure_keys()
seems to work every time.
After init_tiles()
is cr_field()
, which takes a bunch of arguments and also has its return value assigned to a variable.
f=cr_field( 0,0,8,8,8,8,2,2,.5,.5,16,2, cr_tile_pool({{idx=1,cnt=1}, {idx=2,cnt=1}, {idx=3,cnt=1}, {idx=4,cnt=1}}) ) |
CTRL+clicking cr_field()
seems to work every time.
CTRL+clicking cr_tile_pool()
, which is used as one of the arguments to cr_field()
jumps randomly, sometimes to a different file, sometimes within the .p8
file where the code above lives. So far, all of the clicking I have described has taken place in code that in in the main .p8
file, because that is the code that calls into code found in other files. Navigating within .lua
files, and even between .lua
files seems to work. It's only code left in the .p8
file that seems to cause problems.
Other edit: When I started this post, I still had a bunch of code and globals and code in the .p8
file because I ran into issues when I first broke everything into multiple files. For some reason, even though I was importing main.lua
first, some of the downstream imports were complaining about accessing global values that didn't exist. I thought it was a hoisting issue, or maybe something to do with the scoping of included code. Moving the globals and other code from main.lua
back into the .p8
file seemed to fix that. However, at that point I had not finished moving the rest of the code into individual files. I still had several -->8
sections in the .p8
file. I don't know what kind of dependency problem I created by having some but not all of the code broken into different files, but now that it is, I am able to move the last of the code from the .p8
file into main.lua
, and, as far as I can tell, that has solved the code navigation problem.
In summary, this problem seems to only exist when you mix code in the .p8
file with code brought in via #include
s. After moving the last of the code into main.lua
and making thirty or forty random mavigation clicks, this problem hasn't come back.
Thanks for your work on this extension. Also, as someone whose username here is lifted directly from an old Apogee game, I love that you did a Commander Keen demake. Demaking an ancient CGA game is some sort of demake inception.
Thanks for the detailed bug report! My time to work on this extension is pretty thin these days but when I get a chance, I’ll look into this.
And glad you appreciate the Keen demake!
P.S. for anyone else wanting to report a bug, I use GitHub Issues for that, on the pico8-ls repo:
https://github.com/japhib/pico8-ls/issues
(I even made a placeholder issue for the above bug report, so that I don’t forget about it: https://github.com/japhib/pico8-ls/issues/61)
[Please log in to post a comment]