update#554
Conversation
|
|
||
| export.func = function() | ||
| -- When typing `func` in other files, import suggestions will be shown | ||
| end |
There was a problem hiding this comment.
I don't understand what this does? I thought completion already works without this.
There was a problem hiding this comment.
This is to enable automatic import of subfields. We can't directly provide import suggestions for subfields of all exported tables, as this would severely pollute the auto-completion hints in a huge project and lead to very poor performance. This is especially true in game projects where Lua is widely used, as they often have a large number of configuration tables that could cause auto-import to freeze.
Here is an example:
-- test1.lua
---@export
local export = {}
export.func = function()
endfunc -- When you type 'func', the auto-completion will suggest whether you want to automatically import 'test1.func'.There was a problem hiding this comment.
Another benefit of this approach is that when an export table is marked with ---@export, we can provide diagnostics for undefined fields.
Additionally, we might later provide a diagnostic for disallowed imports, as ---@export can accept a variable. For example, when it's specified as ---@export namespace, it will only allow imports of that file from the same namespace.
There was a problem hiding this comment.
If I understand correctly I think I use @class on an exported table for a similar effect: to get undefined field diagnostics.
Does using @export have any other benefits over @class
Additionally, we might later provide a diagnostic for disallowed imports, as ---@export can accept a variable. For example, when it's specified as ---@export namespace, it will only allow imports of that file from the same namespace.
Sorry I don't understand what this means. By import do you mean require?
There was a problem hiding this comment.
@class does not provide automatic import of subfields, and these two are not conflicting. @class can also include @export.
@export simply tells the LSP how to handle the export of this variable.
There was a problem hiding this comment.
@namespace is a namespace. After using @namespace in a file, all subsequent type definitions will automatically have the prefix declared by @namespace added. It also implies @using.
@using is for referencing a namespace and does not affect type definitions.
As for @export, its current primary purpose is to assist with completion, but in the future, we will implement a simple file visibility control for it.
There was a problem hiding this comment.
---@export is globally visible by default.
---@export namespace is only visible within the current namespace.
---@export global is globally visible.
There was a problem hiding this comment.
Now, a simple module import visibility control has been added for him. When importing variables marked with @export, if it is ---@export namespace, it will check whether the current file's namespace matches it. If not, a warning will be issued.
There was a problem hiding this comment.
Sorry I don't understand what this means. By import do you mean
require?
yes
There was a problem hiding this comment.
If @export is not marked, everything remains the same as before. @export is only meant to enhance the module import experience and slightly restrict the current situation where imports can be used freely.
697f34b to
3ff7636
Compare
|
Feature: Index members allow defining an alias, which will be used as the display during completion. If a comment starts with [xxx], it is considered to add an alias for completion to the index, and whitespace characters are allowed before and after the content inside the ---@class Point
---@field [1] number # [ x ]
---@field [2] number # [y]
---@field [3] number # [z]
---@field [4] number # If there is any non-whitespace character before it, then it is not defining an alias. [error]
local test = {
[1] = 1, -- [nameA]
}
|
This comment was marked as resolved.
This comment was marked as resolved.
I remember it should be that the library I used didn't have hints. |
This comment was marked as resolved.
This comment was marked as resolved.
|
I haven't used |
This comment was marked as resolved.
This comment was marked as resolved.
ae50534 to
fc86b67
Compare
|
@lewis6991 @clason @CppCXY Is there a better character than using |
|
Hmm, not sure I'd ever use that feature myself, but maybe just put the alias in parentheses?
Or use a colon (to match the type annotation)?
You could also treat it like a "field name": |
|
|
This is a key name, not a type. I didn't use a colon (:) as I think it could be confusing. |
|
Then |
I have refactor the emmylua_check, you can try the new version. I have removed the |
This comment was marked as resolved.
This comment was marked as resolved.
I have removed the carets, but some unicode issue need resovle |
I have fixed the unicode issues , and it should basically work now. |
a455778 to
673a766
Compare




No description provided.