microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.44k stars 28.62k forks source link

`vscode.ExcludeSettingOptions.FilesExclude` still seems to exclude search excludes #226858

Open connor4312 opened 2 weeks ago

connor4312 commented 2 weeks ago

Testing #226670

Test extension:

``` import * as vscode from 'vscode'; import * as fs from 'fs/promises'; import * as path from 'path'; import * as assert from 'assert'; export function activate(context: vscode.ExtensionContext) { const disposable = vscode.commands.registerCommand('extension.helloWorld', async () => { const wf = vscode.workspace.workspaceFolders![0].uri; await vscode.workspace.getConfiguration('files').update('exclude', { '**/*.fileexclude.*': true, '**/fileexclude/**': true, }, vscode.ConfigurationTarget.Workspace); await vscode.workspace.getConfiguration('search').update('exclude', { '**/*.searchexclude.*': true, '**/searchexclude/**': true, }, vscode.ConfigurationTarget.Workspace); makeAllFiles([ { name: '.gitignore', content: '**/bar.txt' }, 'foo.txt', 'bar.txt', 'fileexclude/foo.txt', 'fileexclude/bar.txt', 'searchexclude/foo.txt', 'searchexclude/bar.txt', 'nested1/foo.txt', 'nested1/bar.txt', 'nested2/foo.txt', 'nested2/bar.txt', ]); let output = ''; output += assertUris( ['foo.txt', 'nested1/foo.txt', 'nested2/foo.txt', 'searchexclude/foo.txt'], await vscode.workspace.findFiles2New([new vscode.RelativePattern(wf, '**/*.txt')], { useExcludeSettings: vscode.ExcludeSettingOptions.FilesExclude }) ); const doc = await vscode.workspace.openTextDocument({ content: output, language: 'plaintext', }); await vscode.window.showTextDocument(doc); }); function assertUris(expected: string[], uris: vscode.Uri[]) { try { const actual = uris.map(u => path.relative(vscode.workspace.workspaceFolders![0].uri.fsPath, u.fsPath)); assert.deepStrictEqual(actual.sort(), expected.sort()); } catch (e) { return String(e) + '\n\n'; } return `Case OK (${JSON.stringify(expected)})\n`; } async function makeAllFiles(files: (string | {name: string, content: string})[]) { const wf = vscode.workspace.workspaceFolders![0].uri.fsPath; for (const file of files) { const name = typeof file === 'string' ? file : file.name; const content = typeof file === 'string' ? '' : file.content; const target = path.join(wf, name); await fs.mkdir(path.dirname(target), { recursive: true }); await fs.writeFile(target, content); } } context.subscriptions.push(disposable); } ```

Fails with:

AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected

  [
    'foo.txt',
    'nested1/foo.txt',
    'nested2/foo.txt',
-   'searchexclude/foo.txt'
  ]

I expected { useExcludeSettings: vscode.ExcludeSettingOptions.FilesExclude } would not use my search exclude setting (only SearchAndFilesExclude would.)

andreamah commented 2 weeks ago

Strangely, this exclude issue is only happening on linux (not even WSL). I'll need to take a look.

andreamah commented 2 weeks ago

Hmm, I suddenly am not running into this. However- why aren't you predicting that the bar.txt files get matched? nvm, it's because it's in the gitignore

andreamah commented 2 weeks ago

This seems to repro for me on linux

  1. directly after reloading
  2. about 1 in 6 times

So it's hard to track down what's going on. It is the same with https://github.com/microsoft/vscode/issues/226861.

I will continue to investigate next iteration, as this just affects the FindFiles2 + FindFiles2New APIs.