japhib / pico8-ls

PICO-8 Language Server
MIT License
64 stars 8 forks source link

feat: Add `region` code fold support & test files #49

Closed TheCyberRonin closed 7 months ago

TheCyberRonin commented 8 months ago

If this PR is accepted, it will add support for code folding using regions and test files associated with different region possibilities.

Code folding is really nice using regions and I use it all the time. I noticed that this language server didn't have it and saw that it was fairly easy to add support for it.

The test files show the different ways that a region can start and end in both of the supported file formats.

As far as usefulness, you can turn this chunk of code:

-------------------------------
-- palettes
-------------------------------

function init_palettes()
 local a=0x5d00
 for p=0,15 do
  for c=0,15 do
   poke(a,bor(sget(p,c),c==14 and 0x80))
   a+=1
  end
 end
end

function set_palette(no,off)
 memcpy(off or 0x5f00,
  0x5d00+shl(flr(no),4),
  16)
end

To this:


-- #region palettes

function init_palettes()
 local a=0x5d00
 for p=0,15 do
  for c=0,15 do
   poke(a,bor(sget(p,c),c==14 and 0x80))
   a+=1
  end
 end
end

function set_palette(no,off)
 memcpy(off or 0x5f00,
  0x5d00+shl(flr(no),4),
  16)
end
-- #endregion

The second would allow you to fold the code in between the region comments so you can hide it and worry about the stuff you want to.

TheCyberRonin commented 7 months ago

Glad that I could add something useful!