From a8f4a7ae2c335197ef2defa3c5c8715f14f88f6b Mon Sep 17 00:00:00 2001 From: Tomas Vik Date: Sun, 25 Oct 2020 11:24:14 +0100 Subject: [PATCH 1/4] Extract common logic to getFileSearchExpression --- src/extension.ts | 4 ++-- src/parsing.ts | 8 ++------ src/utils.ts | 5 +++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9828e8a..e829036 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ import { filterNonExistingEdges, getColumnSetting, getConfiguration, - getFileTypesSetting, + getFileSearchExpression, } 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(",")}}` + getFileSearchExpression() ), false, false, diff --git a/src/parsing.ts b/src/parsing.ts index 6600154..eb720a3 100644 --- a/src/parsing.ts +++ b/src/parsing.ts @@ -11,9 +11,7 @@ import { findLinks, id, FILE_ID_REGEXP, - getFileTypesSetting, - getConfiguration, - getTitleMaxLength, + getFileSearchExpression, } 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(getFileSearchExpression()); const promises: Promise[] = []; diff --git a/src/utils.ts b/src/utils.ts index 1f43f61..f8e812a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -102,9 +102,10 @@ export const getFileIdRegexp = () => { export const FILE_ID_REGEXP = getFileIdRegexp(); -export const getFileTypesSetting = () => { +export const getFileSearchExpression = () => { const DEFAULT_VALUE = ["md"]; - return getConfiguration("fileTypes") || DEFAULT_VALUE; + const fileTypes = getConfiguration("fileTypes") || DEFAULT_VALUE; + return `**/*{${(fileTypes as string[]).map((f) => `.${f}`).join(",")}}`; }; export const getDot = (graph: Graph) => `digraph g { From a651fc9c6dac277cbdbaad9edb09a50c459ed9d9 Mon Sep 17 00:00:00 2001 From: Tomas Vik Date: Sun, 25 Oct 2020 11:50:21 +0100 Subject: [PATCH 2/4] Introduce searchGlob configuration. --- package.json | 7 ++++++- src/utils.ts | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 516920b..46f705e 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.searchGlob" : { + "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/utils.ts b/src/utils.ts index f8e812a..4dd26c1 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,10 +102,20 @@ export const getFileIdRegexp = () => { export const FILE_ID_REGEXP = getFileIdRegexp(); -export const getFileSearchExpression = () => { +export const getFileSearchExpression = (): string => { + const configFileTypes: string[] = getConfiguration("fileTypes"); + 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"]; - const fileTypes = getConfiguration("fileTypes") || DEFAULT_VALUE; - return `**/*{${(fileTypes as string[]).map((f) => `.${f}`).join(",")}}`; + const fileTypes = configFileTypes || DEFAULT_VALUE; + return `**/*{${fileTypes.map((f) => `.${f}`).join(",")}}`; }; export const getDot = (graph: Graph) => `digraph g { From 860c67205f6e019a2d3fb0863f7b2a38ac00277d Mon Sep 17 00:00:00 2001 From: Tomas Vik Date: Sun, 25 Oct 2020 11:53:31 +0100 Subject: [PATCH 3/4] Update readme with the searchGlob configuration option --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 30290a8..6cdbed9 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.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**) From 2dc95e648ac0877dab97d4e1922ec974f2363b44 Mon Sep 17 00:00:00 2001 From: Tomas Vik Date: Sun, 10 Jan 2021 09:32:22 +0100 Subject: [PATCH 4/4] Unify the naming to findFilesGlob throughout the codebase --- README.md | 2 +- package.json | 2 +- src/extension.ts | 4 ++-- src/parsing.ts | 4 ++-- src/utils.ts | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6cdbed9..12b713e 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ 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` +### `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. diff --git a/package.json b/package.json index 46f705e..db0c27b 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "default": "\\d{14}", "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" : { + "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"] diff --git a/src/extension.ts b/src/extension.ts index e829036..3c3c295 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ import { filterNonExistingEdges, getColumnSetting, getConfiguration, - getFileSearchExpression, + getFindFilesGlob, } from "./utils"; import { Graph } from "./types"; @@ -22,7 +22,7 @@ const watch = ( const watcher = vscode.workspace.createFileSystemWatcher( new vscode.RelativePattern( vscode.workspace.rootPath, - getFileSearchExpression() + getFindFilesGlob() ), false, false, diff --git a/src/parsing.ts b/src/parsing.ts index eb720a3..fe3173d 100644 --- a/src/parsing.ts +++ b/src/parsing.ts @@ -11,7 +11,7 @@ import { findLinks, id, FILE_ID_REGEXP, - getFileSearchExpression, + getFindFilesGlob, } from "./utils"; import { basename } from "path"; @@ -98,7 +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(getFileSearchExpression()); + const files = await vscode.workspace.findFiles(getFindFilesGlob()); const promises: Promise[] = []; diff --git a/src/utils.ts b/src/utils.ts index 4dd26c1..aa54c47 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -102,16 +102,16 @@ export const getFileIdRegexp = () => { export const FILE_ID_REGEXP = getFileIdRegexp(); -export const getFileSearchExpression = (): string => { +export const getFindFilesGlob = (): string => { const configFileTypes: string[] = getConfiguration("fileTypes"); - const searchGlob: string = getConfiguration("searchGlob"); - if (searchGlob) { + const findFilesGlob: string = getConfiguration("findFilesGlob"); + if (findFilesGlob) { if (configFileTypes) { vscode.window.showWarningMessage( - "You have both fileTypes and searchGlob settings defined, searchGlob is taking precedence." + "You have both fileTypes and findFilesGlob settings defined, findFilesGlob is taking precedence." ); } - return searchGlob; + return findFilesGlob; } const DEFAULT_VALUE = ["md"]; const fileTypes = configFileTypes || DEFAULT_VALUE;