Olical / aniseed

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

Things left to do with the Aniseed eval+module rewrite #63

Closed Olical closed 2 years ago

Olical commented 3 years ago

I've essentially finished my eval and module rewrite, which hopefully achieves the goals of #56 but we'll see. Things to fix:

; eval (file): ...al/repos/Olical/conjure/fnl/conjure/log.fnl
; ...packer/start/conjure/lua/conjure/aniseed/deps/fennel.lua:534: [string "local sponsors = ___replLocals___['sponsors']..."]:201: main function has more than 200 local variables

Then after some soak time I think we're ready to go! You're more than welcome to use the develop branches now to get the slimmer more efficient Lua output and real interactive aniseed evals. This works now!

(local foo 10)
(+ 10 foo)

;; in two separate evals! No module macros required!
;; although the module macros now output code that should be near enough identical to what you'd write, yay!
Olical commented 3 years ago

Here's an example, aniseed.view source Fennel:

(module aniseed.view)

(def serialise
  (fn [...]
    ((require :aniseed.deps.fennelview) ...)))

And it's original Lua...

local _2afile_2a = "fnl/aniseed/view.fnl"
local _1_
do
  local name_4_auto = "aniseed.view"
  local module_5_auto
  do
    local x_6_auto = _G.package.loaded[name_4_auto]
    if ("table" == type(x_6_auto)) then
      module_5_auto = x_6_auto
    else
      module_5_auto = {}
    end
  end
  module_5_auto["aniseed/module"] = name_4_auto
  module_5_auto["aniseed/locals"] = ((module_5_auto)["aniseed/locals"] or {})
  do end (module_5_auto)["aniseed/local-fns"] = ((module_5_auto)["aniseed/local-fns"] or {})
  do end (_G.package.loaded)[name_4_auto] = module_5_auto
  _1_ = module_5_auto
end
local autoload
local function _3_(...)
  return (require("aniseed.autoload")).autoload(...)
end
autoload = _3_
local function _6_(...)
  local ok_3f_21_auto, val_22_auto = nil, nil
  local function _5_()
    return {}
  end
  ok_3f_21_auto, val_22_auto = pcall(_5_)
  if ok_3f_21_auto then
    _1_["aniseed/local-fns"] = {}
    return val_22_auto
  else
    return print(val_22_auto)
  end
end
local _local_4_ = _6_(...)
local _2amodule_2a = _1_
local _2amodule_name_2a = "aniseed.view"
do local _ = ({nil, _1_, nil, {{}, nil, nil, nil}})[2] end
local serialise
do
  local v_23_auto
  do
    local v_25_auto
    local function _8_(...)
      return require("aniseed.deps.fennelview")(...)
    end
    v_25_auto = _8_
    _1_["serialise"] = v_25_auto
    v_23_auto = v_25_auto
  end
  local t_24_auto = (_1_)["aniseed/locals"]
  t_24_auto["serialise"] = v_23_auto
  serialise = v_23_auto
end
return nil

And here's the new Lua:

local _2afile_2a = "fnl/aniseed/view.fnl"
local _2amodule_name_2a = "aniseed.view"
local _2amodule_2a
do
  package.loaded[_2amodule_name_2a] = {}
  _2amodule_2a = package.loaded[_2amodule_name_2a]
end
local _2amodule_locals_2a
do
  _2amodule_2a["_LOCALS"] = {}
  _2amodule_locals_2a = (_2amodule_2a)._LOCALS
end
local serialise
local function _1_(...)
  return require("aniseed.deps.fennelview")(...)
end
serialise = _1_
_2amodule_2a["serialise"] = serialise

I'm not just realising this should be a defn not a def so that could probably get a couple of lines neater again.

The only "noise" at the top of the output now is creating the initial loaded module for the public functions to be inserted into. It could maybe be reduced further, but it's getting pretty negligible now.

This example is the worst case since Aniseed macros do still insert some boilerplate-ish lines at the top. That becomes a tiny header once you add your own handful of functions, this example is about as bad as it gets, and it's not that bad (imo).

bangedorrunt commented 2 years ago

@Olical I see you completed your tasks today. Congrats 🎉

I'm not sure this is appropriate to ask you here, coz I see Ensure completion works as expected in your task list, but I can't use nvim-cmp atm. On fresh install, it worked a first time, next startup, completion doesn't popup anymore. Please also note that, nvim-cmp works as expected when I use hotpot instead (no offence please, you 2 are amazing).

My packer plugins based on your

(use 
  ;;;; Dependencies
  :wbthomason/packer.nvim {:opt true}
  :Olical/aniseed {:branch :develop}
  :Olical/conjure {:branch :develop
                   :mod :conjure
                   :ft [:clojure :fennel :hy]}
  ;; .... others plugins
  :hrsh7th/nvim-cmp {:branch :custom-menu :module_pattern "cmp.*" :mod :nvim-cmp}
  :hrsh7th/cmp-path {:after :nvim-cmp}
  :hrsh7th/cmp-buffer {:after :nvim-cmp}
  :hrsh7th/cmp-calc {:after :nvim-cmp}
  :hrsh7th/cmp-nvim-lsp {:after :nvim-cmp}
  :hrsh7th/cmp-nvim-lua {:after :nvim-cmp}
  :tzachar/cmp-tabnine {:mod :cmp-tabnine :after :nvim-cmp :run "./install.sh"}
  :PaterJason/cmp-conjure {:after [:nvim-cmp :conjure]}
  :hrsh7th/cmp-emoji {:after :nvim-cmp}
  :abzcoding/cmp_luasnip {:after :nvim-cmp}
  :L3MON4D3/LuaSnip {:module_pattern "luasnip.*"}
  )
Olical commented 2 years ago

Hm, I've never seen anything like that 🤔 completion was completely broken a little while ago from all my rewriting but it's working great for me now. Have you tried it with the very latest develop? Another key thing: Completions still heavily depend on the module macro right now, so if you're not using that you'll run into issues (I should add a way to denote your module name in a comment or something... you can already set b:conjure_context though).

Olical commented 2 years ago

Conjure sources it's completions (completion is a Conjure feature, not Aniseed although I should change that) from a few places:

So if you're loading a Fennel file that isn't compiled by Aniseed or was loaded by something else you may run into problems where :aniseed/locals isn't defined in the module table or you are lacking an identifier to tell Conjure which module you're working with.

Hopefully this is a bit of helpful background!

bangedorrunt commented 2 years ago

@Olical

Have you tried it with the very latest develop?

Yes, both aniseed and conjure are on this branch

Completions still heavily depend on the module macro right now, so if you're not using that you'll run into issues (I should add a way to denote your module name in a comment or something... you can already set b:conjure_context though)

Oh, I didn't know about that. I used module macro before but not now to quickly switch between hotpot and aniseed. If this is a case, I feel bad :(

(let! g/conjure#client#fennel#aniseed#aniseed_module_prefix :aniseed.
      g/conjure#highlight#enabled true 
      g/conjure#extract#tree_sitter#enabled true)