Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command in filetype not taken into account anymore ? #126

Open
vimchun opened this issue Dec 20, 2024 · 13 comments
Open

Command in filetype not taken into account anymore ? #126

vimchun opened this issue Dec 20, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@vimchun
Copy link

vimchun commented Dec 20, 2024

Few hours ago, I could run :RunFile toggleterm with no problem (I could run a python script with a custom command).

The latest commit might have a regression : the filetype I set is not taken into account anymore filetype = { python = "clear && python3 -u" }. It seems the command run is the default one : filetype = { python = "python -u '$dir/$fileName'" }.

Note : I had to remove hot_reload = true because I had an error when saving

Error detected while processing BufWritePost Autocommands for "*":
Error executing lua callback: .../nvim/lazy/code_runner.nvim/lua/code_runner/filetype.lua:19: attempt to index field 'utils' (a nil value)
stack traceback:
        .../nvim/lazy/code_runner.nvim/lua/code_runner/filetype.lua:19: in function 'getCommand'
        .../nvim/lazy/code_runner.nvim/lua/code_runner/commands.lua:43: in function <.../nvim/lazy/code_runner.nvim/lua/code_runner/commands.lua:39>

@vimchun vimchun changed the title The command in filetype not taken into account anymore ? Command in filetype not taken into account anymore ? Dec 20, 2024
@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

Pleace, send screenshot

@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

@vimchun update the plugin, pleace

@vimchun
Copy link
Author

vimchun commented Dec 20, 2024

@CRAG666 I just updated it, I still have the same behavior :
(as you can see, I set python3 as for the command, but I get python -u)

image

@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

@vimchun pleace check your config. My config work:
imagen

@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

@CRAG666 my config:
local preview_cmd = "/bin/zathura"
local folder = ""

return {
"CRAG666/code_runner.nvim",
-- name = "code_runner",
dev = true,
keys = {
{
"e",
function()
require("code_runner").run_code()
end,
desc = "[e]xcute code",
},
},
opts = {
mode = "better_term",
better_term = {
number = 1,
},
filetype = {
v = "v run",
tex = function(...)
require("code_runner.hooks.tectonic").build(preview_cmd, { "--keep-logs" })
end,
quarto = {
"cd $dir &&",
"quarto preview $fileName",
"--no-browser",
"--port 4444",
},
markdown = function(...)
local hook = require "code_runner.hooks.preview_pdf"
require("code_runner.hooks.ui").select {
Marp = function()
require("code_runner").run_from_fn "marp --theme-set $MARPT -w -p . &$end"
end,
Latex = function()
hook.run {
command = "pandoc",
args = { "$fileName", "-o", "$tmpFile", "-t pdf" },
preview_cmd = preview_cmd,
}
end,
Beamer = function()
hook.run {
command = "pandoc",
args = { "$fileName", "-o", "$tmpFile", "-t beamer" },
preview_cmd = preview_cmd,
}
end,
Eisvogel = function()
hook.run {
command = "bash",
args = { "./build.sh" },
preview_cmd = preview_cmd,
overwrite_output = ".",
}
end,
}
end,
javascript = "node",
java = "cd $dir && javac $fileName && java $fileNameWithoutExt",
kotlin = "cd $dir && kotlinc-native $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt.kexe",
c = function(...)
c_base = {
"cd $dir &&",
"gcc $fileName -o",
"/tmp/$fileNameWithoutExt",
}
local c_exec = {
"&& /tmp/$fileNameWithoutExt &&",
"rm /tmp/$fileNameWithoutExt",
}
vim.ui.input({ prompt = "Add more args:" }, function(input)
c_base[4] = input
require("code_runner.commands").run_from_fn(vim.list_extend(c_base, c_exec))
end)
end,
-- c = {
-- "cd $dir &&",
-- "gcc $fileName -o",
-- "/tmp/$fileNameWithoutExt &&",
-- "/tmp/$fileNameWithoutExt &&",
-- "rm /tmp/$fileNameWithoutExt",
-- },
cpp = {
"cd $dir &&",
"g++ $fileName",
"-o /tmp/$fileNameWithoutExt &&",
"/tmp/$fileNameWithoutExt",
},
-- python = "python -u '$dir/$fileName'",
python = "python3",
sh = "bash",
typescript = "deno run",
typescriptreact = "yarn dev$end",
rust = "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
dart = "dart",
cs = function(...)
local root_dir = require("null-ls.utils").root_pattern "*.csproj"(vim.loop.cwd())
return "cd " .. root_dir .. " && dotnet run$end"
end,
},
project_path = vim.fn.expand "~/.config/nvim/project_manager.json",
},
}

