Skip to content

Commit

Permalink
Rework markdown update link glob (microsoft#164766)
Browse files Browse the repository at this point in the history
* Rework markdown update link glob

Fixes microsoft#164587

This changes the `externalFileGlobs` setting to instead be a include array of globs that should trigger link updates. I've split the globs into markdown files and image/video files

This also makes it easier for users to add their own new globs to the list

* Fix scopes
  • Loading branch information
mjbvz authored Oct 26, 2022
1 parent d2f8ae6 commit 1316bf7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
21 changes: 14 additions & 7 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,19 +544,26 @@
],
"default": "never",
"markdownDescription": "%configuration.markdown.updateLinksOnFileMove.enabled%",
"scope": "resource"
"scope": "window"
},
"markdown.updateLinksOnFileMove.externalFileGlobs": {
"type": "string",
"default": "**/*.{jpg,jpe,jpeg,png,bmp,gif,ico,webp,avif,tiff,svg,mp4}",
"description": "%configuration.markdown.updateLinksOnFileMove.fileGlobs%",
"scope": "resource"
"markdown.updateLinksOnFileMove.include": {
"type": "array",
"markdownDescription": "%configuration.markdown.updateLinksOnFileMove.include%",
"scope": "window",
"items": {
"type": "string",
"description": "%configuration.markdown.updateLinksOnFileMove.include.property%"
},
"default": [
"**/*.{md,mkd,mdwn,mdown,markdown,markdn,mdtxt,mdtext,workbook}",
"**/*.{jpg,jpe,jpeg,png,bmp,gif,ico,webp,avif,tiff,svg,mp4}"
]
},
"markdown.updateLinksOnFileMove.enableForDirectories": {
"type": "boolean",
"default": true,
"description": "%configuration.markdown.updateLinksOnFileMove.enableForDirectories%",
"scope": "resource"
"scope": "window"
},
"markdown.occurrencesHighlight.enabled": {
"type": "boolean",
Expand Down
5 changes: 3 additions & 2 deletions extensions/markdown-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
"configuration.markdown.validate.ignoredLinks.description": "Configure links that should not be validated. For example adding `/about` would not validate the link `[about](/about)`, while the glob `/assets/**/*.svg` would let you skip validation for any link to `.svg` files under the `assets` directory.",
"configuration.markdown.validate.unusedLinkDefinitions.description": "Validate link definitions that are unused in the current file.",
"configuration.markdown.validate.duplicateLinkDefinitions.description": "Validate duplicated definitions in the current file.",
"configuration.markdown.updateLinksOnFileMove.enabled": "Try to update links in Markdown files when a file is renamed/moved in the workspace. Use `#markdown.updateLinksOnFileMove.externalFileGlobs#` to configure which files trigger link updates.",
"configuration.markdown.updateLinksOnFileMove.enabled": "Try to update links in Markdown files when a file is renamed/moved in the workspace. Use `#markdown.updateLinksOnFileMove.include#` to configure which files trigger link updates.",
"configuration.markdown.updateLinksOnFileMove.enabled.prompt": "Prompt on each file move.",
"configuration.markdown.updateLinksOnFileMove.enabled.always": "Always update links automatically.",
"configuration.markdown.updateLinksOnFileMove.enabled.never": "Never try to update link and don't prompt.",
"configuration.markdown.updateLinksOnFileMove.fileGlobs": "A glob that specifies which files besides markdown should trigger a link update.",
"configuration.markdown.updateLinksOnFileMove.include": "Glob patterns that specifies which files that trigger automatic link updates. See `#markdown.updateLinksOnFileMove.enabled#` for details about this feature.",
"configuration.markdown.updateLinksOnFileMove.include.property": "The glob pattern to match file paths against. Set to true or false to enable or disable the pattern.",
"configuration.markdown.updateLinksOnFileMove.enableForDirectories": "Enable/disable updating links when a directory is moved or renamed in the workspace.",
"configuration.markdown.occurrencesHighlight.enabled": "Enable/disable highlighting link occurrences in the current document.",
"workspaceTrust": "Required for loading styles configured in the workspace."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { MdLanguageClient } from '../client/client';
import { Delayer } from '../util/async';
import { noopToken } from '../util/cancellation';
import { Disposable } from '../util/dispose';
import { looksLikeMarkdownPath } from '../util/file';
import { convertRange } from './fileReferences';

const localize = nls.loadMessageBundle();

const settingNames = Object.freeze({
enabled: 'updateLinksOnFileMove.enabled',
externalFileGlobs: 'updateLinksOnFileMove.externalFileGlobs',
include: 'updateLinksOnFileMove.include',
enableForDirectories: 'updateLinksOnFileMove.enableForDirectories',
});

Expand Down Expand Up @@ -99,13 +98,13 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
return false;
}

if (looksLikeMarkdownPath(newUri)) {
return true;
}

const externalGlob = config.get<string>(settingNames.externalFileGlobs);
if (!!externalGlob && picomatch.isMatch(newUri.fsPath, externalGlob)) {
return true;
const externalGlob = config.get<string[]>(settingNames.include);
if (externalGlob) {
for (const glob of externalGlob) {
if (picomatch.isMatch(newUri.fsPath, glob)) {
return true;
}
}
}

const stat = await vscode.workspace.fs.stat(newUri);
Expand Down

0 comments on commit 1316bf7

Please sign in to comment.