michaelb / sniprun

A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
MIT License
1.43k stars 46 forks source link

Current Update breaks, rust Repl not outputing result. #282

Closed afidegnum closed 5 months ago

afidegnum commented 5 months ago

Describe the bug A clear and concise description of what the bug is.

Initially, I'm facing an issue where sniprun is not able to load imported modules from Cargo.toml After disabling and renabling, I faced the following bug:

E5108: Error executing lua ...afidegnum/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:125: invalid key: cterfg
stack traceback:
    [C]: in function 'nvim_set_hl'
    ...afidegnum/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:125: in function 'highlight'
    ...afidegnum/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:138: in function 'setup_highlights'
    ...afidegnum/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:192: in function 'start'
    ...afidegnum/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:196: in function 'notify'
    ...afidegnum/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:291: in function 'info'
    [string ":lua"]:1: in main chunk

Can you please assist in the cause of the bug? this is my current sniprun configuration:

  {
    "michaelb/sniprun",
    event = "VeryLazy",
    ft = { "python", "lua", "rust" },
    build = "sh install.sh",
    opts = {
      -- selected_interpreters = { "Python3_fifo" },
      -- repl_enable = { "Python3_fifo" },
      live_display = { "VirtualTextOk", "TerminalOk" },
      display = { "VirtualTextOk", "NvimNotifyErr" },
      live_mode_toggle = "enable",
      inline_messages = true,
      -- selected_interpreters = { "Python3_fifo" },
      selected_interpreters = {
        "Python3_original",
        "Lua_nvim",
        "GFM_original",
        "Rust_original",
        "JS_TS_deno",
        "Go_original",
        "C_original",
      },
      repl_enable = { "Python3_fifo" },
      interpreter_options = {
        Rust_original = {
          compiler = "rustc",
        },
      },
      snipruncolors = {
        SniprunVirtualTextOk = { bg = "#66eeff", fg = "#000000", ctermbg = "Cyan", cterfg = "Black" },
        SniprunFloatingWinOk = { fg = "#66eeff", ctermfg = "Cyan" },
        SniprunVirtualTextErr = { bg = "#881515", fg = "#000000", ctermbg = "DarkRed", cterfg = "Black" },
        SniprunFloatingWinErr = { fg = "#881515", ctermfg = "DarkRed" },
      },
    },

    config = function(_, opts)
      require("sniprun").setup(opts)
      -- TODO: patch to use Kitty.lua
      -- local sd = require "sniprun.display"
      -- sd.term_close = function() end
      -- sd.term_open = function() end
      -- sd.write_to_term = function(message, ok) end
    end,
    cmd = "SnipRun",
    keys = {
      { "<leader>Tx", "<Plug>SnipRun", desc = "SnipRun Line" },
      { "<leader>To", "<Plug>SnipRunOperator", desc = "SnipRun Operator" },
      { "<leader>TQ", "<Plug>SnipReset", desc = "SnipRun Reset" },
      { "<leader>TX", "<Plug>SnipReplMemoryClean", desc = "SnipRun Clean" },
      { "<leader>TI", "<Plug>SnipInfo", desc = "SnipRun Info" },
      { "<leader>Tq", "<Plug>SnipClose", desc = "SnipRun Close" },
      {
        "<leader>Ts",
        function()
          require("sniprun").run("v")
        end,
        mode = { "v" },
        desc = "Selection",
      },
    },
  },
michaelb commented 5 months ago

Hi @afidegnum , sorry about that This is due to a bad example in the documentation for snipruncolors config (cterfg =/ ctermfg) that was there since a long time ago.

The new highlighting in v1.3.12 is more configurable, but less permissive, so it breaks only now

You appear to specify the default highlights anyway, so you can either remove the whole snipruncolors key, or correct the invalid cterfg keys to 'ctermfg'

afidegnum commented 5 months ago

Can you also guide on the Rust issue? Imported modules seems not to be recognized. is there a way to include Cargo.toml or how can i include modules to be recognized by sniprun ?

michaelb commented 5 months ago

Unfortunately, this feature doesn't exist for Rust (yet)

Language with that kind of capabilities in sniprun are labeled at SupportLevel 'Import', and only a couple exist for now, as it requires per-language code. I'm not against implementing it, but there's a little bit more than just grepping the use xxx; statements

afidegnum commented 5 months ago

Ok, Thanks,