Code Monkey home page Code Monkey logo

Comments (3)

Benjamin-Dobell avatar Benjamin-Dobell commented on September 25, 2024

Rather than doing this auto-magically, I'd prefer a more explicit approach e.g.

---@class ServiceDefinition
---@overload ServiceDefinition:new

That way the one project can mix and match instantiation schemes, and if you're publishing a library, people can just use your library as is without needing to change Luanalysis preferences.

This actually touches a little bit on #5... Will comment more there.

from intellij-luanalysis.

adriweb avatar adriweb commented on September 25, 2024

from intellij-luanalysis.

adriweb avatar adriweb commented on September 25, 2024

(sorry for the double comment, I cleaned that up, the first one got posted too early...)

Any news ? :)

I'm asking because I'm still facing difficulties getting everything to work correctly for some more "complex" annotations:

image
(ignore that dummy Class function, that's just for the sake of this screenshot)

As you can see here, for some reason the tmp variable isn't typed as a MyClass, even though everything else seems OK:

  • the private fields are correctly typed if I ctrl-hover them in any class method. (thanks to the first part of the MyClass @type annotation)
  • the constructor is correctly recognized (thanks to the second part of the MyClass @type annotation)

BTW, I did try the following, but that didn't solve it completely (to be clear: it made the return value typed correctly, but the constructor parameters became unknown because MyClass doesn't have the alternate function type that provided the info anymore)

---@class MyClass
---@overload fun(id:number, name:string, options:table<string,any>|nil):MyClass

Is this a bug somehow, or am I missing something? Or is it something that's known to be non-working right now and that would be handled later (with something like what you mentioned in the earlier comments)

Thanks!

Edit :
I found a way to make it work, but unfortunately the actual Lua code changes, and that's a no-no:
I guess the following is the only way to "dual-type" a class correctly.

---@class MyClass
---@overload fun(id:number, name:string, options:table<string,any>|nil):MyClass
---@field private id number
---@field private name string
---@field private options table<string,any>
local MyClass

---@type MyClass | fun(id:number, name:string, options:table<string,any>|nil):MyClass
local MyClass = Class()

[...]

from intellij-luanalysis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.