@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

@vimchun Please delete the plugin and reinstall

@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

pleace check: :lua vim.print(require("code_runner").get_filetype_command())

@vimchun
Copy link
Author

vimchun commented Dec 20, 2024

@CRAG666 I have the same behavior after deleting/reinstalling the plugin, and your command returns python -u /home/mhh/.config/nvim/test_formatting/test_python.py

image

Sorry if the problem is from my environment, I did a lot of modifications in the past few hours... I will check and will come back to you.

@CRAG666 CRAG666 added the invalid This doesn't seem right label Dec 20, 2024
@vimchun
Copy link
Author

vimchun commented Dec 20, 2024

Not sure why you added the invalid label.

I deleted all my plugins except code_runner and toggleterm, uninstall/reinstall both again.

image

I set this :

require("code_runner").setup({
    filetype = { python = "python3" }
})

On my python file, :lua vim.print(require("code_runner").get_filetype_command()) still returns python -u /home/mhh/.config/nvim/test_formatting/test_python.py

image

So I tried with the commit = 'c367431' (the one I was supposed to have when it worked well), and it works (with the message in Spanish #125) :

image

image

@vimchun
Copy link
Author

vimchun commented Dec 20, 2024

(and still works well after loading all my plugins again, ... not sure about the invalid label...)

@CRAG666
Copy link
Owner

CRAG666 commented Dec 20, 2024

More reports for change tag

@AvgBlank
Copy link

AvgBlank commented Dec 24, 2024

Hey, I am experiencing the same issue. My code keeps changing the values of filetype based on how I want to run it, however whatever I run the first time is what's kept. This is my code. This is on MacOS

local function get_command(filetype, quickRun)
  local dir = vim.fn.expand '%:p:h'
  local fileName = vim.fn.expand '%:t'
  -- C/C++
  if filetype == 'cpp' or filetype == 'c' then
    if filetype == 'cpp' then
      RUN = 'bash ~/.config/nvim/lua/codeExec/cmds/cpp.bash -d "'
    else
      RUN = 'bash ~/.config/nvim/lua/codeExec/cmds/c.bash -d "'
    end
    if quickRun then
      RUNWITH = ' '
    else
      RUNWITH = string.lower(vim.fn.input 'Run(r)/Rebuild(b)/DebugCompile(d)/Compile(c)/CompileAndRun(cr): ')
    end
    if RUNWITH == 'r' or RUNWITH == 'cr' then
      local userArgs = vim.fn.input 'If required, enter space separated arguemnts: '
      if userArgs ~= '' then
        return RUN .. dir .. '" -f "' .. fileName .. '" -r "' .. RUNWITH .. '"' .. '2 ' .. userArgs
      else
        return RUN .. dir .. '" -f "' .. fileName .. '" -r "' .. RUNWITH .. '"'
      end
    else
      return RUN .. dir .. '" -f "' .. fileName .. '" -r "' .. RUNWITH .. '"'
    end
    -- SH
  end
end

vim.keymap.set('n', '<leader>r', function()
  local filetype = vim.bo.filetype
  local quickRun = false
  local command = get_command(filetype, quickRun)
  if command then
    require('code_runner').setup {
      filetype = {
        [filetype] = command,
      },
    }
    vim.cmd 'w'
    vim.cmd 'RunCode'
  else
    print('Unsupported filetype ' .. filetype)
  end
end, { noremap = true, silent = false, desc = 'Run Code' })

@CRAG666
Copy link
Owner

CRAG666 commented Dec 24, 2024

@AvgBlank Please send video

@CRAG666 CRAG666 added bug Something isn't working and removed invalid This doesn't seem right labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants