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:
- Open VS Code with the specific project directory as the workspace root. For example:
code /home/eje211/src/projectname
- 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.