diff --git a/.vscodeignore b/.vscodeignore index b030a4e1..9e55a3c8 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -21,6 +21,3 @@ CONTRIBUTING.md **/**.vsix **/**.tar.gz test-resources -!node_modules/prettier/index.js -!node_modules/prettier/third-party.js -!node_modules/prettier/parser-yaml.js diff --git a/smoke-test/smoke.test.ts b/smoke-test/smoke.test.ts index 5a2ed3b1..21f836d3 100644 --- a/smoke-test/smoke.test.ts +++ b/smoke-test/smoke.test.ts @@ -10,9 +10,11 @@ suite('Smoke test suite', function () { const SCHEMA_INSTANCE_NAME = 'references-schema.yaml'; const THROUGH_SETTINGS_NAME = 'references-schema-settings.yaml'; + const UNFORMATTED_NAME = 'unformatted.yaml'; let schemaInstanceUri: URI; let throughSettingsUri: URI; + let unformattedUri: URI; this.beforeAll(async function () { const workspaceUri = vscode.workspace.workspaceFolders[0].uri; @@ -22,6 +24,9 @@ suite('Smoke test suite', function () { throughSettingsUri = workspaceUri.with({ path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + THROUGH_SETTINGS_NAME, }); + unformattedUri = workspaceUri.with({ + path: workspaceUri.path + (workspaceUri.path.endsWith('/') ? '' : '/') + UNFORMATTED_NAME, + }); }); test('instance has right diagnostics', async function () { @@ -43,4 +48,28 @@ suite('Smoke test suite', function () { assert.strictEqual(diagnostics.length, 1); assert.strictEqual(diagnostics[0].message, 'Value is below the minimum of 0.'); }); + + test('has right formatting', async function () { + const textDocument = await vscode.workspace.openTextDocument(unformattedUri); + await vscode.window.showTextDocument(textDocument); + + // heavily borrowed from prettier's test suite + const edits = await vscode.commands.executeCommand( + 'vscode.executeFormatDocumentProvider', + textDocument.uri, + { tabSize: 2, insertSpaces: true } + ); + + if (edits && edits.length > 0) { + const workspaceEdit = new vscode.WorkspaceEdit(); + workspaceEdit.set(textDocument.uri, edits); + await vscode.workspace.applyEdit(workspaceEdit); + } + + const EXPECTED = `aaa: + bbb: hjkl +`; + + assert.strictEqual(textDocument.getText(), EXPECTED); + }); }); diff --git a/smoke-test/unformatted.yaml b/smoke-test/unformatted.yaml new file mode 100644 index 00000000..2630ac88 --- /dev/null +++ b/smoke-test/unformatted.yaml @@ -0,0 +1,2 @@ +aaa: + bbb: hjkl diff --git a/webpack.config.js b/webpack.config.js index 1326b0d4..45b36661 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -31,7 +31,6 @@ const config = { devtool: 'source-map', externals: { 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/ - prettier: 'commonjs prettier', }, resolve: { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader @@ -136,7 +135,6 @@ const serverWeb = { mainFields: ['browser', 'module', 'main'], extensions: ['.ts', '.js'], // support ts-files and js-files alias: { - './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. 'vscode-json-languageservice/lib/umd': 'vscode-json-languageservice/lib/esm', }, fallback: {