luttje / glua-api-snippets

Scrapes the Garry's Mod Wiki in order to build Lua Language Server comments that will provide IDE suggestions and autocompletion.
MIT License
15 stars 5 forks source link

Handle overloaded functions like Angle #7

Closed luttje closed 1 year ago

luttje commented 1 year ago

Angle supports two ways of calling the function: https://wiki.facepunch.com/gmod/Global.Angle

Sadly we currently only parse one way, which can result in this error: image

If the wiki was consistent we could automatically use @overload, but the alternative usage is described in a form that seems non-trivial to parse:

<args>
        <arg name="pitch" type="number" default="0">The pitch value of the angle.

If this is an <page>Angle</page>, this function will return a copy of the given angle.

If this is a <page>string</page>, this function will try to parse the string as a angle. If it fails, it returns a 0 angle.
(See examples)</arg>
        <arg name="yaw" type="number" default="0">The yaw value of the angle.</arg>
        <arg name="roll" type="number" default="0">The roll value of the angle.</arg>
    </args>
Vurv78 commented 1 year ago

Would likely need to hardcode it if you really want people to be able to use that, pretty niche functionality though, if I were to personally use it I'd be fine with adding a diagnostic ignore for the line.

luttje commented 1 year ago

Thanks for your input, this helps me know I'm on the right track. :)

I'll probably hardcode it in the future!

For now I'll use this issue as a call for help to anyone who knows which other functions have overloads like this:

Vurv78 commented 1 year ago

I know Color can take strings for whatever reason (since it uses tonumber).

You probably also want to hardcode Color to return a Color instead of table (or maybe their wiki should be changed instead)

Also unrelated to this, probably want to handle default values, since calling Color(1, 2, 3) causes a warning (because of the alpha argument being missing, which is set to 255 by default as per the wiki)

Let me know if I should make these into separate issues

Made into separate issue.

Vurv78 commented 1 year ago

Now trying the extension, same thing that a lot of extensions struggle with is the need to hardcode SERVER, CLIENT and MENU_DLL as boolean?s