Comments (13)
Well it definitely worked at some point, because the annotations were working just fine, so I guess there was a regression some time? Not sure I could tell you when though :(
from intellij-luanalysis.
I've been using double underscore as a namespace token for my own purposes. Did this work with EmmyLua?
from intellij-luanalysis.
I'd rather reserve .
, :
and []
tokens for returning the type of fields on another type. In the case of penlight, as long as the pl
type contains a List
field, then it'll do what you want. However, you won't be able to do:
---@class pl.List
from intellij-luanalysis.
from intellij-luanalysis.
The downside is just:
reserve
.
,:
and[]
tokens for returning the type of fields on another type
It makes much more sense that .
, :
, []
have the similar semantics in EmmyDoc as they do at runtime i.e. they're used as indexers, which is very useful functionality which is currently missing. It saves you repeating verbose types everywhere, say you've got:
---@class SomeClass
---@field thing number | string | thread | { [1]: "this" | "that", [2]: number }
When you want to refer to the type of SomeClass.thing
you ought to be able to do just that i.e.
---@type SomeClass.thing
local aThing = someClass.thing
as opposed to:
---@type number | string | thread | { [1]: "this" | "that", [2]: number }
local aThing = someClass.thing
This neatly addresses #6
However, if your penlight types are accurate, you won't actually need to change anything. Because penlight does have pl
type, and on it there is a field called List
. So the following will work just fine:
---@type pl.List
local list = pl.List({1, 2, 3, 4})
from intellij-luanalysis.
Right, that's fine maybe for the penlight example, but I do have lots of @Class (and associated @type/param etc in various projects using the lib) declarations that are using it like this:
Let's say I have a Message.lua
file just for annotations (so, dummy methods inside) for a DBus lib (I just took some parts for the example):
...
--------------------------------------------------------------------------------
---@class CompanyName.Bus.Message.Method
local Method = {}
---@param call CompanyName.Bus.Message.Method.Call
---@return CompanyName.Bus.Message.Method.Return
function Method.Return(call) end
--- @return CompanyName.Bus.Message.Method.Call
function Method.Call() end
--------------------------------------------------------------------------------
---@class CompanyName.Bus.Message.Signal
local Signal = {}
---@param member string The signal name
function Signal:setMember(member) end
---@param interface string The interface name
function Signal:setInterface(interface) end
---@return CompanyName.Bus.Object.Iterator
function Signal:begin() end
...
return {
Method = Method,
Signal = Signal,
...
}
For instance CompanyName
doesn't actually represent anything, neither in annotations nor at runtime. It's just considered part of the class "name" (and what's used in the require).
Do I have no other way than changing all my annotations?
Looking at the code, I see it's tag_class
has just an ID
, corresponding to a regex with no possible dots, so I have no idea how it was working this whole time, must have been a bug :(
from intellij-luanalysis.
Looking at the code, I see it's tag_class has just an ID, corresponding to a regex with no possible dots, so I have no idea how it was working this whole time, must have been a bug :(
Yeah, to my knowledge it was never their intention to support periods in identifiers. I assume that it was working by accident. However, you're absolutely more than welcome to fork and make that change. You'll want to update:
https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/blob/master/src/main/java/com/tang/intellij/lua/doc.flex#L60
https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/blob/master/src/main/java/com/tang/intellij/lua/doc.bnf#L37
(Looks like I changed the former file in 6562d4b#diff-905bb6d2efe1bd61d74c550117c8f132L59-R59)
I won't lie, GrammarKit is new to me, so why it was working in the past with periods in just one of those two locations is beyond me.
Anyway, once you've made those two changes, use GrammarKit (https://github.com/JetBrains/Grammar-Kit) to regenerate, quite literally right-click the file in IntelliJ and it's in the context-menu. Then just build again and you're good to go.
As mentioned, I'm unfortunately not interested in making this change myself. I absolutely understand why you want namespaces, having global types and no way of organising them is a recipe for disaster. I'd just rather solve that issue with #3, which needs further brainstorming. Maybe the solution could involve the use of periods to traverse consumer namespaces. However, as for allowing periods in names/identifiers themselves; I don't think I've ever seen a programming language that allows that. Period is usually a token reserved for indexing, which is how I'd like to use the token.
from intellij-luanalysis.
Yeah no worries, I understand your point of view.
It's just too bad that some colleagues and I ended up using this thinking it was a feature and not a bug.
Thanks for the details on how to regenerate it. Not sure I'll do that, but who knows.
from intellij-luanalysis.
Heh, the VSCode EmmyLua plugin also supports dots:
from intellij-luanalysis.
Yeah, impressively, the VSCode plugin actually uses the same code as the Java plugin! It's my intention to get a Luanalysis VSCode build up and running too.
from intellij-luanalysis.
That's great :)
Just as confusing, ID
is the same regex, so no idea why it works...
from intellij-luanalysis.
I stumbled into more examples of annotations in other languages allowing periods in class names. For instance https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/audits/server-response-time.js#L49-L54
Is there really no hope of ever getting this to work like in EmmyLua? :) (even though it was never intended, but still :P)
from intellij-luanalysis.
Instead of trying to retroactively reserve .
, can .
continue to be allowed as part of a class name and instead just reserve a different character for literal indexing (#
comes to mind, which is used in java) ?
from intellij-luanalysis.
Related Issues (20)
- Overrides are checked for static functions HOT 1
- nil checks are not context-aware
- Hello, Is it possible to type a global value with Luanalysis ?
- Top and Bottom Types Distinct from "any" HOT 5
- Unnecessary '0 results are excess arguments' warning HOT 1
- Invalid type mismatch error is given when passing along optional `shape` from one function to another HOT 3
- Type mismatch error when assigning subclasses to an array of superclass HOT 2
- java.lang.NullPointerException HOT 2
- `table<>` definitions with incorrect Type Mismatch errors HOT 1
- Add std defs for LuaJIT
- Allow custom function definitions in table
- Support multi-line text in @field and @param comments
- There seems to be no way to define a non-nil generic return value for a function
- Wrong return type for os.execute
- error HOT 1
- Returned anonymous function is not type-checked HOT 1
- Luanalysis doesn't seem to understand manual nil check
- Executing the Rename action on some files causes severe freeze
- Lua code formatting moves some end-of-line comments to a new line
- Upgrade EmmyLua version. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intellij-luanalysis.