IntelliJ-Luanalysis icon indicating copy to clipboard operation
IntelliJ-Luanalysis copied to clipboard

IntelliJ and Hammerspoon files

Open muescha opened this issue 2 years ago • 11 comments

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: Bildschirmfoto 2022-07-05 um 06 40 16

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?

muescha avatar Jul 05 '22 04:07 muescha

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.

Benjamin-Dobell avatar Jul 05 '22 05:07 Benjamin-Dobell

Ok I will ask there. But how theuly can provide the type definitions? What they need to do?

muescha avatar Jul 05 '22 05:07 muescha

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

muescha avatar Jul 05 '22 05:07 muescha

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

Benjamin-Dobell avatar Jul 05 '22 05:07 Benjamin-Dobell

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 Bildschirmfoto 2022-07-05 um 23 41 02

adding a path:

Bildschirmfoto 2022-07-05 um 23 42 18

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:

Bildschirmfoto 2022-07-05 um 23 46 01

muescha avatar Jul 05 '22 21:07 muescha

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

muescha avatar Aug 08 '22 11:08 muescha

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

muescha avatar Nov 20 '22 20:11 muescha

examples:

  • the main class (and other classes) are marked as "Duplicate found in ..."
Bildschirmfoto 2022-11-20 um 21 52 12
  • "no such member found on ..." Bildschirmfoto 2022-11-20 um 21 58 36
Bildschirmfoto 2022-11-20 um 21 58 54

muescha avatar Nov 20 '22 21:11 muescha

just to explain how the annotation sources are generated:

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

muescha avatar Nov 21 '22 10:11 muescha

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 the hs[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

muescha avatar Nov 23 '22 16:11 muescha