Skip to content

Commit

Permalink
feat: Use vscode-languageserver-protocol to verify params passed to…
Browse files Browse the repository at this point in the history
… the `@prisma/prisma-fmt-wasm`.
  • Loading branch information
avocadowastaken committed Jan 12, 2022
1 parent 1bac04f commit 0ef903d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
},
},
Expand Down
50 changes: 49 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0ef903d

Please sign in to comment.