kortina / vscode-markdown-notes

Install from: https://ark.dance/md-notes
GNU General Public License v3.0
427 stars 65 forks source link

Group notation in search.exclude breaks auto-suggestion #137

Open alexis- opened 3 years ago

alexis- commented 3 years ago

Hello,

Describe the bug While setting up your extension (great job!), I found out that using group notations such as **.{docs,pdf} in search.exclude breaks auto-suggestions.

Hypothetically, the same could be true with files.exclude, although I haven't tested that option.

To Reproduce

Steps to reproduce the behavior:

  1. Go to global or workspace settings
  2. Add under settings:
    "search.exclude": {
      "**.{doc,docx}": true,
    }
  3. Test auto-suggestion (either Ctrl+Space or auto suggest),
  4. See "No suggestions."

Expected behavior Suggestions

Versions

kortina commented 3 years ago

The relevant code is in this lib: https://github.com/kortina/vscode-markdown-notes/blob/master/src/findNonIgnoredFiles.ts

Which I basically found all of the code for in this vscode issue: https://github.com/microsoft/vscode/issues/48674

Help appreciated on this one, as I'm not sure when I'll get around to it.

NB (1)

I was able to duplicate on macos, and I found more detail on the error by opening Log (Extension Host) in the Output Panel:

image

[2021-04-09 15:24:33.724] [exthost] [error] [kortina.vscode-markdown-notes] provider FAILED
[2021-04-09 15:24:33.724] [exthost] [error] Error: command failed with error code 2: error parsing glob '!/{**/node_modules,**/bower_components,**/*.code-search,**.{doc,docx},**/.git,**/.svn,**/.hg,**/CVS,**/.DS_Store}': nested alternate groups are not allowed

NB (2) workaround

I was able to workaround by modifying search.exclude as follows:

  "search.exclude": {
    "**.doc": true,
    "**.docx": true,
  },

which I believe is equivalent, just more verbose.

alexis- commented 3 years ago

Hello Kortina,

I only had a cursory glance at the code you sent, please take my remarks with a grain of salt.

Issue 1 - Nested alternate groups

image

In your screenshot we can see the "alternate group" **.{doc.docs} is nested within a larger one. The compilers gives off the error:

nested alternate groups are not allowed.

See my 2 comments in the code excerpt:

  const exclude = [
    // >> The next line includes **.{doc,docx} in the array
    ...Object.keys((await workspace.getConfiguration('search', null).get('exclude')) || {}),
    ...Object.keys((await workspace.getConfiguration('files', null).get('exclude')) || {}),
  ].join(',');

  // >> The array containing **.{doc,docx} is nested within another alternate group {... ,**.{doc,docx}, ...}
  const uris = await workspace.findFiles(pattern, `{${exclude}}`);
  if (!checkGitIgnore) {
    return uris;
  }

Issue 2 - Search excludes

As far as I understand, search.exclude is only intended to exclude files from the search results (Ctrl+Shift+F, or search in the left panel).

Unless I am missing something, it seems like for MD Notes you'd only want to consider files.exclude.

Workaround

which I believe is equivalent, just more verbose.

That's the solution I've been using and it works well.