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

Finalize markdown link updating on file move #163378

Merged
merged 1 commit into from
Oct 12, 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
18 changes: 9 additions & 9 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -516,38 +516,38 @@
"error"
]
},
"markdown.experimental.updateLinksOnFileMove.enabled": {
"markdown.updateLinksOnFileMove.enabled": {
"type": "string",
"enum": [
"prompt",
"always",
"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"
Expand Down
12 changes: 6 additions & 6 deletions extensions/markdown-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -230,6 +228,6 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
}
}

export function registerUpdateLinksOnRename(client: MdLanguageClient) {
export function registerUpdateLinksOnRename(client: MdLanguageClient): vscode.Disposable {
return new UpdateLinksOnFileRenameHandler(client);
}