Skip to content

Commit 1316bf7

Browse files
authored
Rework markdown update link glob (microsoft#164766)
* 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
1 parent d2f8ae6 commit 1316bf7

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

extensions/markdown-language-features/package.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,26 @@
544544
],
545545
"default": "never",
546546
"markdownDescription": "%configuration.markdown.updateLinksOnFileMove.enabled%",
547-
"scope": "resource"
547+
"scope": "window"
548548
},
549-
"markdown.updateLinksOnFileMove.externalFileGlobs": {
550-
"type": "string",
551-
"default": "**/*.{jpg,jpe,jpeg,png,bmp,gif,ico,webp,avif,tiff,svg,mp4}",
552-
"description": "%configuration.markdown.updateLinksOnFileMove.fileGlobs%",
553-
"scope": "resource"
549+
"markdown.updateLinksOnFileMove.include": {
550+
"type": "array",
551+
"markdownDescription": "%configuration.markdown.updateLinksOnFileMove.include%",
552+
"scope": "window",
553+
"items": {
554+
"type": "string",
555+
"description": "%configuration.markdown.updateLinksOnFileMove.include.property%"
556+
},
557+
"default": [
558+
"**/*.{md,mkd,mdwn,mdown,markdown,markdn,mdtxt,mdtext,workbook}",
559+
"**/*.{jpg,jpe,jpeg,png,bmp,gif,ico,webp,avif,tiff,svg,mp4}"
560+
]
554561
},
555562
"markdown.updateLinksOnFileMove.enableForDirectories": {
556563
"type": "boolean",
557564
"default": true,
558565
"description": "%configuration.markdown.updateLinksOnFileMove.enableForDirectories%",
559-
"scope": "resource"
566+
"scope": "window"
560567
},
561568
"markdown.occurrencesHighlight.enabled": {
562569
"type": "boolean",

extensions/markdown-language-features/package.nls.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
"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.",
4242
"configuration.markdown.validate.unusedLinkDefinitions.description": "Validate link definitions that are unused in the current file.",
4343
"configuration.markdown.validate.duplicateLinkDefinitions.description": "Validate duplicated definitions in the current file.",
44-
"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.",
44+
"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.",
4545
"configuration.markdown.updateLinksOnFileMove.enabled.prompt": "Prompt on each file move.",
4646
"configuration.markdown.updateLinksOnFileMove.enabled.always": "Always update links automatically.",
4747
"configuration.markdown.updateLinksOnFileMove.enabled.never": "Never try to update link and don't prompt.",
48-
"configuration.markdown.updateLinksOnFileMove.fileGlobs": "A glob that specifies which files besides markdown should trigger a link update.",
48+
"configuration.markdown.updateLinksOnFileMove.include": "Glob patterns that specifies which files that trigger automatic link updates. See `#markdown.updateLinksOnFileMove.enabled#` for details about this feature.",
49+
"configuration.markdown.updateLinksOnFileMove.include.property": "The glob pattern to match file paths against. Set to true or false to enable or disable the pattern.",
4950
"configuration.markdown.updateLinksOnFileMove.enableForDirectories": "Enable/disable updating links when a directory is moved or renamed in the workspace.",
5051
"configuration.markdown.occurrencesHighlight.enabled": "Enable/disable highlighting link occurrences in the current document.",
5152
"workspaceTrust": "Required for loading styles configured in the workspace."

extensions/markdown-language-features/src/languageFeatures/linkUpdater.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import { MdLanguageClient } from '../client/client';
1212
import { Delayer } from '../util/async';
1313
import { noopToken } from '../util/cancellation';
1414
import { Disposable } from '../util/dispose';
15-
import { looksLikeMarkdownPath } from '../util/file';
1615
import { convertRange } from './fileReferences';
1716

1817
const localize = nls.loadMessageBundle();
1918

2019
const settingNames = Object.freeze({
2120
enabled: 'updateLinksOnFileMove.enabled',
22-
externalFileGlobs: 'updateLinksOnFileMove.externalFileGlobs',
21+
include: 'updateLinksOnFileMove.include',
2322
enableForDirectories: 'updateLinksOnFileMove.enableForDirectories',
2423
});
2524

@@ -99,13 +98,13 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
9998
return false;
10099
}
101100

102-
if (looksLikeMarkdownPath(newUri)) {
103-
return true;
104-
}
105-
106-
const externalGlob = config.get<string>(settingNames.externalFileGlobs);
107-
if (!!externalGlob && picomatch.isMatch(newUri.fsPath, externalGlob)) {
108-
return true;
101+
const externalGlob = config.get<string[]>(settingNames.include);
102+
if (externalGlob) {
103+
for (const glob of externalGlob) {
104+
if (picomatch.isMatch(newUri.fsPath, glob)) {
105+
return true;
106+
}
107+
}
109108
}
110109

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

0 commit comments

Comments
 (0)