OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

Omnisharp ignoring exclude options in omnisharp.json #1460

Open sicsix opened 5 years ago

sicsix commented 5 years ago

Issue Description

Cannot use FileOptions to prevent Omnisharp from processing unwanted directories using the FileOptions. Also cannot prevent RoslynExtensions (Roslynator) from processing directories. Tried using omnisharp.json in project folder and omnisharp.json in user folder. It does load RoslynExtensionOptions but FileOptions does not appear to work.

Steps to Reproduce

Create a project, put .cs files in a folder, add exclude options like shown here https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options

Expected Behavior

Files are not parsed by omnisharp, and problems are not highlighted by Roslynator

Actual Behavior

Directory is processed.

Environment information

VSCode version: 1.33.1 C# Extension: 1.18.0

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 2.2.203 Commit: e5bab63eca Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.2.203\ Host (useful for support): Version: 2.2.4 Commit: f95848e524 .NET Core SDKs installed: 1.1.0 [C:\Program Files\dotnet\sdk] 2.2.203 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |csharp|ms-vscode|1.18.0| |material-icon-theme|PKief|3.7.0| |Material-theme|zhuangtongfa|2.21.0| |output-colorizer|IBM|0.1.2| |prettier-vscode|esbenp|1.8.1| |theme-monokai-pro-vscode|monokai|1.1.12| |todo-tree|Gruntfuggly|0.0.126| |unity-code-snippets|kleber-swf|1.3.0| |unity-debug|Unity|2.7.2| |unity-tools|Tobiah|1.1.0| |vsc-material-theme|Equinusocio|2.8.2| |vscode-npm-script|eg2|0.3.5|;
filipw commented 5 years ago

It seems that documentation is not being clear about that - FileOptions is used to control which projects OmniSharp should look at, not individual files. What you are asking for is currently not supported.

I will also move this issue to https://github.com/OmniSharp/omnisharp-roslyn repo.

aarononeal commented 5 years ago

@filipw This doesn't work for projects either. They still get processed.

# omnisharp.json
{
  "fileOptions": {
    "userExcludeSearchPatterns": [
      "**/test-input/msbuild/bad.csproj"
    ]
  }
}
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/build-kit-js/test-input/msbuild/bad.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: bad
aarononeal commented 5 years ago

Actually, appears to be a documentation bug. The following with excludeSearchPatterns instead works:

{
  "fileOptions": {
    "excludeSearchPatterns": [
      "**/test-input/msbuild/bad.csproj"
    ]
  }
}
zgramana commented 4 years ago

Bumping into this with a gRPC project: omnisharp-roslyn is reporting problems found in a project's obj/… folder.

The principle of least astonishment suggests obj and bin should excluded from scanning by default.

Malikazz commented 4 years ago

I have the same problem with obj and bin as stated, is there no way to disable it scanning a folder? Is this something that should be in requested features?

ijacquez commented 4 years ago

Is it fileOptions or FileOptions? Also, can it be used to ignore specific .dlls from coming up in a code completion?

idrisnacer commented 4 years ago

As a workaround for obj folder, i redirected it outside the project :

filipw commented 4 years ago

@aarononeal thanks 🤦‍♂ I corrected the docs.

ghost commented 4 years ago

Roslyn seems to be scanning auto-gen files from the Unity Library folder, and I've tried several different versions of the globs above to exclude the respective .csproj files, but none of them seemed to work. I'll be disabling Roslyn for now, but if anyone has a workaround, specifically for this use case, I'd highly appreciate it.

yevhen commented 4 years ago

globbing doesn't work properly for excludeSearchPatterns (on Windows). Having **/*.csproj still scans all project files. OmniSharp: ms-dotnettools.csharp-1.21.16.omnisharp\1.34.15

Iron-E commented 4 years ago

Coming here from #1766.

The description for excludeSearchPatterns and systemExcludeSearchPatterns is:

Used to define which directories and files should not be included in OmniSharp's file scanning/discovery process.

I feel like after reading everything here, that isn't truly representative of what it does. If it cannot actually exclude files from scanning, I think we should have a different description there. Ideally, the warning wouldn't be necessary. Maybe something like this would be better:

Used to define which directories and files should be included in OmniSharp's project file / solution file discovery process. Not individual .cs files.

Iron-E commented 4 years ago

As for excluding specific files from the project, I have to agree with @zgramana:

The principle of least astonishment suggests obj and bin should excluded from scanning by default.

Most of the warnings in my project are from this directory. It makes real errors incredibly difficult to find. If the feature of adding excluded files and directories from actual scanning is not planned, those directories should at least be off by default, since we as developers have little control over their output.

filipw commented 4 years ago

The description for excludeSearchPatterns and systemExcludeSearchPatterns is:

Used to define which directories and files should not be included in OmniSharp's file scanning/discovery process.

I think this is semantics - Omnisharp doesn't ever "discover" .cs files since MsBuild does it. The only files OmniSharp would discover would be "sln/csproj".

Plus, there is a warning just below that explains just that (in bold!) - Warning: this features allows disabling of project file / solution file discovery not individual .cs files.. However, since this is a wiki (https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options) feel free to just edit it the way you feel like makes more sense - thanks and appreciate the help!

2ndwolf commented 4 years ago

Omnisharp isn't honoring my excludeSearchPatterns option. I have tried restarting it multiple times, trying multiple patterns ignoring libs.

Such as:

**/libs/**/*
./libs/**/*
/libs/**/*

Am I just confused?

{
  "fileOptions": {
    "systemExcludeSearchPatterns": [
      "**/node_modules/**/*",
      "**/bin/**/*",
      "**/obj/**/*",
      "**/node_modules/**/*"
    ],
    "excludeSearchPatterns": [
      "**/libs/**/*"
    ]
  },
    "formattingOptions": {
        "tabSize": 2
    }
}

image

Smoovsky commented 4 years ago

Omnisharp isn't honoring my excludeSearchPatterns option. I have tried restarting it multiple times, trying multiple patterns ignoring libs.

Such as:

**/libs/**/*
./libs/**/*
/libs/**/*

Am I just confused?

{
  "fileOptions": {
    "systemExcludeSearchPatterns": [
      "**/node_modules/**/*",
      "**/bin/**/*",
      "**/obj/**/*",
      "**/node_modules/**/*"
    ],
    "excludeSearchPatterns": [
      "**/libs/**/*"
    ]
  },
    "formattingOptions": {
        "tabSize": 2
    }
}

image

I think the reason is that once it's using the solution file, it will discover all the projects in the solution. And here is no way to ask omnisharp to disregard a .sln file if it exists in your root workspace.

2ndwolf commented 4 years ago

I've left aside that project a while ago so I'll answer the best I can.

Well they're not in my root workspace, but divided in a libs folder. Unless you mean if they are mentioned as something that is used by the project? It would make sense then but if I remember correctly that really slowed down omnisharp. Also, Audrey.Tests.csproj was broken I think. I'm guessing the solution would be to remove references to it from the sln.

Smoovsky commented 4 years ago

I've left aside that project a while ago so I'll answer the best I can.

Well they're not in my root workspace, but divided in a libs folder. Unless you mean if they are mentioned as something that is used by the project? It would make sense then but if I remember correctly that really slowed down omnisharp. Also, Audrey.Tests.csproj was broken I think. I'm guessing the solution would be to remove references to it from the sln.

I just tested it out: If there is any .sln file in your workspace(including subfolders), Omnisharp will always try to open one of them and use it as the entry point for discovery and I simply can not stop this behavior. And, Yes, it will include those projects which are referenced but not in solution. The walkaround is also simple enough, I can create a fake solution which only contains part of the entire project tree, or, I can just temporarily rename or remove the .sln file, and reverse it later. If Omnisharp couldn't find any .sln file, it will try to discover the workspace folder while honoring the exclude section in omnisharp.json

Davilink commented 4 years ago

Solution Filter maybe can help https://github.com/OmniSharp/omnisharp-roslyn/pull/1952

RamunasAdamonis commented 2 years ago

Did someone managed to make it work with solution filter and has a working example to share?