Finalize markdown link updating on file move (#163378)

Fixes #148146
This commit is contained in:
Matt Bierner 2022-10-11 17:42:10 -07:00 committed by GitHub
parent 6cf68a1f23
commit e1a373defd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 27 deletions

View file

@ -516,7 +516,7 @@
"error"
]
},
"markdown.experimental.updateLinksOnFileMove.enabled": {
"markdown.updateLinksOnFileMove.enabled": {
"type": "string",
"enum": [
"prompt",
@ -524,30 +524,30 @@
"never"
],
"markdownEnumDescriptions": [
"%configuration.markdown.experimental.updateLinksOnFileMove.enabled.prompt%",
"%configuration.markdown.experimental.updateLinksOnFileMove.enabled.always%",
"%configuration.markdown.experimental.updateLinksOnFileMove.enabled.never%"
"%configuration.markdown.updateLinksOnFileMove.enabled.prompt%",
"%configuration.markdown.updateLinksOnFileMove.enabled.always%",
"%configuration.markdown.updateLinksOnFileMove.enabled.never%"
],
"default": "never",
"markdownDescription": "%configuration.markdown.experimental.updateLinksOnFileMove.enabled%",
"markdownDescription": "%configuration.markdown.updateLinksOnFileMove.enabled%",
"scope": "resource",
"tags": [
"experimental"
]
},
"markdown.experimental.updateLinksOnFileMove.externalFileGlobs": {
"markdown.updateLinksOnFileMove.externalFileGlobs": {
"type": "string",
"default": "**/*.{jpg,jpe,jpeg,png,bmp,gif,ico,webp,avif,tiff,svg,mp4}",
"description": "%configuration.markdown.experimental.updateLinksOnFileMove.fileGlobs%",
"description": "%configuration.markdown.updateLinksOnFileMove.fileGlobs%",
"scope": "resource",
"tags": [
"experimental"
]
},
"markdown.experimental.updateLinksOnFileMove.enableForDirectories": {
"markdown.updateLinksOnFileMove.enableForDirectories": {
"type": "boolean",
"default": true,
"description": "%configuration.markdown.experimental.updateLinksOnFileMove.enableForDirectories%",
"description": "%configuration.markdown.updateLinksOnFileMove.enableForDirectories%",
"scope": "resource",
"tags": [
"experimental"

View file

@ -39,11 +39,11 @@
"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.experimental.updateLinksOnFileMove.enabled": "Try to update links in Markdown files when a file is renamed/moved in the workspace. Use `#markdown.experimental.updateLinksOnFileMove.externalFileGlobs#` to configure which files trigger link updates.",
"configuration.markdown.experimental.updateLinksOnFileMove.enabled.prompt": "Prompt on each file move.",
"configuration.markdown.experimental.updateLinksOnFileMove.enabled.always": "Always update links automatically.",
"configuration.markdown.experimental.updateLinksOnFileMove.enabled.never": "Never try to update link and don't prompt.",
"configuration.markdown.experimental.updateLinksOnFileMove.fileGlobs": "A glob that specifies which files besides markdown should trigger a link update.",
"configuration.markdown.experimental.updateLinksOnFileMove.enableForDirectories": "enable/disable updating links when a directory is moved or renamed in the workspace.",
"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.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.enableForDirectories": "enable/disable updating links when a directory is moved or renamed in the workspace.",
"workspaceTrust": "Required for loading styles configured in the workspace."
}

View file

@ -18,9 +18,9 @@ import { convertRange } from './fileReferences';
const localize = nls.loadMessageBundle();
const settingNames = Object.freeze({
enabled: 'experimental.updateLinksOnFileMove.enabled',
externalFileGlobs: 'experimental.updateLinksOnFileMove.externalFileGlobs',
enableForDirectories: 'experimental.updateLinksOnFileMove.enableForDirectories',
enabled: 'updateLinksOnFileMove.enabled',
externalFileGlobs: 'updateLinksOnFileMove.externalFileGlobs',
enableForDirectories: 'updateLinksOnFileMove.enableForDirectories',
});
const enum UpdateLinksOnFileMoveSetting {
@ -45,14 +45,11 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
super();
this._register(vscode.workspace.onDidRenameFiles(async (e) => {
for (const { newUri, oldUri } of e.files) {
const config = vscode.workspace.getConfiguration('markdown', newUri);
if (!await this.shouldParticipateInLinkUpdate(config, newUri)) {
continue;
await Promise.all(e.files.map(async (rename) => {
if (await this.shouldParticipateInLinkUpdate(rename.newUri)) {
this._pendingRenames.add(rename);
}
this._pendingRenames.add({ newUri, oldUri });
}
}));
if (this._pendingRenames.size) {
this._delayer.trigger(() => {
@ -95,7 +92,8 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
return false;
}
}
private async shouldParticipateInLinkUpdate(config: vscode.WorkspaceConfiguration, newUri: vscode.Uri): Promise<boolean> {
private async shouldParticipateInLinkUpdate(newUri: vscode.Uri): Promise<boolean> {
const config = vscode.workspace.getConfiguration('markdown', newUri);
const setting = config.get<UpdateLinksOnFileMoveSetting>(settingNames.enabled);
if (setting === UpdateLinksOnFileMoveSetting.Never) {
return false;
@ -230,6 +228,6 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
}
}
export function registerUpdateLinksOnRename(client: MdLanguageClient) {
export function registerUpdateLinksOnRename(client: MdLanguageClient): vscode.Disposable {
return new UpdateLinksOnFileRenameHandler(client);
}