GithubHelp home page GithubHelp logo

Comments (3)

rktjmp avatar rktjmp commented on June 12, 2024

I'll be honest, it's been a while since I've worked on the code and don't have the time to check properly right now (half of this post is really notes to future me), but my test:

  describe "#69", ->
    it "errors", ->
      base = parse -> {
        A { fg: "#00FF00", gui: "italic" }
      }
      spec = parse -> {
        A { base.A, gui: nil }
      }

Gives the error:

user bugs #69 errors
./lua/lush/parser.lua:1: {
  code = "circular_self_link",
  msg = "Attempt to link self",
  on = "A"
}

Off the top of my head,

  • gui = nil is probably ending up as a no-op/getting stripped.
    • (perhaps this is an oversight or perhaps the preferred way is actually redefining the rule with all keys, will have to think about that.)
  • so A { base.A, gui = nil } == A { base.A } which is illegal (circular self link).

So the parser can't rectify the spec and somewhere it's failing to check for errors or perhaps just cant surface the error context properly.


Anyway, if you gui = "NONE", you force the key to be set to a value and the error doesn't happen.

For your user, you might have to wrap the mini-spec in a Colorscheme autocommand (check exact name) so the mini-spec is applied after the normal colorscheme since it's not executed in an obvious order. That's a neat trick I hadn't thought of doing, just passing a small patch of highlights to apply, good use of the internal tool chain!

extends/merge is the prescribed way to do it for bigger changesets but the small patch is a nice way too. Extends/merge sets up a proper parent scope, which is probably why the error doesn't show up in that case, but I would have to look into it.

That should keep you moving, but it is a bug, at least in not showing a useful error if nothing else.

from lush.nvim.

rktjmp avatar rktjmp commented on June 12, 2024

Getting my brain back in Lua mode, I am thinking:

  • key = nil is the same as not having the key in a lua table (IIRC)
  • so when I request/pairs() the keys given for a highlight group, lua doesn't return gui because it's nil, as good as not being in the table
  • so the highlight only has a group name and changes from an inherit rule into a link rule.

I bet if you set gui = nil, fg = "#11111" it probably works fine because a key exists and it stays as an inherit rule instead of becoming a link.

Nils are ok to reach the compiler, they get coerced into "NONE"

-- sanitise value if empty or blank
local function value_or_NONE(value)
if value == nil or value == '' then
return 'NONE'
end

Not 100% if I can actually check for this, since checking if a key is nil would probably break the whole link idea cause everything would look like an inherit without checking all the way up chains for differences.

Probably the fix will just be surfacing the error and documenting that key = "NONE" is the correct way to unset a value.

from lush.nvim.

mcchrish avatar mcchrish commented on June 12, 2024

Anyway, if you gui = "NONE", you force the key to be set to a value and the error doesn't happen.

This works! I should have thought of this in the first place. Not sure why I went with nil.

I'll probably make this mcchrish/zenbones.nvim#14 (comment) the recommended way for simple overrides. It's much more flexible but still simple to write. I first considered showing the extend/merge way but that seems to large of an apply/compile for one override.

from lush.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.