code_runner.nvim icon indicating copy to clipboard operation
code_runner.nvim copied to clipboard

cannot use project_path

Open aharoldk opened this issue 2 years ago • 2 comments
trafficstars

hi, i tried to run spring boot using code_runner project_path but got error when using project_path. could you help me to use the project_path?

image image

this is my coderunner-project.json

{
  "~/Downloads/demo": {
    "name": "Demo Java",
    "description": "Java",
    "command": "./gradlew bootRun"
  },
  "~/devex/ms-configuration": {
    "name": "Kotlin",
    "description": "Kotlin",
    "command": "./mvnw build && ./mvnw spring-boot:run"
  },
  "~/cpp/example": {
    "name": "ExapleCpp",
    "description": "Project with make file",
    "command": "make buid && cd buid/ && ./compiled_file"
  },
}

aharoldk avatar Oct 09 '23 05:10 aharoldk

which background are u using ?

Azizaman avatar Nov 15 '23 11:11 Azizaman

This is what you use to search for projects, make sure you have your projects correctly

local function getProjectRootPath()
  local projects = o.get().project
  local path = vim.fn.expand("%:p")
  for project_path, _ in pairs(projects) do
    path_full = vim.fs.normalize(project_path)
    if string.find(path, path_full) == 1 then
      current_proyect = projects[project_path]
      current_proyect["path"] = project_path
      return current_proyect
    end
  end
end

CRAG666 avatar Nov 18 '23 15:11 CRAG666

could we make it like vscode? we put the configuration file inside the project (.vscode) so every time we run the project it will refer to that file first.

aharoldk avatar Feb 13 '24 06:02 aharoldk

Hi, @CRAG666, I think there is a problem with projects that contain - (potentially other special characters as well). I think this might be this offending line: https://github.com/CRAG666/code_runner.nvim/blob/0c701cae3265c79b4fdfd4b35a4f3d7c5986d46c/lua/code_runner/commands.lua#L44

Tested in command mode with prefix of lua:

print(string.find("path-WithMinus", "path-With")) -- nil
print(string.find("pathWithout", "path")) -- 1 4

This also makes me wonder if this would make it impossible to define a project /path/to/foo without also matching /path/to/foobar as string.find("/path/to/foobar/shell", "/path/to/foo") would return 1 12 thus matching. Appending a / to the project pattern does not work as it will be stripped by vim.fs.normalize. Potential fix for the foobar match could be string.find(path, path_full .. "/") but the - problem remains.

@aharoldk, could you confirm that code_runner works as expected with the other two projects (demo and example) you defined?

Syphdias avatar Feb 13 '24 23:02 Syphdias

Looking at https://github.com/CRAG666/code_runner.nvim/commit/701807c4f181cd00d4fad0280bbc821324cbe3c1#diff-247ceb4910166218fe8b1e16bd14726ababae11faaa9f247bb4be8122822fd46L45, it looks like the pattern matching is the reason that - break the match.

This would work:

print(string.find("path-WithMinus", "path-With", 1, true)) -- 1 9

It makes no sense to enable pattern matching here if the "pattern" is the normalized path of the file. I see two options:

  1. Use string.find(path, path_full, 1, true) to only match without pattern.
  2. Use string.find(path_full, path) to ~~enable~~ require patterns. This might break configs I suppose but would make it possible to use regex (I think). But at this point someone might even prefer to write their own function for project (not sure if that is possible like it is with filetype)

Syphdias avatar Feb 13 '24 23:02 Syphdias

I just realised that this is wrong and I thought path_full is the file and path is the pattern/project. The names confused me.

Syphdias avatar Mar 04 '24 20:03 Syphdias