japhib / pico8-ls

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

Symbols update #33

Open mika76 opened 1 year ago

mika76 commented 1 year ago

Just created a draft pull request here to track changes and see if it's heading in the direction that you like @japhib I still have more changes for the lua comment doc, but am just having some issues because I made comments tokens and now parsing breaks in a couple of places...

mika76 commented 1 year ago

Oh and I don't think the compile/bundling will work yet since I changed the compile file from main.js to extension.js (basically I put everything back to the basic tutorial for lsp server and then worked from there to make it debuggable)

mika76 commented 1 year ago

PPS 🤣 I did all these changes in a jumble then tried to selectively stage and commit - I think I got all the ones needed for these specific changes but be aware I might have missed something.

japhib commented 1 year ago

Seems like there's a bunch of stuff missing though. I don't see anything related to ldoc, for example, or anything in server.ts which would translate the new symbol types.

mika76 commented 1 year ago

Seems like there's a bunch of stuff missing though. I don't see anything related to ldoc, for example, or anything in server.ts which would translate the new symbol types.

I'm still trying to resolve the comment parsing - I made comments a proper Token, but then that kinda screwed up some of the Statement, Table and Function parsing so it was showing errors (it was not expecting extra comment tokens) - but this is also the part that is reading in and parsing the descriptions for the ldoc.

I've just hit a bit of a busy patch at work and haven't had a chance to clean it all up - I will get back to it in a couple of days hopefully...

mika76 commented 1 year ago

Looking at https://www.lua.org/manual/5.4/manual.html#3.1 I can see that even the spec says comments are mostly ignored, so I'm going to rewrite the comment part a little because I don't like the direction it took. Making it a token makes it really difficult to ignore, I have to basically put in code all over the place to make sure comments are skipped.

mika76 commented 1 year ago

So got a bit further now - I had to do a bit of rewriting because I didn't like how I did it before.

  1. Originally short comments were being stored separated by line breaks, so I had to build in a way to group them together into a comment block.
  2. I had to propagate the comments through the lexer to the parser and symbols visitor somehow - currently a DocComment is only being attached to a function keyword but I think it should be connected to a table as well (there is no one definition for luadoc and annotations, plus this is for pico-8 so I don't think I'm going to make it very advanced and try and keep it simple)
  3. I had to also create a way to find the scope of the symbol being queried (I've only changed the OnHover for the moment) but I think I managed - still lots of testing to be done.
  4. Only rudimentary display of the markdown for the moment - this needs to be cleaned up and formatted nicely

Still it's been fun and I'm getting there 😊

Any comments or suggestions welcome.