{"action":"created","issue":{"url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua/issues/197","repository_url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua","labels_url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua/issues/197/labels{/name}","comments_url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua/issues/197/comments","events_url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua/issues/197/events","html_url":"https://github.com/EmmyLua/IntelliJ-EmmyLua/issues/197","id":371154493,"node_id":"MDU6SXNzdWUzNzExNTQ0OTM=","number":197,"title":"Distinction between a class and instance (of a class) - static vs instance methods/variables","user":{"login":"Benjamin-Dobell","id":482276,"node_id":"MDQ6VXNlcjQ4MjI3Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/482276?v=4","gravatar_id":"","url":"https://api.github.com/users/Benjamin-Dobell","html_url":"https://github.com/Benjamin-Dobell","followers_url":"https://api.github.com/users/Benjamin-Dobell/followers","following_url":"https://api.github.com/users/Benjamin-Dobell/following{/other_user}","gists_url":"https://api.github.com/users/Benjamin-Dobell/gists{/gist_id}","starred_url":"https://api.github.com/users/Benjamin-Dobell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Benjamin-Dobell/subscriptions","organizations_url":"https://api.github.com/users/Benjamin-Dobell/orgs","repos_url":"https://api.github.com/users/Benjamin-Dobell/repos","events_url":"https://api.github.com/users/Benjamin-Dobell/events{/privacy}","received_events_url":"https://api.github.com/users/Benjamin-Dobell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-17T16:06:44Z","updated_at":"2018-10-17T16:12:32Z","closed_at":null,"author_association":"NONE","body":"Environment（环境）\r\n--------------\r\n   name   |   version  \r\n----------|----------\r\n IDEA version         | IntelliJ IDEA 2018.2.4 (Ultimate Edition) - Build #IU-182.4505.22, built on September 18, 2018\r\n EmmyLua version | 1.2.5-IDEA182\r\n OS                        | macOS 10.13.6\r\n\r\nWhat are the steps to reproduce this issue?（重现步骤？）\r\n------------------------------------------------\r\n1. Create a class, add a static method e.g. using the sample code found in the README animation:\r\n\r\n```lua\r\n---@class MyClass\r\n---@field public child MyClass\r\nlocal cls = {}\r\n\r\nfunction cls:init(name, child)\r\n    self.child = child\r\n    self.name = name\r\nend\r\n\r\n---@return MyClass\r\nfunction cls.new()\r\n    --todo: return new instance\r\nend\r\n```\r\n2. Instantiate an instance of the class (or `@type MyClass` a variable):\r\n\r\n```lua\r\nlocal instance = cls.new()\r\n```\r\n\r\n3. Access auto-complete on the instance e.g.\r\n\r\n```lua\r\ninstance.-- Leave your text cursor here\r\n```\r\n\r\nWhat happens?（出现什么问题？）\r\n-------------\r\nAuto-complete suggests static methods which do not exist on the instance, in this case `new`:\r\n\r\n![screen shot 2018-10-18 at 2 43 04 am](https://user-images.githubusercontent.com/482276/47099296-b76fbb80-d280-11e8-98f8-ae9f031935d1.png)\r\n\r\nThe inverse is also true, if you have a reference to `cls`, instance methods are suggested.\r\n\r\nWhat were you expecting to happen?（期望？）\r\n-----------------------------------------\r\nOnly see instance variables/functions on references to an instance of a class, only see static variables/instances on references to a class.\r\n…\r\n\r\nAny logs, error output, etc?（有没有什么log, error输出？）\r\n------------------------------\r\nAs shown in the screenshot above.\r\n\r\n\r\nAny other comments?（其它说明）\r\n------------------------\r\nI believe there's also no way to type annotate a _reference to a class_.\r\n\r\ne.g. Dynamic instantiation example:\r\n\r\n```lua\r\n---@class Transport @parent class\r\n---@public field name string\r\nlocal transport = {}\r\n\r\n---@return Transport\r\nfunction transport.new()\r\n    --todo: return new instance\r\nend\r\n\r\nfunction transport:move()end\r\n\r\n---@class Car : Transport @Car extends Transport\r\nlocal car = {}\r\nfunction car:move()end\r\n\r\n---@return Car\r\nfunction car.new()\r\n    --todo: return new instance\r\nend\r\n\r\n---@class Ship : Transport @Ship extends Transport\r\nlocal ship = {}\r\n\r\n---@return Ship\r\nfunction ship.new()\r\n    --todo: return new instance\r\nend\r\n```\r\n\r\nNow let's create a function that takes a reference to a Transport class (_not_ an instance):\r\n\r\n```lua\r\n---@type transportCls ?????? -- <=== WHAT GOES HERE?\r\n---@return Transport\r\nfunction buildTransport(transportCls)\r\n    return transportCls.new()\r\nend\r\n```\r\n\r\nIf we were to annotate `transportCls` as `---@type transportCls Transport` that would be incorrect, as that's how you annotate a method that takes an _instance_ of a class. Instances of the class do not have the required `new` function.\r\n"},"comment":{"url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua/issues/comments/430691619","html_url":"https://github.com/EmmyLua/IntelliJ-EmmyLua/issues/197#issuecomment-430691619","issue_url":"https://api.github.com/repos/EmmyLua/IntelliJ-EmmyLua/issues/197","id":430691619,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDY5MTYxOQ==","user":{"login":"ice1000","id":16398479,"node_id":"MDQ6VXNlcjE2Mzk4NDc5","avatar_url":"https://avatars3.githubusercontent.com/u/16398479?v=4","gravatar_id":"","url":"https://api.github.com/users/ice1000","html_url":"https://github.com/ice1000","followers_url":"https://api.github.com/users/ice1000/followers","following_url":"https://api.github.com/users/ice1000/following{/other_user}","gists_url":"https://api.github.com/users/ice1000/gists{/gist_id}","starred_url":"https://api.github.com/users/ice1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ice1000/subscriptions","organizations_url":"https://api.github.com/users/ice1000/orgs","repos_url":"https://api.github.com/users/ice1000/repos","events_url":"https://api.github.com/users/ice1000/events{/privacy}","received_events_url":"https://api.github.com/users/ice1000/received_events","type":"User","site_admin":false},"created_at":"2018-10-17T16:12:32Z","updated_at":"2018-10-17T16:12:32Z","author_association":"CONTRIBUTOR","body":"IMO it's correct. You can call static functions on an object with `.` like `a.staticFunc()`, or instance functions on an object with self passed manually like `a.instanceFunc(a)`, or use `:` like `a:instanceFunc()`.\r\n\r\nWhy do you think we shouldn't provide completion for valid codes?"}}
{"actor":{"display_login":"ice1000"}}