Omnisharp on Linux fails because it's looking through looping directories for no reason

When I start Visual Studio Code with a C# project, I get this in the output tab: [stdout] {"Event":"log","Body":{"LogLevel":"ERROR","Name":"OmniSharp.WorkspaceIn - Pastebin.com

It seems to have found a looping path inside some of my Wine prefixes. But it has no business looking there in the first place! The project itself is in /home/eje211/src/projectname. I cannot find a setting that causes Omnisharp, Cake, or whatever other extension, to look upwards in the file system.

I have been deleting or moving these prefixes as Omnisharp finds them. (Many of them were no longer useful anyway.) But this does not feel like a good solution. If anyone knows how to stop Omnisharp from looking where it shouldn’t please let me know.

OmniSharp’s recursive search behavior can indeed be frustrating, especially if it unnecessarily crawls through directories like Wine prefixes. This behavior typically stems from OmniSharp’s attempt to search for .NET projects, scripts, and solutions within the workspace directory and potentially even higher-level directories. Here’s how to prevent OmniSharp from scanning unwanted areas:

1. Adjust OmniSharp Search Depth

To limit the directories OmniSharp crawls, try setting a maximum depth for its recursive search. This can sometimes be configured in the settings.json file in VS Code with:

"omnisharp.path": "latest",
"omnisharp.projectLoadTimeout": 60,
"omnisharp.searchDepth": 1

Setting "omnisharp.searchDepth": 1 tells OmniSharp to search only the immediate directory of your project.

2. Use a .gitignore or .omnisharpignore File

If OmniSharp respects .gitignore files in your project, try adding an ignore rule for the Wine prefixes or other unwanted directories. If OmniSharp doesn’t respect .gitignore, you can try creating a .omnisharpignore file in the project root and add patterns to ignore specific directories or paths:

# Ignore all Wine prefixes
/home/username/.wine

# Ignore any other unwanted paths
/path/to/other/unwanted/dir

3. Specify the Exact Project Path

If the above methods don’t work, try opening the project folder in a way that limits OmniSharp’s visibility to that specific directory:

  1. Open VS Code with the specific project directory as the workspace root. For example:
code /home/eje211/src/projectname
  1. Avoid opening parent directories (like /home/eje211/src) to ensure OmniSharp won’t search upwards.

4. Set omnisharp.json Config File in Project Directory

You can also add an omnisharp.json configuration file directly in your project’s root directory to specify OmniSharp’s behavior more explicitly. In this file, add:

{
    "fileOptions": {
        "excludeSearchPatterns": [
            "/home/eje211/.wine/*"
        ]
    }
}

This configuration excludes specific paths, such as your Wine prefixes, from OmniSharp’s search paths.

5. Alternative Solution: Use OmniSharp in “Solution” Mode

If you work on a single .sln file in your project, you can configure OmniSharp to load only the solution file and avoid searching for additional projects or directories:

"omnisharp.useGlobalMono": "always",
"omnisharp.projectLoadTimeout": 60

Summary

Using a combination of limiting search depth, excluding paths, and opening the exact project directory should prevent OmniSharp from accessing irrelevant directories like Wine prefixes. These adjustments should help keep OmniSharp focused only on the project at hand.

If OmniSharp continues to exhibit the same issue, a final step could be to check its GitHub issues for similar reports, as community or official solutions may become available.