From 0ef903db49ffcb30a9c39199d48ff4c4403de6b5 Mon Sep 17 00:00:00 2001 From: Umidbek Karimov <4734297+umidbekk@users.noreply.github.com> Date: Wed, 12 Jan 2022 11:33:44 +0200 Subject: [PATCH] feat: Use `vscode-languageserver-protocol` to verify params passed to the `@prisma/prisma-fmt-wasm`. --- lib/plugin.js | 12 ++++++++---- package-lock.json | 50 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 ++- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index e255803..1ba0eeb 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -30,17 +30,21 @@ module.exports = { print(path, options) { const { format } = require("@prisma/prisma-fmt-wasm"); const { text } = path.getValue(); - const params = JSON.stringify({ + /** @type {import('vscode-languageserver-protocol').DocumentFormattingParams} */ + const params = { textDocument: { - uri: new URL(`file://${options.filepath}`), + uri: new URL(`file://${options.filepath}`).toString(), }, options: { tabSize: options.tabWidth, insertSpaces: !options.useTabs, + trimFinalNewlines: true, + insertFinalNewline: true, + trimTrailingWhitespace: true, }, - }); + }; - return format(text, params); + return format(text, JSON.stringify(params)); }, }, }, diff --git a/package-lock.json b/package-lock.json index 8b1a897..a75ce65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,8 @@ "np": "7.6.0", "prettier": "2.5.1", "prettier-plugin-packagejson": "2.2.15", - "typescript": "4.5.4" + "typescript": "4.5.4", + "vscode-languageserver-protocol": "3.16.0" }, "engines": { "node": ">=12", @@ -7824,6 +7825,31 @@ "builtins": "^1.0.3" } }, + "node_modules/vscode-jsonrpc": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz", + "integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==", + "dev": true, + "engines": { + "node": ">=8.0.0 || >=10.0.0" + } + }, + "node_modules/vscode-languageserver-protocol": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz", + "integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==", + "dev": true, + "dependencies": { + "vscode-jsonrpc": "6.0.0", + "vscode-languageserver-types": "3.16.0" + } + }, + "node_modules/vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==", + "dev": true + }, "node_modules/w3c-hr-time": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz", @@ -14074,6 +14100,28 @@ "builtins": "^1.0.3" } }, + "vscode-jsonrpc": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz", + "integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==", + "dev": true + }, + "vscode-languageserver-protocol": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz", + "integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==", + "dev": true, + "requires": { + "vscode-jsonrpc": "6.0.0", + "vscode-languageserver-types": "3.16.0" + } + }, + "vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==", + "dev": true + }, "w3c-hr-time": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz", diff --git a/package.json b/package.json index 90b44ba..bfdcfb7 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "np": "7.6.0", "prettier": "2.5.1", "prettier-plugin-packagejson": "2.2.15", - "typescript": "4.5.4" + "typescript": "4.5.4", + "vscode-languageserver-protocol": "3.16.0" }, "peerDependencies": { "prettier": ">=2"