mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Rework markdown update link glob (#164766)
* Rework markdown update link glob Fixes #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
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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',
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user