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

No parent project could be resolved #57

Open
blasco opened this issue Nov 17, 2022 · 9 comments
Open

No parent project could be resolved #57

blasco opened this issue Nov 17, 2022 · 9 comments

Comments

@blasco
Copy link

blasco commented Nov 17, 2022

I'm trying to get csharp-ls to work with nvim coc within a Unity project. I'm getting the following error:

[coc.nvim] csharp-ls: No parent project could be resolved to add file "/c%3A/Users/blasc/Projects/path/in/project/assemblies/UnityEngine.CoreModule/symbols/UnityEngine.Vector3.cs" to workspace

Any idea if there is a way to make it work? Is this a known issue?

@razzmatazz
Copy link
Owner

hm.. you may need to create a dummy .csproj for csharp-ls to work

a basic minimum copied from the output dir from dotnet new console should work -- or at least you should try, as I don't have any experience with unity

@gorsheninmv
Copy link

I came across the same problem on Windows and Neovim. The problem is Neovim lsp client makes the uri like file:///D:\Path\to\file.cs then

    let handleTextDocumentDidOpen (scope: ServerRequestScope) (openParams: Types.DidOpenTextDocumentParams): 
...
                let docFilePath = openParams.TextDocument.Uri.Substring("file://".Length) 

docFilePath has value /D:\Path\to\file.cs that is impossible to find.

And it's not the problem of Neovim you can see available uri options here: https://en.wikipedia.org/wiki/File_URI_scheme

@razzmatazz
Copy link
Owner

razzmatazz commented Jan 16, 2023

thanks for great follow up.. will check now

razzmatazz added a commit that referenced this issue Jan 16, 2023
Things should work on Windows now too, hopefully
@razzmatazz
Copy link
Owner

Hopefully f63f3e4 fixes your issues on Windows (I don't have Windows machine nearby to test though)

If you're not able to compile/run csharp-ls to validate this fix I will release new version later.

razzmatazz added a commit that referenced this issue Jan 16, 2023
@borring
Copy link

borring commented Jan 17, 2023

Not sure if this is related, but:
I'm running on the commit directly after your f63f3e4 fix.

csharp-ls finds the csproj file, no problem. The file is added to workspace and there's LSP goodness in the buffer.

However, it seems like no other projects get loaded. When I get hover text on classes outside of the current csproj, it just gives me a generic xxxxx from assembly yyyy. Then also interestingly, when I open up a cs file from another csproj, csharp-ls tells me that it cannot find a parent project even though there is in fact a csproj file.

first file:

LSP[csharp_ls][Log] csharp-ls: attempting to find and load solution based on cwd ("C:\source\..\projA\..cs")..
LSP[csharp_ls][Log] csharp-ls: 0 solution(s) found: []
LSP[csharp_ls][Log] csharp-ls: no or multiple .sln files found on C:\source\..\projA ..
LSP[csharp_ls][Log] csharp-ls: looking for .csproj/fsproj files on C:\source\..\projA ..
LSP[csharp_ls][Log] csharp-ls: loading project "C:\source\..\projA\projA.csproj"..
LSP[csharp_ls][Log] csharp-ls: OK, 1 project files loaded

Opening a 2nd file from a related project

LSP[csharp_ls][Log] csharp-ls: No parent project could be resolved to add file "C:\source\..\projB\..cs" to workspace

On the other hand, if I open up the *.sln file first and let csharp-ls find and load all projects, I can open all the *.cs files no problem, and I can even get some LSP benefits. BUT, all hover texts still only show assembly information, and definition still returns a csharp:// uri instead of file://

Edit: It seems to work fine if I pass in the solution as an argument -s xyz.sln I'll just need to hack my editor to do this automatically.

@razzmatazz
Copy link
Owner

mhm.. ok, I definitely need to setup a Windows VM to verify all this on my own machine.. otherwise I will never fix this properly :(

@tcx4c70 tcx4c70 mentioned this issue Jul 25, 2023
2 tasks
@tcx4c70 tcx4c70 mentioned this issue Aug 24, 2023
@joefbsjr
Copy link

I also had this issue. It seems to be related to special characters in folders. The latest commits fixed in a sense, I don't get that error anymore, but no action works. It can't find reference to the symbols or anything, it is like the project is not loaded.
All files inside this folder has this issue, while in the other folders it works fine: Assets/_Project/Modules/@Core

@vlad-anger
Copy link

vlad-anger commented Oct 17, 2023

Anyone who use neovim with nvim-lspconfig & has issue that csharp-language-server (csharp_ls):

  1. Cant load projects | load only one project which you jump to, not all solutions in your workspace, so you can't normally jump to definition | references between them
  2. Or you can't jump to definition at all

You can solve it with:

  1. Provide correct root_dir in configs. Regular case would be to do pattern matching to *.sln | .git to find root
  2. You should setup decompiler

Here's an example of how you should configure lsp:

local lspconfig = require('lspconfig')

-- local csharp_ls_bin = "$HOME/git/csharp-language-server/src/CSharpLanguageServer/bin/Debug/net7.0/CSharpLanguageServer"
lspconfig.csharp_ls.setup {
  -- cmd = { csharp_ls_bin }, -- specify if you build project locally (modify csharp_ls_bin path first), otherwise download using `dotnet tools` & keep that like ignored

  -- custom handler to be able go-to-definition(vim.lsp.buf.definition())
  handlers = {
    -- [Decompiler repo](https://github.com/Decodetalkers/csharpls-extended-lsp.nvim)
    ["textDocument/definition"] = require('csharpls_extended').handler,
  },

  -- specify root_dir, so lsp can find all solutions related to your workspace
  root_dir = function(startpath)
    return lspconfig.util.root_pattern("*.sln")(startpath)
      or lspconfig.util.root_pattern("*.csproj")(startpath)
      or lspconfig.util.root_pattern("*.fsproj")(startpath)
      or lspconfig.util.root_pattern(".git")(startpath)
  end,
}

Related issues to csharp_ls in nvim-lspconfig to take a look and track:
neovim/nvim-lspconfig#2612

@emilioziniades
Copy link

Hey there, since neovim/nvim-lspconfig#2885 has been merged, the default configuration for csharp_ls in nvim-lspconfig should now prioritize *.sln files over *.csproj files if a solution file exists in the current directory or any parent directory.

All you need to do is update the nvim-lspconfig to the latest version on master, which is 7384e7149e79365c96dc623d9fa3444737776982 at the time of writing.

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

7 participants