Olical / nfnl

Enhance your Neovim with Fennel
The Unlicense
236 stars 8 forks source link

fix: need to provide a table as input #16

Closed Kamholtz closed 1 year ago

Kamholtz commented 1 year ago

nfnl.config.default now takes a table as input so the docs should show this.

Olical commented 1 year ago

Ah good catch! I think I'll make it so you can just skip the table entirely and also have it set some sensible defaults. This will invalidate this PR but still be related to it.

It's actually a little tricky because I need the user to pass in the path to the current config files containing directory. It's so that certain paths get set up correctly for them using absolute paths to avoid any sort of confusion when editing a file from the wrong directory tree.

So if your nvim is in /foo/bar and you're editing /foo/baz/quuz.fnl and you have a .nfnl.fnl file in /foo/bar AND in /foo/baz then we need to make sure it's the /foo/baz one that's used and all paths are relative to that because THAT's the project you're editing.

It's all about the file you're editing, not the directory Neovim is currently in, which means when you build the config object you need to pass the project directory into it like (config.default {:root-dir "/foo/baz"}) so it can set up the paths correctly.

I need to make that easy for the user to do correctly. Just thinking about that now.

Kamholtz commented 1 year ago

Makes sense!

Olical commented 1 year ago

Alright fixed in a roundabout way! You can now call (config.default) again and it finds the right dir and Just Does The Right Thing on your behalf. So it'll return default config with absolute paths based on the closest parent of a .nfnl.fnl file, i.e. your project root. Thus eliminating all sorts of weird relative path logic. Success! I think!

Olical commented 1 year ago

Running it for myself in nfnl's own repo with no args now gives me:

; eval (current-form): (config.default)
{:compiler-options {}
 :fennel-macro-path "/home/olical/repos/Olical/nfnl/?.fnl;/home/olical/repos/Olical/nfnl/?/init-macros.fnl;/home/olical/repos/Olical/nfnl/?/init.fnl;/home/olical/repos/Olical/nfnl/fnl/?.fnl;/home/olical/repos/Olical/nfnl/fnl/?/init-macros.fnl;/home/olical/repos/Olical/nfnl/fnl/?/init.fnl"
 :fennel-path "/home/olical/repos/Olical/nfnl/?.fnl;/home/olical/repos/Olical/nfnl/?/init.fnl;/home/olical/repos/Olical/nfnl/fnl/?.fnl;/home/olical/repos/Olical/nfnl/fnl/?/init.fnl"
 :fnl-path->lua-path #<function: 0x7f0ef95b3b58>
 :source-file-patterns ["*.fnl" "**/*.fnl"]}

So I'm happy with that, closing this PR but thank for you spotting it and providing an immediate fix to the error. Hope this all makes sense and helps!