Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Clear formatter error logs #36

Open
pappasam opened this issue Oct 26, 2020 · 2 comments
Open

Feature: Clear formatter error logs #36

pappasam opened this issue Oct 26, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@pappasam
Copy link

pappasam commented Oct 26, 2020

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

@iamcco iamcco added the enhancement New feature or request label Oct 27, 2020
@pappasam
Copy link
Author

Any recommendations for how to develop this effectively locally? I keep running into this error when I try to create a mon-repo with this + coc-diagnostic: https://stackoverflow.com/questions/57422458/error-ts6059-file-is-not-under-rootdir-rootdir-is-expected-to-contain-al

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) {

@iamcco
Copy link
Owner

iamcco commented Nov 2, 2020

logger.warn(stderr) only output to log channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants