Skip to content

Commit

Permalink
Use FormatDocumentProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Willis committed Nov 17, 2024
1 parent d22b18d commit 3556933
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
1 change: 0 additions & 1 deletion Src/CSharpier.VSCode/src/DiagnosticsService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as vscode from "vscode";
import { Difference, generateDifferences, showInvisibles } from "prettier-linter-helpers";
import { FixAllCodeActionsCommand } from "./FixAllCodeActionCommand";
import { CSharpierProcessProvider } from "./CSharpierProcessProvider";
import { Logger } from "./Logger";
import { FormatDocumentProvider } from "./FormatDocumentProvider";

Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.VSCode/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const initPlugin = async (context: ExtensionContext) => {
const fixAllCodeActionProvider = new FixAllCodeActionProvider(diagnosticsDocumentSelector);

new FormattingService(formatDocumentProvider);
new FixAllCodeActionsCommand(context, csharpierProcessProvider, logger);
new FixAllCodeActionsCommand(context, formatDocumentProvider, logger);

context.subscriptions.push(
csharpierProcessProvider,
Expand Down
20 changes: 3 additions & 17 deletions Src/CSharpier.VSCode/src/FixAllCodeActionCommand.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as vscode from "vscode";
import { CSharpierProcessProvider } from "./CSharpierProcessProvider";
import { Logger } from "./Logger";
import { FormatDocumentProvider } from "./FormatDocumentProvider";

export class FixAllCodeActionsCommand {
public static readonly Id = "csharpier-vscode.fixAllCodeActions";
public readonly id = FixAllCodeActionsCommand.Id;

constructor(
private readonly context: vscode.ExtensionContext,
private readonly csharpierProcessProvider: CSharpierProcessProvider,
private readonly formatDocumentProvider: FormatDocumentProvider,
private readonly logger: Logger,
) {
this.context.subscriptions.push(vscode.commands.registerCommand(this.id, this.execute));
Expand All @@ -33,21 +33,7 @@ export class FixAllCodeActionsCommand {
};

private async getChanges(document: vscode.TextDocument): Promise<string | null> {
let formattedSource = "";
const source = document.getText();
const csharpierProcess = this.csharpierProcessProvider.getProcessFor(document.fileName);
if ("formatFile2" in csharpierProcess) {
const parameter = {
fileContents: source,
fileName: document.fileName,
};
const result = await csharpierProcess.formatFile2(parameter);
if (result) {
formattedSource = result.formattedFile;
}
} else {
formattedSource = await csharpierProcess.formatFile(source, document.fileName);
}
const formattedSource = (await this.formatDocumentProvider.formatDocument(document)) ?? "";
return formattedSource;
}
}
3 changes: 0 additions & 3 deletions Src/CSharpier.VSCode/src/FormattingService.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { performance } from "perf_hooks";
import {
CancellationToken,
Diagnostic,
FormattingOptions,
languages,
Position,
Range,
TextDocument,
TextEdit,
WorkspaceEdit,
} from "vscode";
import { Difference, generateDifferences } from "prettier-linter-helpers";
import { FormatDocumentProvider } from "./FormatDocumentProvider";
Expand Down

0 comments on commit 3556933

Please sign in to comment.