Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

includes option underneath the existing excludes option #883

Open
bobmagicii opened this issue Dec 13, 2019 · 15 comments
Open

includes option underneath the existing excludes option #883

bobmagicii opened this issue Dec 13, 2019 · 15 comments

Comments

@bobmagicii
Copy link

bobmagicii commented Dec 13, 2019

Feature description or problem with existing feature
an includes option that operates on the principle of exclude > include. to get things to work well on our codebase i had to add a bunch of lines to our excludes to make sure that it only scans folders that contain php classes, especially skipping a symlink to a remote filesystem.

	"intelephense.files.exclude": [
		"**/.git/**",
		"**/backups/**",
		"**/data/**",
		"**/log/**",
		"**/test/**",
		"**/tests/**",
		"**/tools/**",
		"**/vendor/**/{vendor,tests}/**",
		"**/www/**"
	],

in our project this only leaves most of vendor, and our core folder which is a psr0 autoload dir.

Describe the solution you'd like

	"intelephense.files.include": [
		"**/core",
		"**/vendor"
	],
	"intelephense.files.exclude": [
		"**/vendor/**/{vendor,tests}/**",
	],

where if include is an empty array or null, you'd fall back to the current behaviour of it just scanning the entire workspace for backwards compat.

Additional context
each of our projects is going to need the excludes in the workspace .vscode/settings.json but with minor variations. it would be nice if we could first tell it "you are allowed to go here, but still skip some of this crap"

additionally, the next folder that gets added to the project by someone who doesn't have my experience trying to get it all working might not know they need to add that to the excludes. this makes it also a handy extra-cautious future proofing against freshmen on the dev team.

cheers m8

@bmewburn
Copy link
Owner

So you want to exclude everything except for core and vendor for example? I haven't tried it but does a glob pattern in exclude like below work?

**/!(core|vendor)/**

@KapitanOczywisty
Copy link
Contributor

Unless you're using own glob implementation - not supported in vscode microsoft/vscode#869

@zorac
Copy link

zorac commented Feb 18, 2020

This would also be useful to allow hiding the vendor folder in the explorer, if it override the top level files.exclude:

"files.exclude": [
	"**/vendor"
],
"intelephense.files.include": [
	"**/vendor"
],

@mikehaertl
Copy link

@bmewburn Can you point to a documentation for the supported glob patterns?

I also have the case where basically I want to say: Exclude everything in vendor or below that sounds like test or tests - except for all the files that are in vendor/x/test

@mikehaertl
Copy link

Should have opened my eyes - it's probably https://github.com/mrmlnc/fast-glob as mentioned in the README. Will check if it's possible to solve the problem with a nifty glob pattern.

@mikehaertl
Copy link

mikehaertl commented Oct 19, 2020

@bmewburn I would say the following pattern should work - but it doesn't:

  "intelephense.files.exclude": [
    "!**/vendor/foo/bar",
    "**/vendor/**/{Test,Tests,test,tests}/**"
  ]

It should exclude all the test directories except all the files from vendor/foo/bar/test/ but they are still included. I've done a little test with fast-glob myself.

const fg = require('fast-glob');
const entries = fg.sync([
    "!**/vendor/foo/bar",
    "**/vendor/**/{Test,Tests,test,tests}/**"
]);
console.log(entries);

Here the result is the correct list of all files and does not include vendor/foo/bar/test.

So I assume that glob expansion of excludes is implemented a bit different. Any ideas?

@KapitanOczywisty
Copy link
Contributor

KapitanOczywisty commented Oct 19, 2020

@mikehaertl These patterns are probably going to vscode api function itself (like this)

But if you're really, really, reeeaaaally desperate:
**/node_modules/{[^f]*,f[^o]*,fo[^o]*,foo?*}/**/{Test,Tests,test,tests}/**

@mikehaertl
Copy link

@KapitanOczywisty

createFileSystemWatcher(globPattern: GlobPattern, ignoreCreateEvents?: boolean, ignoreChangeEvents?: boolean, ignoreDeleteEvents?: boolean): FileSystemWatcher

This call only expects glob patterns for a directory to watch. But this issue is about the exclude pattern. So even if this API method is used I assume that the list of directories/patterns to watch is first checked agains the exclude patterns somehow.

BTW thanks for the workaround - it's indeed quite ugly, so a proper fix would be nice.

@KapitanOczywisty
Copy link
Contributor

@mikehaertl I've copied wrong link, I meant next one: findFiles.

There isn't good way to "fix" it in intelephense without bypassing build-in api, which is very bad idea, because you can have custom FileSystemProviders in vscode and these won't be supported by fast-glob etc. For this feature, please upvote following issue microsoft/vscode#869

@mikehaertl
Copy link

@KapitanOczywisty I see, thanks. But looking at how old that issue is we can safely assume that this will never get fixed. Too bad.

@KapitanOczywisty
Copy link
Contributor

@mikehaertl They're trying to include older issues in every iteration and issues with more recent activity have higher chance to be worked on.

@bobmagicii
Copy link
Author

bobmagicii commented Oct 21, 2020

with the addition of vscode's proper remote development extension this became mostly a non-issue for me as sshfs is no longer choking (or even being used) on scanning files i don't even care about. it still seems like it could be nice to avoid getting pointless suggestions, but as a critical need now not any more.

@bmewburn
Copy link
Owner

The vscode file finding api was used in the past but then this functionality was moved server side (to support other editors) and fast-glob is now used. So any pattern in fast-glob should work.

@mikehaertl in your fast-glob test it looks like you not using the ignore option.

@mikehaertl
Copy link

@bmewburn From another test it seems that it's really an issue with fs-glob and there's already a related issue: mrmlnc/fast-glob#86 which unfortunately is not fixed yet despite being 2 years old.

If you agree that this causes the problem I'll add a comment with the following example there:

$ npm install fast-glob
$ mkdir -p vendor/{a,b,c}/test
$ touch vendor/{a,b,c}/file.txt
$ touch vendor/{a,b,c}/test/file.txt
$ tree
.
└── vendor
    ├── a
    │   ├── file.txt
    │   └── test
    │       └── file.txt
    ├── b
    │   ├── file.txt
    │   └── test
    │       └── file.txt
    └── c
        ├── file.txt
        └── test
            └── file.txt
const fg = require('fast-glob');
const entries = fg.sync(
  [
    "**/*.txt"
  ],
  {
    ignore: [
      "!**/vendor/a/test",
      "**/vendor/**/test/*.txt"
    ]
  }
);
console.log(entries);
$ node test.js 
[ 'vendor/a/file.txt', 'vendor/b/file.txt', 'vendor/c/file.txt' ]

Expected result:

[ 'vendor/a/file.txt',  'vendor/b/file.txt',  'vendor/c/file.txt',  'vendor/a/test/file.txt' ]

@glen-84
Copy link

glen-84 commented Dec 27, 2021

This would also be useful to allow hiding the vendor folder in the explorer, if it override the top level files.exclude:

"files.exclude": [
	"**/vendor"
],
"intelephense.files.include": [
	"**/vendor"
],

@zorac As a workaround, you can use "intelephense.environment.includePaths": ["vendor"].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants