IntelliJ-Luanalysis
IntelliJ-Luanalysis copied to clipboard
IntelliJ and Hammerspoon files
Environment
Name | Version |
---|---|
IDEA version | Build #IU-222.3244.4, built on June 29, 2022 |
Luanalysis version | 1.2.2-IDEA203 |
OS | macOS M1 Monterey 12.1 (21C52) |
Preferences
Preferences -> Languages & Frameworks > Luanalysis:
Lua
Name | Setting |
---|---|
Language level | Lua 5.3 |
Type Safety
Name | Setting |
---|---|
Strict nil checks | ❎ |
Unknown type (any) is indexable | ☑️ |
Unknown type (any) is callabale | ☑️ |
What are the steps to reproduce this issue?
i tried to use IntelliJ IDEA to edit the hammerspoon lua files
What happens?
one problem is, that it marks me some of the hs.
as unknown variables and also some more errors because of unknown types
this also show me an error:
local win = hs.window.focusedWindow()
local app = win:application()
local currentFrame = win:frame()
local wins = app:allWindows()
for _, childwin in ipairs(wins) do
childwin:setFrame(currentFrame) -- No such member 'setFrame' found on type 'V'
end
local function Set (list)
local set = {}
for _, l in ipairs(list) do set[l] = true end -- error: No such indexer '[V]' found on type 'table'
return set
end
What were you expecting to happen?
- no errors
- a way to include the hammerspoon source files
Any logs, error output, etc?
-
No such member 'setFrame' found on type 'V'
-
No such indexer '[V]' found on type 'table'
Any other comments?
…
I might be misunderstanding because I've never heard of Hammerspoon before now. However, it sounds like you're asking for Hammerspoon type definitions, in which case you'll want to ask the Hammerspoon project whether this is something they wish to support.
Ok I will ask there. But how theuly can provide the type definitions? What they need to do?
I see the second error (No such indexer '[V]' found on type 'table'
) is not hammerspoon related. I should open a new issue for this
Luanalysis is fairly opinionated. You can certainly turn inspections off but you'll lose out on the type safety benefits. In this case you probably want something like:
---@generic V
---@param list V[]
local function Set (list)
---@type table<V, nil | true>
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
thx
i tried to add the hammerspoon files to the external libraries, but i think thats not possible that way - they don't show up there
adding a path:

but non of this path helps
/Applications/Hammerspoon.app/Contents/Resources/extensions/hs
/Applications/Hammerspoon.app/Contents/Resources/extensions
/Applications/Hammerspoon.app/Contents/Resources
it would be nice to know what files you need so they not marked as error or warning:

FYI: a little bit helped me to install the EmmyLua Spoon which generates stubs for the core functions
see https://github.com/Hammerspoon/hammerspoon/issues/3247#issuecomment-1175615204
the generated sources for hammerspoon you can find at my repo, but they still somehow a little bit wrong. maybe you can suggest how to change the generation process to not see errors?
https://github.com/muescha/dot_hammerspoon/tree/master/Spoons/EmmyLua.spoon/annotations
examples:
- the main class (and other classes) are marked as "Duplicate found in ..."

- "no such member found on ..."

just to explain how the annotation sources are generated:
-
Hammerspoon generates at the build process an docs.json(gist) with the script build_docs.py based on the file comments in in: - /Hammerspoon/setup.lua - /extensions
-
The Spoon EmmyLua generates from
docs.json
the the annotations
Note:
The lua files are included in theHammerspoon.app
and could be added as source path from Luanalysis (but with no luck):
-
/Applications/Hammerspoon.app/Contents/Resources/
-
setup.lua
-
extensions/?.lua
-
docs.json
-
the creator of EmmyLua explained why he not direct use the files in App folder - but maybe there is an other idea how to get it working :)
Why not just add
/Applications/Hammerspoon.app/Contents/Resources/extensions/
as an external library to the lsp config?
Simply adding the hammerspoon extensions
directory as an external library doesn't work for a couple of reasons:
class instances, constructors and function return would not get proper autocompletion
_coresetup
populates thehs[string]
table with all modules. LSP servers have a hard time dealing with this and think all functions/methods/variables anywhere are valid auto completions for every module. With the generated stubs, auto completion works for all HS functionality.
Source: https://github.com/Hammerspoon/hammerspoon/pull/2530#issue-710269254