Adopt prefix private with _ in markdown extension (#165088)

This commit is contained in:
Matt Bierner
2022-10-31 14:22:39 -07:00
committed by GitHub
parent b97827dacf
commit 33867c55f3
29 changed files with 374 additions and 355 deletions

View File

@@ -34,7 +34,7 @@ class PasteEditProvider implements vscode.DocumentPasteEditProvider {
for (const imageMime of supportedImageMimes) {
const file = dataTransfer.get(imageMime)?.asFile();
if (file) {
const edit = await this.makeCreateImagePasteEdit(document, file, token);
const edit = await this._makeCreateImagePasteEdit(document, file, token);
if (token.isCancellationRequested) {
return;
}
@@ -49,7 +49,7 @@ class PasteEditProvider implements vscode.DocumentPasteEditProvider {
return snippet ? new vscode.DocumentPasteEdit(snippet) : undefined;
}
private async makeCreateImagePasteEdit(document: vscode.TextDocument, file: vscode.DataTransferFile, token: vscode.CancellationToken): Promise<vscode.DocumentPasteEdit | undefined> {
private async _makeCreateImagePasteEdit(document: vscode.TextDocument, file: vscode.DataTransferFile, token: vscode.CancellationToken): Promise<vscode.DocumentPasteEdit | undefined> {
if (file.uri) {
// If file is already in workspace, we don't want to create a copy of it
const workspaceFolder = vscode.workspace.getWorkspaceFolder(file.uri);
@@ -59,7 +59,7 @@ class PasteEditProvider implements vscode.DocumentPasteEditProvider {
}
}
const uri = await this.getNewFileName(document, file);
const uri = await this._getNewFileName(document, file);
if (token.isCancellationRequested) {
return;
}
@@ -78,7 +78,7 @@ class PasteEditProvider implements vscode.DocumentPasteEditProvider {
return pasteEdit;
}
private async getNewFileName(document: vscode.TextDocument, file: vscode.DataTransferFile): Promise<vscode.Uri> {
private async _getNewFileName(document: vscode.TextDocument, file: vscode.DataTransferFile): Promise<vscode.Uri> {
const root = Utils.dirname(document.uri);
const ext = path.extname(file.name);

View File

@@ -22,14 +22,14 @@ class AddToIgnoreLinksQuickFixProvider implements vscode.CodeActionProvider {
private static readonly _addToIgnoreLinksCommandId = '_markdown.addToIgnoreLinks';
private static readonly metadata: vscode.CodeActionProviderMetadata = {
private static readonly _metadata: vscode.CodeActionProviderMetadata = {
providedCodeActionKinds: [
vscode.CodeActionKind.QuickFix
],
};
public static register(selector: vscode.DocumentSelector, commandManager: CommandManager): vscode.Disposable {
const reg = vscode.languages.registerCodeActionsProvider(selector, new AddToIgnoreLinksQuickFixProvider(), AddToIgnoreLinksQuickFixProvider.metadata);
const reg = vscode.languages.registerCodeActionsProvider(selector, new AddToIgnoreLinksQuickFixProvider(), AddToIgnoreLinksQuickFixProvider._metadata);
const commandReg = commandManager.register({
id: AddToIgnoreLinksQuickFixProvider._addToIgnoreLinksCommandId,
execute(resource: vscode.Uri, path: string) {

View File

@@ -17,7 +17,7 @@ export class FindFileReferencesCommand implements Command {
public readonly id = 'markdown.findAllFileReferences';
constructor(
private readonly client: MdLanguageClient,
private readonly _client: MdLanguageClient,
) { }
public async execute(resource?: vscode.Uri) {
@@ -31,7 +31,7 @@ export class FindFileReferencesCommand implements Command {
location: vscode.ProgressLocation.Window,
title: localize('progress.title', "Finding file references")
}, async (_progress, token) => {
const locations = (await this.client.getReferencesToFileInWorkspace(resource!, token)).map(loc => {
const locations = (await this._client.getReferencesToFileInWorkspace(resource!, token)).map(loc => {
return new vscode.Location(vscode.Uri.parse(loc.uri), convertRange(loc.range));
});

View File

@@ -39,13 +39,13 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
private readonly _pendingRenames = new Set<RenameAction>();
public constructor(
private readonly client: MdLanguageClient,
private readonly _client: MdLanguageClient,
) {
super();
this._register(vscode.workspace.onDidRenameFiles(async (e) => {
await Promise.all(e.files.map(async (rename) => {
if (await this.shouldParticipateInLinkUpdate(rename.newUri)) {
if (await this._shouldParticipateInLinkUpdate(rename.newUri)) {
this._pendingRenames.add(rename);
}
}));
@@ -55,26 +55,26 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: localize('renameProgress.title', "Checking for Markdown links to update")
}, () => this.flushRenames());
}, () => this._flushRenames());
});
}
}));
}
private async flushRenames(): Promise<void> {
private async _flushRenames(): Promise<void> {
const renames = Array.from(this._pendingRenames);
this._pendingRenames.clear();
const result = await this.getEditsForFileRename(renames, noopToken);
const result = await this._getEditsForFileRename(renames, noopToken);
if (result && result.edit.size) {
if (await this.confirmActionWithUser(result.resourcesBeingRenamed)) {
if (await this._confirmActionWithUser(result.resourcesBeingRenamed)) {
await vscode.workspace.applyEdit(result.edit);
}
}
}
private async confirmActionWithUser(newResources: readonly vscode.Uri[]): Promise<boolean> {
private async _confirmActionWithUser(newResources: readonly vscode.Uri[]): Promise<boolean> {
if (!newResources.length) {
return false;
}
@@ -83,7 +83,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
const setting = config.get<UpdateLinksOnFileMoveSetting>(settingNames.enabled);
switch (setting) {
case UpdateLinksOnFileMoveSetting.Prompt:
return this.promptUser(newResources);
return this._promptUser(newResources);
case UpdateLinksOnFileMoveSetting.Always:
return true;
case UpdateLinksOnFileMoveSetting.Never:
@@ -91,7 +91,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
return false;
}
}
private async shouldParticipateInLinkUpdate(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) {
@@ -115,7 +115,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
return false;
}
private async promptUser(newResources: readonly vscode.Uri[]): Promise<boolean> {
private async _promptUser(newResources: readonly vscode.Uri[]): Promise<boolean> {
if (!newResources.length) {
return false;
}
@@ -140,7 +140,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
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 links for the following {0} files?", newResources.length), newResources), {
: this._getConfirmMessage(localize('promptMoreThanOne', "Update Markdown links for the following {0} files?", newResources.length), newResources), {
modal: true,
}, rejectItem, acceptItem, alwaysItem, neverItem);
@@ -156,7 +156,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
config.update(
settingNames.enabled,
UpdateLinksOnFileMoveSetting.Always,
this.getConfigTargetScope(config, settingNames.enabled));
this._getConfigTargetScope(config, settingNames.enabled));
return true;
}
case neverItem: {
@@ -164,7 +164,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
config.update(
settingNames.enabled,
UpdateLinksOnFileMoveSetting.Never,
this.getConfigTargetScope(config, settingNames.enabled));
this._getConfigTargetScope(config, settingNames.enabled));
return false;
}
default: {
@@ -173,8 +173,8 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
}
}
private async getEditsForFileRename(renames: readonly RenameAction[], token: vscode.CancellationToken): Promise<{ edit: vscode.WorkspaceEdit; resourcesBeingRenamed: vscode.Uri[] } | undefined> {
const result = await this.client.getEditForFileRenames(renames.map(rename => ({ oldUri: rename.oldUri.toString(), newUri: rename.newUri.toString() })), token);
private async _getEditsForFileRename(renames: readonly RenameAction[], token: vscode.CancellationToken): Promise<{ edit: vscode.WorkspaceEdit; resourcesBeingRenamed: vscode.Uri[] } | undefined> {
const result = await this._client.getEditForFileRenames(renames.map(rename => ({ oldUri: rename.oldUri.toString(), newUri: rename.newUri.toString() })), token);
if (!result?.edit.documentChanges?.length) {
return undefined;
}
@@ -194,7 +194,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
};
}
private getConfirmMessage(start: string, resourcesToConfirm: readonly vscode.Uri[]): string {
private _getConfirmMessage(start: string, resourcesToConfirm: readonly vscode.Uri[]): string {
const MAX_CONFIRM_FILES = 10;
const paths = [start];
@@ -213,7 +213,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
return paths.join('\n');
}
private getConfigTargetScope(config: vscode.WorkspaceConfiguration, settingsName: string): vscode.ConfigurationTarget {
private _getConfigTargetScope(config: vscode.WorkspaceConfiguration, settingsName: string): vscode.ConfigurationTarget {
const inspected = config.inspect(settingsName);
if (inspected?.workspaceFolderValue) {
return vscode.ConfigurationTarget.WorkspaceFolder;