Olical / aniseed

Neovim configuration and plugins in Fennel (Lisp compiled to Lua)
https://discord.gg/wXAMr8F
The Unlicense
610 stars 28 forks source link

On windows, config path contains mixed file separators #47

Closed Kethku closed 3 years ago

Kethku commented 3 years ago

Seems like something broke since I last tried to compile my vim config with aniseed.

When I recompiled my config I got:

runtime error: attempt to call local 'load_fn' (a nil value)
stack traceback:
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3267: in function 'parse_string'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3346: in function '(for generator)'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:2685: in function ?
  [C]: in function 'str'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:101: in function 'file'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:129: in function 'glob'
  ...-data\site\pack\packer\start\aniseed\lua\aniseed\env.lua:92: in function 'init'
  [string "luaeval()"]:1: in main chunk
"C:\Users\keith\AppData\Local\nvim/fnl\module\bindings.fnl"
runtime error: attempt to call local 'load_fn' (a nil value)
stack traceback:
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3267: in function 'parse_string'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3346: in function '(for generator)'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:2685: in function ?
  [C]: in function 'str'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:101: in function 'file'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:129: in function 'glob'
  ...-data\site\pack\packer\start\aniseed\lua\aniseed\env.lua:92: in function 'init'
  [string "luaeval()"]:1: in main chunk
"C:\Users\keith\AppData\Local\nvim/fnl\module\settings.fnl"
runtime error: attempt to call local 'load_fn' (a nil value)
stack traceback:
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3267: in function 'parse_string'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3346: in function '(for generator)'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:2685: in function ?
  [C]: in function 'str'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:101: in function 'file'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:129: in function 'glob'
  ...-data\site\pack\packer\start\aniseed\lua\aniseed\env.lua:92: in function 'init'
  [string "luaeval()"]:1: in main chunk
"C:\Users\keith\AppData\Local\nvim/fnl\util.fnl"
runtime error: attempt to call local 'load_fn' (a nil value)
stack traceback:
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3267: in function 'parse_string'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:3346: in function '(for generator)'
  ...te\pack\packer\start\aniseed\lua\aniseed\deps\fennel.lua:2685: in function ?
  [C]: in function 'str'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:101: in function 'file'
  ...a\site\pack\packer\start\aniseed\lua\aniseed\compile.lua:129: in function 'glob'
  ...-data\site\pack\packer\start\aniseed\lua\aniseed\env.lua:92: in function 'init'
  [string "luaeval()"]:1: in main chunk

So I searched on the fennel repo for similar errors and found: https://github.com/bakpakin/Fennel/issues/357

Which told me that the error I was running into was likely due to a character escape issue. So I looked in the fennel.lua file and added a print line which revealed among other things, this string: "C:\Users\keith\AppData\Local\nvim/fnl\init.fnl"

I believe this comes from the stdpath(config) call. However becomes I'm on windows I'm not able to recompile aniseed (or don't know how) given that they are shell scripts. I think the backslashes need to be converted to forward slashes in env.fnl. Any clues as to how to fork and recompile on windows os I can fix this issue?

Olical commented 3 years ago

Ah that sucks! Well done for spotting it though! I should really try to get my test suites running on Windows (and ARM actually...), it's definitely a platform I neglect as a *nix centric developer. I try to avoid using anything that doesn't seem portable, so I hope issues with Windows are always small easy fixes. Neovim and LibUV are great cross platform foundations 😄

Looks like #48 will do the trick though, I'll merge and compile that for you then we can see if it helps.

Olical commented 3 years ago

So, let me know if the issue is fixed for you on develop 😄 hopefully that does the trick!

Olical commented 3 years ago

I'll optimistically close in the hopes that the gsub fixed the issue, if not, please do reopen!

nganhkhoa commented 3 years ago

image

Is this the same error? On linux and macOS, the config is working. While on Windows, I get this ambiguous error. I have changed endline from \r\n to \n but still no difference. Strangely, the error indicator is showing at the "." dot character.

nganhkhoa commented 3 years ago

Explanation:

filename is propagated into fennel parsing string literal. Thus, the backslash is parsed as escaping the next character, which is illegal (\i \l \p \s).

Resolve:

An easy fix is to replace the backslash with forward slash. Below, I demonstrate how and where it should be fixed. If there is a better place to employ the fix, you can tell me to test it out.

Below is the code I fixed directly on lua:

        -- compile.lua
        local _3_ = a.get(opts, "filename")
        if _3_ then
          filename = string.gsub(_3_, (nvim.fn.getcwd() .. "/"), "")
        else
          filename = _3_
        end
        filename = string.gsub(filename, "\\", "/")

Fennel code reference: https://github.com/Olical/aniseed/blob/4ca3d418eebc0da452b7defc18970c83f7de5070/fnl/aniseed/compile.fnl#L9-L12

Olical commented 3 years ago

Is this working for you now on develop and the soon to be released version? @nganhkhoa

nganhkhoa commented 3 years ago

I confirm the compilation success on the develop branch.