Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntelliJ and Hammerspoon files #132

Open
muescha opened this issue Jul 5, 2022 · 11 comments
Open

IntelliJ and Hammerspoon files #132

muescha opened this issue Jul 5, 2022 · 11 comments

Comments

@muescha
Copy link
Contributor

muescha commented Jul 5, 2022

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?

@Benjamin-Dobell
Copy link
Owner

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.

@muescha
Copy link
Contributor Author

muescha commented Jul 5, 2022

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

@muescha
Copy link
Contributor Author

muescha commented Jul 5, 2022

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

@Benjamin-Dobell
Copy link
Owner

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

@muescha
Copy link
Contributor Author

muescha commented Jul 5, 2022

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
Copy link
Contributor Author

muescha commented Aug 8, 2022

FYI: a little bit helped me to install the EmmyLua Spoon which generates stubs for the core functions

see Hammerspoon/hammerspoon#3247 (comment)

@muescha
Copy link
Contributor Author

muescha commented Nov 20, 2022

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
Copy link
Contributor Author

muescha commented Nov 20, 2022

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
Copy link
Contributor Author

muescha commented Nov 21, 2022

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
Copy link
Contributor Author

muescha commented Nov 23, 2022

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: Hammerspoon/hammerspoon#2530 (comment)

@jonathanstokes
Copy link

I'm working with Hammerspoon too, and am interested in getting Luanalysis working in IntelliJ. I'm having some of the same problems (plus require() of multi-folder paths not working right), so I'll be watching this thread for solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants