Skip to content

clang-format integration returns an error when formatting an empty buffer #102

@malcolmr

Description

@malcolmr

e.g.

$ vim empty.cc
:FormatCode
Error formatting file: ERROR(ShellError): Error running: /usr/bin/clang-format -style file -assume-filename /home/malcolmr/empty.cc -lines 1:1 -cursor -2
clang-format: for the -cursor option: '-2' value invalid for uint argument!

Oddly, insert and remove a blank line in the buffer (which I think means that the buffer now contains a single empty line rather than 'no lines'), and you'll instead get:

Unable to parse clang-format cursor pos: Vim(let):E684: List index out of range: 0

From the looks of the logs, this last is because we run clang-format ... --cursor 0 successfully, but clang-format doesn't print out the new cursor location for empty inputs:

$ echo -n | clang-format -cursor 0
$ echo | clang-format -cursor 0
{ "Cursor": 0, "IncompleteFormat": false }

$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions