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

Introduce findFilesGlob configuration. Allows to define where to look for the files. #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

viktomas
Copy link

@viktomas viktomas commented Oct 25, 2020

Closes #63

This PR introduces a new configuration option, searchGlob. The configuration option is null by default and doesn't interfere with the current logic.

If set, the option overrides the expression generated from fileTypes configuration. If the fileTypes configuration has been set, we'll warn the user:

Screenshot 2020-10-25 at 11 49 19 AM

This PR contains 3 commits:

  1. the first commit only refactors the code in preparation for a change. There's no functionality change
  2. the second commit implements the change
  3. the third commit adds README entry

I tried to write tests, but I wasn't able to run them since this extension uses webpack rather than plain tsc.

src/utils.ts Outdated
@@ -102,9 +102,20 @@ export const getFileIdRegexp = () => {

export const FILE_ID_REGEXP = getFileIdRegexp();

export const getFileTypesSetting = () => {
export const getFileSearchExpression = (): string => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the naming getFileSearchExpression. It could be changed to getFindFilesGlob to make it more in sync with VS Code API?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFindFilesGlob sounds better to me. Although we probably don't want to shadow the API in case this is what happens here (I don't fully get what you mean so might be talking nonsense).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, findFilesGlob sounds better. I renamed:

  • getFilesSearchExpression to getFindFilesGlob
  • searchGlob to findFilesGlob

This way it's consistent throughout the whole change.

I don't fully get what you mean so might be talking nonsense

The second sentence in my comment only meant that VS Code API decided to name the option for finding files getFindFilesGlob. I think that it's good that we use the same naming if we don't have a particular reason to diverge.

@@ -102,9 +102,20 @@ export const getFileIdRegexp = () => {

export const FILE_ID_REGEXP = getFileIdRegexp();

export const getFileTypesSetting = () => {
export const getFileSearchExpression = (): string => {
const configFileTypes: string[] = getConfiguration("fileTypes");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably either deprecate this search option or include it to package.json and README.

package.json Outdated
"description": "Regular extension used to find file IDs. First match of this regex in file contents, excluding [[links]], will be used as the file ID. This file ID can be used for wiki-style links."
"description": "Regular expression used to find file IDs. First match of this regex in file contents, excluding [[links]], will be used as the file ID. This file ID can be used for wiki-style links."
},
"markdown-links.searchGlob" : {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we release this PR, searchGlob is going to be a part of the public interface and very hard to rename in the future. I'm open to any other names like fileSearchGlob findFilesExpression or any cobination of the search, find, files, expression, glob..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good idea. Appreciate a lot the fact that you consider it already at this point!

I think searchGlob is ok. Maybe it would be more future proof to specify what is the search we are doing here. Maybe fileDiscoveryGlob presents it better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with findFilesGlob for consistency. Let me know if that's ok :)

@Craskermasker
Copy link

Will this allow sub-directories to be excluded from the search?

@viktomas
Copy link
Author

@Craskermasker in some limited cases. This feature is more for defining where your notes are than where they aren't.

You can see more details in the VS Code API documentation for workspace.findFiles

There is an exclude parameter for that function that is probably more what you are after.

@viktomas viktomas changed the title Introduce searchGlob configuration. Allows to define where to look for the files. Introduce findFilesGlob configuration. Allows to define where to look for the files. Jan 10, 2021
@viktomas
Copy link
Author

@tchayen I addressed your feedback and tested the change locally (it still works). Please let me know if there's anything else I can do 👍

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

Successfully merging this pull request may close these issues.

Use custom search expression
3 participants