Skip to content

Commit d0a7299

Browse files
authored
Update to Prettier 3 (#909)
- Prettier 3 is async, so related functions were made async. - Code was reformatted using Prettier. - Prettier now ships their own types, so `@types/prettier` was removed. - Prettier was moved to `dependencies`. `optionalDependencies` is for dependencies that have a `install` script that may fail. This isn’t the case for Prettier. - `eslint-config-prettier` was updated as well. - `eslint-plugin-prettier` was updated as well.
1 parent 379bdfa commit d0a7299

15 files changed

Lines changed: 93 additions & 54 deletions

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
"type": "git",
3030
"url": "https://github.com/redhat-developer/yaml-language-server.git"
3131
},
32-
"optionalDependencies": {
33-
"prettier": "2.8.7"
34-
},
3532
"dependencies": {
3633
"ajv": "^8.11.0",
3734
"lodash": "4.17.21",
35+
"prettier": "^3.0.0",
3836
"request-light": "^0.5.7",
3937
"vscode-json-languageservice": "4.1.8",
4038
"vscode-languageserver": "^9.0.0",
@@ -49,17 +47,16 @@
4947
"@types/chai": "^4.2.12",
5048
"@types/mocha": "8.2.2",
5149
"@types/node": "16.x",
52-
"@types/prettier": "2.7.2",
5350
"@types/sinon": "^9.0.5",
5451
"@types/sinon-chai": "^3.2.5",
5552
"@typescript-eslint/eslint-plugin": "^5.38.0",
5653
"@typescript-eslint/parser": "^5.38.0",
5754
"chai": "^4.2.0",
5855
"coveralls": "3.1.1",
5956
"eslint": "^8.24.0",
60-
"eslint-config-prettier": "^8.5.0",
57+
"eslint-config-prettier": "^9.0.0",
6158
"eslint-plugin-import": "^2.26.0",
62-
"eslint-plugin-prettier": "^4.2.1",
59+
"eslint-plugin-prettier": "^5.0.0",
6360
"http-proxy-agent": "^5.0.0",
6461
"https-proxy-agent": "^5.0.0",
6562
"mocha": "9.2.2",

src/languageserver/handlers/languageHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class LanguageHandlers {
114114
* Called when the formatter is invoked
115115
* Returns the formatted document content using prettier
116116
*/
117-
formatterHandler(formatParams: DocumentFormattingParams): TextEdit[] {
117+
formatterHandler(formatParams: DocumentFormattingParams): Promise<TextEdit[]> {
118118
const document = this.yamlSettings.documents.get(formatParams.textDocument.uri);
119119

120120
if (!document) {

src/languageserver/handlers/requestHandlers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import { SchemaModificationNotification } from '../../requestTypes';
1414

1515
export class RequestHandlers {
1616
private languageService: LanguageService;
17-
constructor(private readonly connection: Connection, languageService: LanguageService) {
17+
constructor(
18+
private readonly connection: Connection,
19+
languageService: LanguageService
20+
) {
1821
this.languageService = languageService;
1922
}
2023

src/languageserver/handlers/validationHandlers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export class ValidationHandler {
1414
private languageService: LanguageService;
1515
private yamlSettings: SettingsState;
1616

17-
constructor(private readonly connection: Connection, languageService: LanguageService, yamlSettings: SettingsState) {
17+
constructor(
18+
private readonly connection: Connection,
19+
languageService: LanguageService,
20+
yamlSettings: SettingsState
21+
) {
1822
this.languageService = languageService;
1923
this.yamlSettings = yamlSettings;
2024

src/languageserver/handlers/workspaceHandlers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { ExecuteCommandParams, Connection } from 'vscode-languageserver';
77
import { CommandExecutor } from '../commandExecutor';
88

99
export class WorkspaceHandlers {
10-
constructor(private readonly connection: Connection, private readonly commandExecutor: CommandExecutor) {}
10+
constructor(
11+
private readonly connection: Connection,
12+
private readonly commandExecutor: CommandExecutor
13+
) {}
1114

1215
registerHandlers(): void {
1316
this.connection.onExecuteCommand((params) => this.executeCommand(params));

src/languageservice/parser/jsonParser07.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ export interface ISchemaCollector {
286286

287287
class SchemaCollector implements ISchemaCollector {
288288
schemas: IApplicableSchema[] = [];
289-
constructor(private focusOffset = -1, private exclude: ASTNode = null) {}
289+
constructor(
290+
private focusOffset = -1,
291+
private exclude: ASTNode = null
292+
) {}
290293
add(schema: IApplicableSchema): void {
291294
this.schemas.push(schema);
292295
}

src/languageservice/services/documentSymbols.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import { convertErrorToTelemetryMsg } from '../utils/objects';
1717
export class YAMLDocumentSymbols {
1818
private jsonDocumentSymbols;
1919

20-
constructor(schemaService: YAMLSchemaService, private readonly telemetry?: Telemetry) {
20+
constructor(
21+
schemaService: YAMLSchemaService,
22+
private readonly telemetry?: Telemetry
23+
) {
2124
this.jsonDocumentSymbols = new JSONDocumentSymbols(schemaService);
2225

2326
// override 'getKeyLabel' to handle complex mapping

src/languageservice/services/yamlCodeLens.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { convertErrorToTelemetryMsg } from '../utils/objects';
1515
import { getSchemaTitle } from '../utils/schemaUtils';
1616

1717
export class YamlCodeLens {
18-
constructor(private schemaService: YAMLSchemaService, private readonly telemetry?: Telemetry) {}
18+
constructor(
19+
private schemaService: YAMLSchemaService,
20+
private readonly telemetry?: Telemetry
21+
) {}
1922

2023
async getCodeLens(document: TextDocument): Promise<CodeLens[]> {
2124
const result = [];

src/languageservice/services/yamlFormatter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import { Range, Position, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
88
import { CustomFormatterOptions, LanguageSettings } from '../yamlLanguageService';
9-
import * as prettier from 'prettier';
10-
import { Options } from 'prettier';
11-
import * as parser from 'prettier/parser-yaml';
9+
import { format, Options } from 'prettier';
10+
import * as parser from 'prettier/plugins/yaml';
1211
import { TextDocument } from 'vscode-languageserver-textdocument';
1312

1413
export class YAMLFormatter {
@@ -20,7 +19,10 @@ export class YAMLFormatter {
2019
}
2120
}
2221

23-
public format(document: TextDocument, options: Partial<FormattingOptions> & CustomFormatterOptions = {}): TextEdit[] {
22+
public async format(
23+
document: TextDocument,
24+
options: Partial<FormattingOptions> & CustomFormatterOptions = {}
25+
): Promise<TextEdit[]> {
2426
if (!this.formatterEnabled) {
2527
return [];
2628
}
@@ -43,7 +45,7 @@ export class YAMLFormatter {
4345
printWidth: options.printWidth,
4446
};
4547

46-
const formatted = prettier.format(text, prettierOptions);
48+
const formatted = await format(text, prettierOptions);
4749

4850
return [TextEdit.replace(Range.create(Position.create(0, 0), document.positionAt(text.length)), formatted)];
4951
} catch (error) {

src/languageservice/services/yamlHover.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export class YAMLHover {
2626
private indentation: string;
2727
private schemaService: YAMLSchemaService;
2828

29-
constructor(schemaService: YAMLSchemaService, private readonly telemetry?: Telemetry) {
29+
constructor(
30+
schemaService: YAMLSchemaService,
31+
private readonly telemetry?: Telemetry
32+
) {
3033
this.shouldHover = true;
3134
this.schemaService = schemaService;
3235
}

0 commit comments

Comments
 (0)