CRAG666/code_runner.nvim

cannot use project_path

Closed this issue · 6 comments

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"
  },
}

which background are u using ?

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

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.

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:

if string.find(path, path_full) == 1 then

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?

Looking at 701807c#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)

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.