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

[Bug] Aniseed compile potentially conflicts with impatient.nvim #68

Closed
bangedorrunt opened this issue Sep 25, 2021 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@bangedorrunt
Copy link

Using impatient.nvim give me significant startup improvement, however this also give me a weird and/or unknow bug as shown in the following

Screen_Recording_2021-09-25_at_3.12.28_pm.mov

Actual behavior: a same file was loaded 4 times

Expected behavior: file is loaded normally

The config which caused the issue

;; core/macros.fnl
(fn fn? [obj]
  "Returns true if the object is a function
  This only works at compilation time"
  (and (list? obj) (or (= (->str (first obj)) :hashfn)
                       (= (->str (first obj)) :fn))))

(fn pug [val prefix?]
  (let [inter-compile-uid (_G.os.date "%s")
        name (if prefix?
                  (.. (->str (gensym prefix?)) inter-compile-uid)
                  (.. (->str (gensym :pug)) inter-compile-uid))]
  `(do
     (tset _G ,name ,val)
     ,name)))

(fn vlua [what prefix?]
  `(.. "v:lua." ,(pug what prefix?) "()"))

(fn command! [name expr]
  (let [name (->str name)]
     (if (fn? expr)
       `(vim.cmd (string.format "command! %s call %s" ,name ,(vlua expr)))
       `(vim.cmd (string.format "command! %s %s" ,name ,expr)))))

;; lsp/init.fnl
(import-macros {: nmap! : noremap! : buf-noremap!
                : augroup! : buf-augroup! : autocmd! : buf-autocmd!
                : command! : buf-command! : lua-buf-command!
                : pug : vlua} :core.macros)
(fn reload-lsp []
  (lsp.stop_client (vim.lsp.get_active_clients))
  (vim.cmd :edit))

(fn open-lsp-log []
  (let [path (vim.lsp.get_log_path)]
    (vim.cmd (.. "edit " path))))

(command! :LspLog #(open-lsp-log))
(command! :LspRestart #(reload-lsp))

Remove impatient.nvim plugin, the configuration works as normal

Quote from Aniseed creator:

... that sounds like that's going to introduce a bunch of breaking changes for aniseed since I was in charge of loading your lua before 😦
If that's doing some -> bytecode stuff and loading it automatically weird things might start happening (like what you're seeing) but I'm not sure yet ...

@Olical Olical added the bug Something isn't working label Sep 25, 2021
@bangedorrunt
Copy link
Author

bangedorrunt commented Sep 26, 2021

Hmm, it's weird, now I have the same issue with impatient.nvim plugin already removed. The macro command! mentioned above still apply in this case.
Possibly caused by latest fennel update? afaik, hotpot hasn't updated to latest fennel yet.

@Olical
Copy link
Owner

Olical commented Sep 27, 2021

Hmm there could be issues, Fennel is changing a LOT right now as they move towards v1, so they're making breaking changes in the run up. I think I've insulated you from the environment changes with Aniseed though.

They did change some actual compiler things too, the one that comes to mind is (when ...) used to produce a single branch if that would return absolutely nothing (not even nil) in the else case because Lua lets you do that (in the same way it lets you return many values from one function). Now (when ...) returns a two branch if and the else contains return nil basically, so you always get a value, even if it's nil.

I prefer that and I think it's the right move, but it could be a breaking change if you're expecting absolutely nothing returned from some functions in some cases.

@bangedorrunt
Copy link
Author

Hmm, interesting, this could be the case then.
bakpakin/Fennel@176c90b

@bangedorrunt
Copy link
Author

bangedorrunt commented Oct 3, 2021

Update: I use built-in nvim.ex.command for the command macro (instead of vim.cmd) and the issue is resolved. There actually must be something weird with macros evaluation since your rewritten.

(fn command [name expr]
  (if (fn? expr)
      `(nvim.ex.command_ ,(->str name) :call ,(vlua expr))
      `(nvim.ex.command_ ,(->str name) ,expr)))

(fn buf-command [name expr]
  (if (fn? expr)
      `(nvim.ex.command_ :-buffer ,(->str name) :call ,(vlua expr))
      `(nvim.ex.command_ :-buffer ,(->str name) ,expr)))

@Olical
Copy link
Owner

Olical commented Oct 4, 2021

How's this look on develop for you now, out of interest? I've added some extra options and defaults to force the module macros to produce static ready Lua even if you're compiling in a dynamic env or where the module already exists.

I used to assume if the module is already loaded and you try to compile it you're doing an interactive eval, so it produced dynamic eval targeted Lua. Now I force it to produce static ready Lua in more scenarios.

@Olical
Copy link
Owner

Olical commented Oct 4, 2021

It's working for me and shaved off about 20-50ms! That plus Aniseed's new module system which produces MUCH more efficient and minimal Lua now. (in line with what you'd hand write anyway)

@bangedorrunt
Copy link
Author

@Olical first of all, kudos to your hardworking. When I saw what you said above, I couldn't wait to try it out. I'm happy to say that my issue is fixed, though it might be too soon to speak. Also, it feels snappier when startup. You're genius 🧙‍♂️

@bangedorrunt
Copy link
Author

@Olical
This is the reason why my autocmd called multiple times. Now we can safely put this issue at ease
wbthomason/packer.nvim#636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants