Skip to content

Commit

Permalink
Avoid returning TextEdit on empty diff (#3435)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanburen authored Oct 30, 2024
1 parent 4b587f3 commit da80689
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion private/buf/buflsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ func (s *server) Formatting(
return nil, err
}

newText := out.String()
// Avoid formatting the file if text has not changed.
if newText == file.text {
return nil, nil
}

// XXX: The current compiler does not expose a span for the full file. Instead of
// potentially undershooting the correct span (which can cause comments at the
// start and end of the file to be duplicated), we instead manually count up the
Expand All @@ -241,7 +247,7 @@ func (s *server) Formatting(
Character: uint32(lastChar),
},
},
NewText: out.String(),
NewText: newText,
},
}, nil
}
Expand Down

0 comments on commit da80689

Please sign in to comment.