diff --git a/README.md b/README.md index 30290a8..12b713e 100644 --- a/README.md +++ b/README.md @@ -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.findFilesGlob` + +[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**) diff --git a/package.json b/package.json index 516920b..db0c27b 100644 --- a/package.json +++ b/package.json @@ -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.findFilesGlob" : { + "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", diff --git a/src/extension.ts b/src/extension.ts index 9828e8a..3c3c295 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ import { filterNonExistingEdges, getColumnSetting, getConfiguration, - getFileTypesSetting, + getFindFilesGlob, } from "./utils"; import { Graph } from "./types"; @@ -22,7 +22,7 @@ const watch = ( const watcher = vscode.workspace.createFileSystemWatcher( new vscode.RelativePattern( vscode.workspace.rootPath, - `**/*{${getFileTypesSetting().join(",")}}` + getFindFilesGlob() ), false, false, diff --git a/src/parsing.ts b/src/parsing.ts index 6600154..fe3173d 100644 --- a/src/parsing.ts +++ b/src/parsing.ts @@ -11,9 +11,7 @@ import { findLinks, id, FILE_ID_REGEXP, - getFileTypesSetting, - getConfiguration, - getTitleMaxLength, + getFindFilesGlob, } from "./utils"; import { basename } from "path"; @@ -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(getFindFilesGlob()); const promises: Promise[] = []; diff --git a/src/utils.ts b/src/utils.ts index 1f43f61..aa54c47 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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) { @@ -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); @@ -102,9 +102,20 @@ export const getFileIdRegexp = () => { export const FILE_ID_REGEXP = getFileIdRegexp(); -export const getFileTypesSetting = () => { +export const getFindFilesGlob = (): string => { + const configFileTypes: string[] = getConfiguration("fileTypes"); + const findFilesGlob: string = getConfiguration("findFilesGlob"); + if (findFilesGlob) { + if (configFileTypes) { + vscode.window.showWarningMessage( + "You have both fileTypes and findFilesGlob settings defined, findFilesGlob is taking precedence." + ); + } + return findFilesGlob; + } 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 {