dapetcu21 / atom-autocomplete-lua

Extensible autocomplete+ provider for Lua
35 stars 6 forks source link

Problem with variants and named types #15

Open rm-code opened 7 years ago

rm-code commented 7 years ago

Hi @dapetcu21,

I'm currently rewriting my love-atom package to work with atom-autocomplete-lua and I've run into a small into issue with the return types of function variants.

Below is an example of how my JSON file is formatted:

"newImageData":{
   "type":"function",
   "description":"Create a new ImageData object.",
   "link":"https://love2d.org/wiki/love.image.newImageData",
   "variants":[
      {
         "args":[
            {
               "name":"width"
            },
            {
               "name":"height"
            }
         ],
         "returnTypes":[
            {
               "type":"ref",
               "name":"ImageData"
            }
         ]
      },
      {
         "args":[
            {
               "name":"width"
            },
            {
               "name":"height"
            },
            {
               "name":"data"
            }
         ],
         "returnTypes":[
            {
               "type":"ref",
               "name":"ImageData"
            }
         ]
      },
      {
         "args":[
            {
               "name":"filename"
            }
         ],
         "returnTypes":[
            {
               "type":"ref",
               "name":"ImageData"
            }
         ]
      },
      {
         "args":[
            {
               "name":"filedata"
            }
         ],
         "returnTypes":[
            {
               "type":"ref",
               "name":"ImageData"
            }
         ]
      }
   ]
},

As you can see the returnTypes are inside of the variants table and atom-autocomplete-lua doesn't resolve them correctly.

When I write local foo = love.graphics.newImageData(), foo doesn't have any method suggestions.

It works fine for functions without variants:

"newText":{
   "type":"function",
   "description":"Creates a new Font.",
   "args":[
      {
         "name":"font"
      },
      {
         "displayName":"[textstring]",
         "name":"textstring"
      }
   ],
   "returnTypes":[
      {
         "type":"ref",
         "name":"Text"
      }
   ],
   "link":"https://love2d.org/wiki/love.graphics.newText"
},

In this case (local foo = love.graphics.newText()), foo is correctly marked as an object of type Text.

As far as I know there are some functions in the LÖVE API whose variants have different returnTypes so I can't simply move them outside of the variant definition.

Is there something I am missing, or is this not supported by your package?

Best wishes, Robert

dapetcu21 commented 7 years ago

Yup. This is not currently supported by this package. But this would be an interesting feature to have. I'll leave this issue open and maybe look into it at some point.

rm-code commented 7 years ago

Thanks 👍

For now I just moved the returnTypes definition outside of the variants as a workaround.