You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code formatters can fail when the code they're formatting is not valid. For example, "black" fails on invalid Python. It would be great if there were a feature that saved formatter errors for pretty display to the end user; it seems like these error messages are discarded at present (see #11)
I've implemented my own Vim formatter plugin a while ago that provides a version of this, but I'd like to migrate to your general language server for formatting if possible. The error logging feature is an extremely nice to have, so I'm opening this issue in case anyone has the time / inclination to implement something helpful (custom action show stderr on failed formatters, etc). I think formatter debugging capabilities is a fundamental part of a tool that provides code formatting.
My hunch is that something like this could be a simple path forward for now. If you're able to test more-easily than me, might be worth giving this a try:
diff --git a/src/handles/handleFormat.ts b/src/handles/handleFormat.ts
index 376a05c..a1841f5 100644
--- a/src/handles/handleFormat.ts
+++ b/src/handles/handleFormat.ts
@@ -3,6 +3,7 @@ import { TextEdit, TextDocument, CancellationToken, Range, Position } from 'vsco
import { URI } from 'vscode-uri';
import { IFormatterConfig } from '../common/types';
+import logger from '../common/logger';
import { findWorkDirectory, findCommand, executeFile, checkAnyFileExists } from '../common/util';
import HunkStream from '../common/hunkStream';
@@ -49,6 +50,9 @@ async function handleFormat(
let output = '';
if (code > 0) {
output = text
+ if (stderr) {
+ logger.warn(stderr)
+ }
} else if (config.doesWriteToFile) {
output = fs.readFileSync(URI.parse(textDocument.uri).fsPath, 'utf8')
} else if (isStdout === undefined && isStderr === undefined) {
Code formatters can fail when the code they're formatting is not valid. For example, "black" fails on invalid Python. It would be great if there were a feature that saved formatter errors for pretty display to the end user; it seems like these error messages are discarded at present (see #11)
I've implemented my own Vim formatter plugin a while ago that provides a version of this, but I'd like to migrate to your general language server for formatting if possible. The error logging feature is an extremely nice to have, so I'm opening this issue in case anyone has the time / inclination to implement something helpful (custom action show stderr on failed formatters, etc). I think formatter debugging capabilities is a fundamental part of a tool that provides code formatting.
Reference: https://github.com/pappasam/vim-filetype-formatter/blob/845aaa95dc00efa20a9aa2c8615a47bbd4bf50f7/doc/filetype_formatter.txt#L128
The text was updated successfully, but these errors were encountered: