Repository: OmniSharp/omnisharp-vscode
Pull request #5382 (2022-09-23 02:26:48)

Add projectFilesIncludePattern & projectFilesExcludePattern options.
Add two options instead of hardcoded string, so that user have chance to change it.

dnfadmin: [![CLA assistant check](https://cla.dotnetfoundation.org/pull/badge/not_signed)](https://cla.dotnetfoundation.org/OmniSharp/omnisharp-vscode?pullRequest=5382) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla.dotnetfoundation.org/OmniSharp/omnisharp-vscode?pullRequest=5382) before we can accept your contribution.<br/><br/>:x: xieyubo [sign now](https://cla.dotnetfoundation.org/OmniSharp/omnisharp-vscode?pullRequest=5382)<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla.dotnetfoundation.org/check/OmniSharp/omnisharp-vscode?pullRequest=5382) it.</sub>
JoeRobich: So I have a few thoughts about this, 
1) The include pattern is not something that should be adjusted. We have to specify what activates our extension at publish time and changes to this setting would not have an effect.
https://github.com/OmniSharp/omnisharp-vscode/blob/55bc0546da2a3b233133d1dca3eee2e1e964f59f/package.json#L603
Also, we can't introduce "new" project or solution types to load as we specifically look for the extensions being searched for a nothing else (see `resourcesAndFolderMapToLaunchTargets` method in launcher.ts).
2) The excludes pattern may not be necessary either. It may be more correct for us to union our exclude patterns with those configured in `files.exclude`. Would this achieve the result you are looking for?

xieyubo: The use case: our project contains a lot of *.csproj files (no .sln file, we use dirs.proj to manage). We also have a git submodule which comes from a third-party repository contains a lot of *.sln files. Now, when we launch vscode, it will automatically load the projects from the third-party repository. We want to exclude the third-party folder totally. Is there anyway to do?
JoeRobich: @xieyubo Ah, in that case you would still want to see the files from the submodule in VS Code, but simply not have them be considered as a project location. If you remove the include pattern setting, I think we could take this PR.

Patch:
diff --git a/package.json b/package.json
index 992f898d..1f45042f 100644
--- a/package.json
+++ b/package.json
@@ -1013,6 +1013,11 @@
           "default": true,
           "description": "Specifies whether the OmniSharp server will be automatically started or not. If false, OmniSharp can be started with the 'Restart OmniSharp' command"
         },
+        "omnisharp.projectFilesExcludePattern" :{
+          "type": "string",
+          "default": "**/node_modules/**,**/.git/**,**/bower_components/**",
+          "description": "The exclude pattern used by OmniSharp to find all project files."
+        },
         "omnisharp.projectLoadTimeout": {
           "type": "number",
           "default": 60,
diff --git a/src/omnisharp/launcher.ts b/src/omnisharp/launcher.ts
index 52c2422d..16c7be82 100644
--- a/src/omnisharp/launcher.ts
+++ b/src/omnisharp/launcher.ts
@@ -65,7 +65,7 @@ export async function findLaunchTargets(options: Options): Promise<LaunchTarget[
 
     const projectFiles = await vscode.workspace.findFiles(
         /*include*/ '{**/*.sln,**/*.slnf,**/*.csproj,**/project.json,**/*.csx,**/*.cake}',
-        /*exclude*/ '{**/node_modules/**,**/.git/**,**/bower_components/**}');
+        /*exclude*/ `{${options.projectFilesExcludePattern}}`);
 
     const csFiles = await vscode.workspace.findFiles(
         /*include*/ '{**/*.cs}',
diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts
index 9ca8bb53..7fc6e4b0 100644
--- a/src/omnisharp/options.ts
+++ b/src/omnisharp/options.ts
@@ -12,6 +12,7 @@ export class Options {
         public waitForDebugger: boolean,
         public loggingLevel: string,
         public autoStart: boolean,
+        public projectFilesExcludePattern: string,
         public projectLoadTimeout: number,
         public maxProjectResults: number,
         public useEditorFormattingSettings: boolean,
@@ -94,6 +95,7 @@ export class Options {
 
         const autoStart = omnisharpConfig.get<boolean>('autoStart', true);
 
+        const projectFilesExcludePattern = omnisharpConfig.get<string>('projectFilesExcludePattern', '**/node_modules/**,**/.git/**,**/bower_components/**');
         const projectLoadTimeout = omnisharpConfig.get<number>('projectLoadTimeout', 60);
         const maxProjectResults = omnisharpConfig.get<number>('maxProjectResults', 250);
         const defaultLaunchSolution = omnisharpConfig.get<string>('defaultLaunchSolution', '');
@@ -157,6 +159,7 @@ export class Options {
             waitForDebugger,
             loggingLevel,
             autoStart,
+            projectFilesExcludePattern,
             projectLoadTimeout,
             maxProjectResults,
             useEditorFormattingSettings,


Test patch:
diff --git a/test/unitTests/Fakes/FakeOptions.ts b/test/unitTests/Fakes/FakeOptions.ts
index 0a3d55ee..c0e1b192 100644
--- a/test/unitTests/Fakes/FakeOptions.ts
+++ b/test/unitTests/Fakes/FakeOptions.ts
@@ -12,6 +12,7 @@ export function getEmptyOptions(): Options {
         /* waitForDebugger */false,
         /* loggingLevel */"",
         /* autoStart */false,
+        /* projectFilesExcludePattern */"",
         /* projectLoadTimeout */0,
         /* maxProjectResults */0,
         /* useEditorFormattingSettings */false,