Skip to content

buf beta lsp formatting duplicates leading comments in file #3423

@stefanvanburen

Description

@stefanvanburen

GitHub repository with your minimal reproducible example (do not fill out this field with "github.com/bufbuild/buf" or we will automatically close your issue, see the instructions above!)

https://github.com/stefanvanburen/buf-repros

Commands

cd ./lsp-duplicate-leading-comments
nvim test.proto
# format the file with the LSP

Output

Results in a duplicate leading comment, diff:

diff --git a/lsp-duplicate-leading-comments/test.proto b/lsp-duplicate-leading-comments/test.proto
index f383f8e..8e97aa1 100644
--- a/lsp-duplicate-leading-comments/test.proto
+++ b/lsp-duplicate-leading-comments/test.proto
@@ -1,4 +1,5 @@
 // Leading comment.
+// Leading comment.
 syntax = "proto3";
 
 package TODO;

Expected Output

No diff.

Anything else?

The issue seems to lie in using the fileNode in the range returned in the TextEdit; the AST doesn't count the leading comments when calculating NodeInfo.Start(), while the formatter touches the entire file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions