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

Remove extra enums #162686

Merged
merged 1 commit into from Oct 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -123,68 +123,57 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
return false;
}

const enum Choice {
None = 0,
Accept = 1,
Reject = 2,
Always = 3,
Never = 4,
}

interface Item extends vscode.MessageItem {
readonly choice: Choice;
}

const response = await vscode.window.showInformationMessage<Item>(
newResources.length === 1
? localize('prompt', "Update Markdown links for '{0}'?", path.basename(newResources[0].fsPath))
: this.getConfirmMessage(localize('promptMoreThanOne', "Update Markdown link for the following {0} files?", newResources.length), newResources), {
modal: true,
}, {
const rejectItem: vscode.MessageItem = {
title: localize('reject.title', "No"),
choice: Choice.Reject,
isCloseAffordance: true,
}, {
};

const acceptItem: vscode.MessageItem = {
title: localize('accept.title', "Yes"),
choice: Choice.Accept,
}, {
};

const alwaysItem: vscode.MessageItem = {
title: localize('always.title', "Always automatically update Markdown Links"),
choice: Choice.Always,
}, {
};

const neverItem: vscode.MessageItem = {
title: localize('never.title', "Never automatically update Markdown Links"),
choice: Choice.Never,
});
};

if (!response) {
return false;
}
const choice = await vscode.window.showInformationMessage(
newResources.length === 1
? localize('prompt', "Update Markdown links for '{0}'?", path.basename(newResources[0].fsPath))
: this.getConfirmMessage(localize('promptMoreThanOne', "Update Markdown link for the following {0} files?", newResources.length), newResources), {
modal: true,
}, rejectItem, acceptItem, alwaysItem, neverItem);

switch (response.choice) {
case Choice.Accept: {
switch (choice) {
case acceptItem: {
return true;
}
case Choice.Reject: {
case rejectItem: {
return false;
}
case Choice.Always: {
case alwaysItem: {
const config = vscode.workspace.getConfiguration('markdown', newResources[0]);
config.update(
settingNames.enabled,
UpdateLinksOnFileMoveSetting.Always,
this.getConfigTargetScope(config, settingNames.enabled));
return true;
}
case Choice.Never: {
case neverItem: {
const config = vscode.workspace.getConfiguration('markdown', newResources[0]);
config.update(
settingNames.enabled,
UpdateLinksOnFileMoveSetting.Never,
this.getConfigTargetScope(config, settingNames.enabled));
return false;
}
default: {
return false;
}
}

return false;
}

private async getEditsForFileRename(renames: readonly RenameAction[], token: vscode.CancellationToken): Promise<{ edit: vscode.WorkspaceEdit; resourcesBeingRenamed: vscode.Uri[] } | undefined> {
Expand Down
Expand Up @@ -147,62 +147,47 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
return false;
}

const enum Choice {
None = 0,
Accept = 1,
Reject = 2,
Always = 3,
Never = 4,
}
const rejectItem: vscode.MessageItem = {
title: localize('reject.title', "No"),
isCloseAffordance: true,
};

interface Item extends vscode.MessageItem {
readonly choice: Choice;
}
const acceptItem: vscode.MessageItem = {
title: localize('accept.title', "Yes"),
};

const alwaysItem: vscode.MessageItem = {
title: localize('always.title', "Always automatically update imports"),
};

const neverItem: vscode.MessageItem = {
title: localize('never.title', "Never automatically update imports"),
};

const response = await vscode.window.showInformationMessage<Item>(
const response = await vscode.window.showInformationMessage(
newResources.length === 1
? localize('prompt', "Update imports for '{0}'?", path.basename(newResources[0].fsPath))
: this.getConfirmMessage(localize('promptMoreThanOne', "Update imports for the following {0} files?", newResources.length), newResources), {
modal: true,
}, {
title: localize('reject.title', "No"),
choice: Choice.Reject,
isCloseAffordance: true,
}, {
title: localize('accept.title', "Yes"),
choice: Choice.Accept,
}, {
title: localize('always.title', "Always automatically update imports"),
choice: Choice.Always,
}, {
title: localize('never.title', "Never automatically update imports"),
choice: Choice.Never,
});
}, rejectItem, acceptItem, alwaysItem, neverItem);

if (!response) {
return false;
}

switch (response.choice) {
case Choice.Accept:
{
return true;
}
case Choice.Reject:
{
return false;
}
case Choice.Always:
{
const config = this.getConfiguration(newResources[0]);
config.update(
updateImportsOnFileMoveName,
UpdateImportsOnFileMoveSetting.Always,
this.getConfigTargetScope(config, updateImportsOnFileMoveName));
return true;
}
case Choice.Never:
switch (response) {
case acceptItem: {
return true;
}
case rejectItem: {
return false;
}
case alwaysItem: {
const config = this.getConfiguration(newResources[0]);
config.update(
updateImportsOnFileMoveName,
UpdateImportsOnFileMoveSetting.Always,
this.getConfigTargetScope(config, updateImportsOnFileMoveName));
return true;
}
case neverItem:
{
const config = this.getConfiguration(newResources[0]);
config.update(
Expand All @@ -211,9 +196,10 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
this.getConfigTargetScope(config, updateImportsOnFileMoveName));
return false;
}
default: {
return false;
}
}

return false;
}

private async getJsTsFileBeingMoved(resource: vscode.Uri): Promise<vscode.Uri | undefined> {
Expand Down