IntelliJ-Luanalysis
IntelliJ-Luanalysis copied to clipboard
Limit type visibility
The mere presence of a type in a project should not expose that type to every file i.e. types should not be global.
Luanalysis should (~~recursively~~ EDIT: Recursively pulling in is a bad idea, don't do that) pull in types when it sees a require
. Additionally, we should provide some mechanism to allow consumers to avoid type name collisions.
e.g.
local Map = require("Map")
local LibraryMap = require("library/Map") ---@prefix Library
---@type Map
local myMap = Map()
---@type LibraryMap
local libraryMap = LibraryMap()
Just a hypothetical solution, other languages allow individual types to be renamed. The above is fairly low friction though.
Additionally, we may want to define types that we never export to consumers i.e. consider adding local
types like:
---@local alias Builder fun(): void
If this was to go ahead, we'd also need something like:
---@require "some-userdata-type"
---@require "some-legacy-global"
To ensure that types that are available globally in a Lua context (not required) can be utilised.
Could see this becoming cumbersome in some environments though, so would be wise to offer some mechanism to import types project wide as well.