Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hphp/hack/Makefile.dune
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build-hack$(2):
dune build \
src/hh_server.$(1) \
src/hh_client.$(1) \
src/hh_single_ide_format.$(1) \
src/hh_single_type_check.$(1) \
src/hackfmt.$(1) \
src/hh_parse.$(1) \
Expand All @@ -44,6 +45,7 @@ copy-hack$(2)-files: build-hack$(2)
mkdir -p "$(HACK_BIN_DIR)"
${COPY_EXE} "$(DUNE_BUILD_DIR)/default/hack/src/hh_server.$(1)" "$(HACK_BIN_DIR)/hh_server$(ext)"
${COPY_EXE} "$(DUNE_BUILD_DIR)/default/hack/src/hh_client.$(1)" "$(HACK_BIN_DIR)/hh_client$(ext)"
${COPY_EXE} "$(DUNE_BUILD_DIR)/default/hack/src/hh_single_ide_format.$(1)" "$(HACK_BIN_DIR)/hh_single_ide_format$(ext)"
${COPY_EXE} "$(DUNE_BUILD_DIR)/default/hack/src/hh_single_type_check.$(1)" "$(HACK_BIN_DIR)/hh_single_type_check$(ext)"
${COPY_EXE} "$(DUNE_BUILD_DIR)/default/hack/src/hackfmt.$(1)" "$(HACK_BIN_DIR)/hackfmt$(ext)"
${COPY_EXE} "$(DUNE_BUILD_DIR)/default/hack/src/hh_parse.$(1)" "$(HACK_BIN_DIR)/hh_parse$(ext)"
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/src/client/ide_service/ide_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ let minimal_edit (old_src : string) (new_src : string) :
(List.length old_src_lines - range_end_line)
in
let (new_text, start_line_adjustment) =
if List.is_empty new_src_novel_lines then
if List.is_empty new_src_novel_lines && range_end_line < List.length new_src_lines then
(*
Empty `new_src_novel_lines` does not mean that there was no change
(otherwise we wouldn't have reached here),
Expand Down
10 changes: 10 additions & 0 deletions hphp/hack/test/hackfmt/ide_format/newlines3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?hh
// Formatting an otherwise-correctly formatted file with trailing newlines
// should not devour the last line before the newlines.
class A {
public function baz(): int {
return 5;
}
}


29 changes: 29 additions & 0 deletions hphp/hack/test/hackfmt/ide_format/newlines3.php.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
> lines and columns in ranges are 1-indexed
received code:
1 <?hh
2 // Formatting an otherwise-correctly formatted file with trailing newlines
3 // should not devour the last line before the newlines.
4 class A {
5 public function baz(): int {
6 return 5;
7 }
8 }
9
10

New text at range 9:1-11:1 (1-indexed) is
'
'

Code after applying language server edits:
'<?hh
// Formatting an otherwise-correctly formatted file with trailing newlines
// should not devour the last line before the newlines.
class A {
public function baz(): int {
return 5;
}
}
'

Matched Hackfmt result