csharp-language-server icon indicating copy to clipboard operation
csharp-language-server copied to clipboard

Exclude directories

Open xFA25E opened this issue 2 years ago • 2 comments

Hi, thanks for the great project!

I'm having issues with exclusion of some directories. I'm using direnv (with nix on linux) which puts, in the project directory, a .direnv directory where cached files are stored. It stores there *.sln and *.csproj files, too. Which is a problem, since csharp-ls detects them and thinks that there is a solution in there.

Currently, I'm using a custom patch to deal with this issue, but I was thinking maybe there is a better solution.

Does csharp-ls have a generic mechanism for exclusion of certain directories?

I presume it doesn't, because there is a hardcoded exclusion of node_modules directory. Should csharp-ls provide this generic mechanism?

In case you might need it, here is the patch:

diff --git a/src/CSharpLanguageServer/RoslynHelpers.fs b/src/CSharpLanguageServer/RoslynHelpers.fs
index 2cd6c9c..68f5e53 100644
--- a/src/CSharpLanguageServer/RoslynHelpers.fs
+++ b/src/CSharpLanguageServer/RoslynHelpers.fs
@@ -865,9 +865,15 @@ let findAndLoadSolutionOnDir logMessage dir = async {
         |> Seq.contains "node_modules"
         |> not
 
+    let fileNotOnDotDirenv (filename: string) =
+        filename.Split(Path.DirectorySeparatorChar)
+        |> Seq.contains ".direnv"
+        |> not
+
     let solutionFiles =
         Directory.GetFiles(dir, "*.sln", SearchOption.AllDirectories)
         |> Seq.filter fileNotOnNodeModules
+        |> Seq.filter fileNotOnDotDirenv
         |> Seq.toList
 
     logMessage (sprintf "%d solution(s) found: [%s]" solutionFiles.Length (String.Join(", ", solutionFiles)) )

xFA25E avatar Jan 14 '23 12:01 xFA25E

Hmm.. I couldn't find anything on https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/ that would enable an editor/environment to submit excluded dirs.. unless I am not search this properly

So at the moment.. no mechanism there, maybe I could add a command line param to exclude directories?

This project is a bit of a hack :) -- thus the "node_modules" manual exclusion. So if you could make a PR that doesn't break other people's environment I will be willing to merge it.

Also of note, there is a "-s" optional argument available to specify an explicit solution to load, which maybe of help to you, especially if you have multiple legit solution files on your project dir.

razzmatazz avatar Jan 16 '23 09:01 razzmatazz

Even If it's a hack, it is working quite well :) Sadly, I had some issues with omnisharp-roslyn, so I tried csharp-lsp.

Thanks for the note of "-s" option, I missed it somehow. I'll try it.

I have literally 0 knowledge of F#, so I don't think that I'm qualified enough for a PR, for now. I definitely gonna learn it in the near future, so maybe I'll send it later.

However, I think that the main problem is in the solution. It would be great to hook into the existing mechanisms. I would like to use only files that are not ignored by git, but, in that case, csharp-ls will not provide support for the non-git users. Inventing our own .csharp-ls-ignore, IMO, is not very practical, since the maintenance costs are too high.

You can close this issue if you want and thanks again :)

xFA25E avatar Jan 17 '23 12:01 xFA25E