Skip to content

No command available for this filetype #135

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

Open
FrancescoDerme opened this issue Apr 9, 2025 · 4 comments
Open

No command available for this filetype #135

FrancescoDerme opened this issue Apr 9, 2025 · 4 comments

Comments

@FrancescoDerme
Copy link

I'm trying to add cpp to the list of supported languages, my config function is defined as follows. When I run :RunCode on a .cpp file, I'm prompted with "Add more args:", but then whatever I enter the command fails with "No command available for this file type", what am I doing wrong? Please notice that I've also modified a command to 'cd "$dir" &&' instead of "cd "$dir"&&", since $dir might contain spaces.

return{
    "CRAG666/code_runner.nvim",
    config = function()
        require('code_runner').setup({
            filetype = {
                java = {
                    "cd $dir &&",
                    "javac $fileName &&",
                    "java $fileNameWithoutExt"
                },
                python = "python3 -u",
                typescript = "deno run",
                rust = {
                    "cd $dir &&",
                    "rustc $fileName &&",
                    "$dir/$fileNameWithoutExt"
                },
                cpp = function(...)
                    cpp_base = {
                        'cd "$dir" &&',
                        "g++ $fileName -o",
                        "/tmp/$fileNameWithoutExt",
                    }
                    local cpp_exec = {
                        "&& /tmp/$fileNameWithoutExt &&",
                        "rm /tmp/$fileNameWithoutExt",
                    }
                    vim.ui.input({ prompt = "Add more args:" }, function(input)
                        cpp_base[4] = input
                        vim.print(vim.tbl_extend("force", cpp_base, cpp_exec))
                        require("code_runner.commands").run_from_fn(vim.list_extend(cpp_base, cpp_exec))
                    end)
                end,
                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
                        vim.print(vim.tbl_extend("force", c_base, c_exec))
                        require("code_runner.commands").run_from_fn(vim.list_extend(c_base, c_exec))
                    end)
                end,
            },
        })
    end
}
@CRAG666
Copy link
Owner

CRAG666 commented Apr 10, 2025

Image
Working for me

Working with folder with space:

Image

    filetype = {
      v = 'v run',
      tex = function(...)
        require('code_runner.hooks.tectonic').build(
          preview_cmd,
          { '--keep-intermediates', '--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,
      -- cpp = {
      --   'cd $dir &&',
      --   'g++ $fileName',
      --   '-o /tmp/$fileNameWithoutExt &&',
      --   '/tmp/$fileNameWithoutExt',
      -- },
      cpp = function(...)
        cpp_base = {
          [[cd '$dir' &&]],
          'g++ $fileName -o',
          '/tmp/$fileNameWithoutExt',
        }
        local cpp_exec = {
          '&& /tmp/$fileNameWithoutExt &&',
          'rm /tmp/$fileNameWithoutExt',
        }
        vim.ui.input({ prompt = 'Add more args:' }, function(input)
          cpp_base[4] = input
          vim.print(vim.tbl_extend('force', cpp_base, cpp_exec))
          require('code_runner.commands').run_from_fn(
            vim.list_extend(cpp_base, cpp_exec)
          )
        end)
      end,
      python = "python -u '$dir/$fileName'",
      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 Apr 10, 2025

@FrancescoDerme use [[]] instead ''

@FrancescoDerme
Copy link
Author

@CRAG666 Thank you, I’ll try ASAP

@FrancescoDerme
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants