EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.73k stars 290 forks source link

AwesomeWM - Go to declaration (ctrl+B) - enhancement #446

Closed raven2cz closed 1 year ago

raven2cz commented 2 years ago

I'm using very often emmy lua in idea for AwesomeWM implementation.

It's working good. I'm big fan of this approach. There is one topic which can improve my work and speed up my process very rapidly.

The feature Go to declaration (ctrl+B) works very good if the expression corresponds with library name. For example, naughty.notify() is correctly navigated to naughty.lua it is correct.

But for example: awful.keyboard.append_client_keybindings(), The aweful is the library defined by directory awful/init.lua and the keyboard.lua is declared in the init.lua and the keyboard.lua is placed in the directory awful. But this is not matched and jump to declaration doesn't work, it is not possible to jump to keyboard.lua too. No match found.

Is it possible to extend Go to declaration for standard usage with directory and included lib files, like: aweful/init.lua and aweful/keyboard.lua => awful.keyboard.append_client_keybindings()

For more info, you can install awesome package, and look to libraries in /usr/share/awesome/lib package.

I understand that always there will be dynamic linkages, lua is very dynamic. But this behavior with directory and inside libraries with same name is fixed concept which I see many times in different projects too.

CppCXY commented 2 years ago

use the emmylua annotation will help the go to declaration

raven2cz commented 2 years ago

use the emmylua annotation will help the go to declaration

I tried it. And it doesn't work.

I have for example directory fishlive/layout and there is file init.lua where is the declaration of the fishlive.layout module. So, I insert the annotation to this init.lua document for the layout declaration:

---@module 'fishlive.layout'
local layout       = { _NAME = "fishlive.layout" }

and this layout module is used in the rc.lua file, like: fishlive.layout.mirrored_tile.left

I tried to navigate to the @module 'fishlive.layout' but it doesn't see it.

CppCXY commented 2 years ago

This is not emmylua annotation syntax, here should be

-- fishlive/layout.lua

---@class fishlive.layout
local layout = { _NAME = "fishlive.layout" }

return layout

and init,lua

-- init.lua

---@class fishlive
local fishlive = {}
---@type fishlive.layout
fishlive.layout = require "fishlive.layout"
raven2cz commented 2 years ago

almost winning. The linkage between init.lua and layout.lua with type and class works correctly.

The problem is still with rc.lua. I signed with type the fishlive module in the required path. So, in rc.lua is new this:

---@type fishlive
local fishlive = require("fishlive")

So if I press ctrl+b on the type line, it is correctly jump to the appropriate directory to the init.lua. But I'm on the this line in the rc.lua

fishlive.layout.mirrored_tile.left

and I expect that the press ctrl+b on the layout it jump to fishlive.layout, but nothing happen. Ctrl+b on the fishlive jump to the required line on the top of rc.lua. Is it possible to wire the fishlive.layout.mirrored_tile.left to map fishlive.layout declared class?

CppCXY commented 2 years ago

Ctrl b will jump to his definition

fishlive.layout = ...

define in init.lua, it will jump to init.lua if it define in layout.lua it will jump to layout.lua Or you accept the jump twice,first jump to init.lua and jump to the layout .lua by type fishlive.layout Jump work correctly in my machine.

CppCXY commented 2 years ago

It is too late now, If you have any questions, I'll see it tomorrow

raven2cz commented 2 years ago

So, thanks for help. Last question. Can you give me full example how to correctly navigate my basic line which I used very often?

fishlive.layout.mirrored_tile.left

First It means to navigate to fishlive.layout submodule, and second navigate to the defined table in the layout itself mirrored_tile. What is your best practice to annotate or use other techniques with emmylua? Or some tricks which quick navigation.

CppCXY commented 2 years ago

see navigate.zip and some practice resty api

raven2cz commented 2 years ago

Thanks for your examples. It very helps. I see the problem now.

The problem is organization of modules which are used. I attached image.

emmy-lua-module-inits

Our Lua Modules are organized by directories (packages), not by files. Each module is defined by init.lua file which describes the parent module (for example fishlive) or submodule (e.g. layout).

Submodule is declared by standard mechanism without .init suffix. It means layout = require "fishlive.layout" not "fishlive.layout.init". mirrored_tile.lua file is automatically attached to the module where is placed.

I tried to test it, and it seems that the linkage works if the .init suffixes are used, but it doesn't work for approach package module structure without .init. Is there some possibility to involve general/common mapping with init.lua module declarations?

neopaf commented 1 year ago

I guess, this issue duplicates #415 now. Maybe should focus on one of those...

CppCXY commented 1 year ago

I guess, this issue duplicates #415 now. Maybe should focus on one of those...

The author has been busy, so the problem is not solved yet. I also have a lot of projects mentioned.

raven2cz commented 1 year ago

I started to use vscode with lua integration. It works perfectly for awesomewm.