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
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Controls in which column should clicked files open. Refer to [Column values](###

A [regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) used to find the file ID for use in wiki-style links.

### `markdown-links.searchGlob`

[Glob pattern](https://code.visualstudio.com/api/references/vscode-api#GlobPattern) used to find files to parse with the Markdown Links extension. Handy in a case that you want only a part of your workspace parsed.

### `markdown-links.graphType`

- `default` (**default**)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
"markdown-links.fileIdRegexp": {
"type": "string",
"default": "\\d{14}",
"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 :)

"type": "string",
"description": "Glob pattern used to find files to parse with the Markdown Links extension. https://code.visualstudio.com/api/references/vscode-api#GlobPattern",
"examples": ["**/*.md", "notes-folder/*.md"]
},
"markdown-links.autoStart": {
"type": "boolean",
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
filterNonExistingEdges,
getColumnSetting,
getConfiguration,
getFileTypesSetting,
getFileSearchExpression,
} from "./utils";
import { Graph } from "./types";

Expand All @@ -22,7 +22,7 @@ const watch = (
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
vscode.workspace.rootPath,
`**/*{${getFileTypesSetting().join(",")}}`
getFileSearchExpression()
),
false,
false,
Expand Down
8 changes: 2 additions & 6 deletions src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
findLinks,
id,
FILE_ID_REGEXP,
getFileTypesSetting,
getConfiguration,
getTitleMaxLength,
getFileSearchExpression,
} from "./utils";
import { basename } from "path";

Expand Down Expand Up @@ -100,9 +98,7 @@ export const parseDirectory = async (
) => {
// `findFiles` is used here since it respects files excluded by either the
// global or workspace level files.exclude config option.
const files = await vscode.workspace.findFiles(
`**/*{${(getFileTypesSetting() as string[]).map((f) => `.${f}`).join(",")}}`
);
const files = await vscode.workspace.findFiles(getFileSearchExpression());

const promises: Promise<void>[] = [];

Expand Down
19 changes: 15 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const findTitle = (ast: MarkdownNode): string | null => {
child.children &&
child.children.length > 0
) {
let title = child.children[0].value!
let title = child.children[0].value!;

const titleMaxLength = getTitleMaxLength();
if (titleMaxLength > 0 && title.length > titleMaxLength) {
Expand Down Expand Up @@ -83,7 +83,7 @@ const settingToValue: { [key: string]: vscode.ViewColumn | undefined } = {

export const getTitleMaxLength = () => {
return getConfiguration("titleMaxLength");
}
};

export const getColumnSetting = (key: string) => {
const column = getConfiguration(key);
Expand All @@ -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.

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.

const searchGlob: string = getConfiguration("searchGlob");
if (searchGlob) {
if (configFileTypes) {
vscode.window.showWarningMessage(
"You have both fileTypes and searchGlob settings defined, searchGlob is taking precedence."
);
}
return searchGlob;
}
const DEFAULT_VALUE = ["md"];
return getConfiguration("fileTypes") || DEFAULT_VALUE;
const fileTypes = configFileTypes || DEFAULT_VALUE;
return `**/*{${fileTypes.map((f) => `.${f}`).join(",")}}`;
};

export const getDot = (graph: Graph) => `digraph g {
Expand Down