CRAG666 / code_runner.nvim

Neovim plugin.The best code runner you could have, it is like the one in vscode but with super powers, it manages projects like in intellij but without being slow
MIT License
533 stars 38 forks source link

Expected lua string #15

Closed KeqiZeng closed 2 years ago

KeqiZeng commented 2 years ago

HI! At first, thanks a lot for the nice plugin.

When I used this plugin just now, I got an error:

E5108: Error executing lua ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:89: Expected lua string
stack traceback:
        [C]: in function 'cmd'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:89: in function 'run_filetype'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:138: in function 'run_code'
        [string ":lua"]:1: in main chunk

here is my minimal init.lua about code_runner:

use { 'CRAG666/code_runner.nvim', requires = 'nvim-lua/plenary.nvim' }   in packer

require('code_runner').setup {
  term = {
    position = "belowright",
    size = 8
  },
  filetype_path = "$HOME/.config/nvim/code_runner.json",
  project_path = "$HOME/.config/nvim/projects.json"
}

and here is my coder_runner.json:

{
      "python": "python -u"
}

It seems also like this for other languages.

CRAG666 commented 2 years ago

pleace check if error exist

karimlevallois commented 2 years ago

I'm getting the same issue and still happens after the latest fix. The only way to fix the issue is to add vim.g.fileCommands = {python = 'python3'} to my init.lua.

KeqiZeng commented 2 years ago

pleace check if error exist

Now I get this error:

E5108: Error executing lua ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:43: attempt to index field 'fileC
ommands' (a nil value)
stack traceback:
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:43: in function 'get_command'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:76: in function 'get_filetype_command'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:81: in function 'run_filetype'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:138: in function 'run_code'
        [string ":lua"]:1: in main chunk

I also try to addvim.g.fileCommands = {python = 'python3'}(as @KarimLeVallois said) to my init.lua, but there is nothing different on my laptop.

KeqiZeng commented 2 years ago

I find this issue is same as #14. I try to configure in pure lua as you recommended, and it works fine for a single file. So I think this plugin maybe can not correctly recognize my json flie? What should I do if i want to configure with json? Thank you so much for your effort!!

CRAG666 commented 2 years ago

This is my personal configuration, yes use json file

require('code_runner').setup({
  term = {
    size = 15,
  },
  filetype_path = vim.fn.expand('~/.config/nvim/code_runner.json'),
  project_path = vim.fn.expand('~/.config/nvim/project_manager.json'),
}
{
    "javascript": "node",
    "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
    "kotlin": "cd $dir && kotlinc-native $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt.kexe",
    "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir/$fileNameWithoutExt",
    "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir/$fileNameWithoutExt",
    "python": "python -u",
    "shellscript": "bash",
    "csharp": "cd $dir && mcs $fileName && mono $fileNameWithoutExt.exe",
    "typescript": "deno run",
    "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
    "dart": "dart"
}
CRAG666 commented 2 years ago

This is a setup using pure lua:

require('code_runner').setup {
  term = {
    size = 15,
  },
  filetype = {
    java = "cd $dir && javac $fileName && java $fileNameWithoutExt",
    python = "python -u",
    typescript = "deno run",
    rust = "cd $dir && rustc $fileName && $dir/$fileNameWithoutExt"
  },
}
CRAG666 commented 2 years ago

The error existed before the last commit, try to update the plugin and check if the problem persists, because of all the tests that I have done, the plugin works without any problem. Remember that if it is json, you should not include trailing commas, that is, a comma after the last element. In case you use lua also try to write a correct table format because all these things the plugin cannot or should not handle. Finally, if this is resolved, I would appreciate closing the issue or, if applicable, doing a pr.

CRAG666 commented 2 years ago

HI! At first, thanks a lot for the nice plugin.

When I used this plugin just now, I got an error:

E5108: Error executing lua ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:89: Expected lua string
stack traceback:
        [C]: in function 'cmd'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:89: in function 'run_filetype'
        ...cker/start/code_runner.nvim/lua/code_runner/commands.lua:138: in function 'run_code'
        [string ":lua"]:1: in main chunk

here is my minimal init.lua about code_runner:

use { 'CRAG666/code_runner.nvim', requires = 'nvim-lua/plenary.nvim' }   in packer

require('code_runner').setup {
  term = {
    position = "belowright",
    size = 8
  },
  filetype_path = "$HOME/.config/nvim/code_runner.json",
  project_path = "$HOME/.config/nvim/projects.json"
}

and here is my coder_runner.json:

{
      "python": "python -u"
}

It seems also like this for other languages.

try to expand the url, above leave how you do it in vim, remember that code runner works with absolute not relative paths, in fact I will be more clear, I will add more explanation of this in the README

CRAG666 commented 2 years ago

Thank you for letting me know that the projects weren't working, data that failed because I called them projects and not project. It was so simple to correct but here I leave the complete example configuration:

require('code_runner').setup {
  term = {
    size = 15,
  },
  filetype = {
    java = "cd $dir && javac $fileName && java $fileNameWithoutExt",
    python = "python -u",
    typescript = "deno run",
    rust = "cd $dir && rustc $fileName && $dir/$fileNameWithoutExt"
  },
  project = {
    ["~/prueba"] = {
      name = "App1",
      description = "Tmx frontend api",
      file_name = "prueba.py"
    },
  }
}
KeqiZeng commented 2 years ago

Sorry for being late in replying. Now it works totally fine. I think my issue comes from here:

At first I just copy the config example to my init.lua, but it can't work so good. image

Just now I change

filetype_path = "$HOME/.config/nvim/code_runner.json",
project_path = "$HOME/.config/nvim/projects.json"

to

filetype_path = vim.fn.expand('~/.config/nvim/code_runner.json'),
project_path = vim.fn.expand('~/.config/nvim/project_manager.json'),

Then it can works fine. Whatever, thank you so much again for your explanation.