Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework markdown update link glob #164766

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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