Skip to content

Commit 6dc8906

Browse files
committed
Adjust to switch of formatter implementation from prettier to yaml
We switched the formatter implementation of yaml-language-server to be based on eemeli/yaml instead of prettier, since it can provide all the same functionality, and avoiding the extra dependency on prettier reduces the total size of the language server. Using prettier to provide formatting support was also a blocker for getting the formatting to work in the web version of the extension, since prettier doesn't work well with bundlers. This PR removes the shim that changed formatting on web to a NO-OP, since we should now be able to format properly on web. Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 64c5308 commit 6dc8906

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

.vscodeignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ CONTRIBUTING.md
2121
**/**.vsix
2222
**/**.tar.gz
2323
test-resources
24-
!node_modules/prettier/index.js
25-
!node_modules/prettier/third-party.js
26-
!node_modules/prettier/parser-yaml.js

smoke-test/smoke.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ suite('Smoke test suite', function () {
1010

1111
const SCHEMA_INSTANCE_NAME = 'references-schema.yaml';
1212
const THROUGH_SETTINGS_NAME = 'references-schema-settings.yaml';
13+
const UNFORMATTED_NAME = 'unformatted.yaml';
1314

1415
let schemaInstanceUri: URI;
1516
let throughSettingsUri: URI;
17+
let unformattedUri: URI;
1618

1719
this.beforeAll(async function () {
1820
const workspaceUri = vscode.workspace.workspaceFolders[0].uri;
@@ -22,6 +24,9 @@ suite('Smoke test suite', function () {
2224
throughSettingsUri = workspaceUri.with({
2325
path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + THROUGH_SETTINGS_NAME,
2426
});
27+
unformattedUri = workspaceUri.with({
28+
path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + UNFORMATTED_NAME,
29+
});
2530
});
2631

2732
test('instance has right diagnostics', async function () {
@@ -43,4 +48,28 @@ suite('Smoke test suite', function () {
4348
assert.strictEqual(diagnostics.length, 1);
4449
assert.strictEqual(diagnostics[0].message, 'Value is below the minimum of 0.');
4550
});
51+
52+
test('has right formatting', async function () {
53+
const textDocument = await vscode.workspace.openTextDocument(unformattedUri);
54+
await vscode.window.showTextDocument(textDocument);
55+
56+
// heavily borrowed from prettier's test suite
57+
const edits = await vscode.commands.executeCommand<vscode.TextEdit[]>(
58+
'vscode.executeFormatDocumentProvider',
59+
textDocument.uri,
60+
{ tabSize: 2, insertSpaces: true }
61+
);
62+
63+
if (edits && edits.length > 0) {
64+
const workspaceEdit = new vscode.WorkspaceEdit();
65+
workspaceEdit.set(textDocument.uri, edits);
66+
await vscode.workspace.applyEdit(workspaceEdit);
67+
}
68+
69+
const EXPECTED = `aaa:
70+
bbb: hjkl
71+
`;
72+
73+
assert.strictEqual(textDocument.getText(), EXPECTED);
74+
});
4675
});

smoke-test/unformatted.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
aaa:
2+
bbb: hjkl

webpack.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const config = {
3131
devtool: 'source-map',
3232
externals: {
3333
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
34-
prettier: 'commonjs prettier',
3534
},
3635
resolve: {
3736
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
@@ -136,7 +135,6 @@ const serverWeb = {
136135
mainFields: ['browser', 'module', 'main'],
137136
extensions: ['.ts', '.js'], // support ts-files and js-files
138137
alias: {
139-
'./services/yamlFormatter': path.resolve(__dirname, './build/polyfills/yamlFormatter.js'), // not supported for now. prettier can run in the web, but it's a bit more work.
140138
'vscode-json-languageservice/lib/umd': 'vscode-json-languageservice/lib/esm',
141139
},
142140
fallback: {

0 commit comments

Comments
 (0)