nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: elm-tooling/elm-language-server
Pull request #1175 (2024-02-17 19:47:38)

Fix Add missing case branches action adding missing branches outside of parenthesis
Currently if you have the following:
```elm
func a =
    (case a of
        1 ->
            ""
        
    )
        |> Debug.log "test"
```

And then use the `Add missing case branches` action, the result is:

```elm
func a =
    (case a of
        1 ->
            ""
        
    )

        _ ->
            Debug.todo "branch '_' not implemented"
        |> Debug.log "test"
```

The following changes fixes that by since the case_of_expr's endPosition includes the ending ) we instead try to find the last case_of_branch, and take its position as the insert position.


razzeee: Thank you

Patch:
diff --git a/src/common/providers/codeAction/addMissingCaseBranchesCodeAction.ts b/src/common/providers/codeAction/addMissingCaseBranchesCodeAction.ts
index 75a6a30..606426f 100644
--- a/src/common/providers/codeAction/addMissingCaseBranchesCodeAction.ts
+++ b/src/common/providers/codeAction/addMissingCaseBranchesCodeAction.ts
@@ -65,11 +65,16 @@ function getEdits(params: ICodeActionParams, range: Range): TextEdit[] {
       "",
     );
 
+    // case_of_expr might be wrapped in parenthesis, those are included in the case_of_expr's endPosition
+    // So we try to get the last case_of_branch's endPosition if it exists
+    // Otherwise we just fallback to taking the case_of_expr's end position
+    const insertPosition =
+      nodeAtPosition.children.filter((x) => x.type == "case_of_branch").at(-1)
+        ?.endPosition ?? nodeAtPosition.endPosition;
+
     return [
       TextEdit.insert(
-        PositionUtil.FROM_TS_POSITION(
-          nodeAtPosition.endPosition,
-        ).toVSPosition(),
+        PositionUtil.FROM_TS_POSITION(insertPosition).toVSPosition(),
         edit,
       ),
     ];


Test patch:
diff --git a/test/codeActionTests/addMissingCaseBranches.test.ts b/test/codeActionTests/addMissingCaseBranches.test.ts
index 79734dd..d47040c 100644
--- a/test/codeActionTests/addMissingCaseBranches.test.ts
+++ b/test/codeActionTests/addMissingCaseBranches.test.ts
@@ -92,4 +92,40 @@ func a b =
       expectedSource,
     );
   });
+
+  it("should add missing cases inside of ()", async () => {
+    const source = `
+    --@ Test.elm
+module Test exposing (..)
+
+func a =
+    (case a of
+    --^
+        1 ->
+            ""
+    )
+        |> Debug.log "test"
+`;
+
+    const expectedSource = `
+--@ Test.elm
+module Test exposing (..)
+
+func a =
+    (case a of
+        1 ->
+            ""
+
+        _ ->
+            Debug.todo "branch '_' not implemented"
+    )
+        |> Debug.log "test"
+`;
+
+    await testCodeAction(
+      source,
+      [{ title: "Add missing case branches" }],
+      expectedSource,
+    );
+  });
 });
Repository: gpbl/react-day-picker
Pull request #2172 (2024-05-30 23:30:55)

fix: onNextClick, onPrevClick not being called


Patch:
diff --git a/src/components/Nav.tsx b/src/components/Nav.tsx
index 41d24695f..98f9d869c 100644
--- a/src/components/Nav.tsx
+++ b/src/components/Nav.tsx
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { MouseEventHandler } from "react";
 
 import { UI } from "../UI";
 import { useCalendar } from "../contexts/calendar";
@@ -22,11 +22,25 @@ export function Nav() {
     labels: { labelNext, labelPrevious },
     locale,
     components,
-    id
+    id,
+    onNextClick,
+    onPrevClick
   } = useProps();
 
   const calendar = useCalendar();
 
+  const handlePreviousClick = () => {
+    if (!calendar.previousMonth) return;
+    calendar.goToPreviousMonth();
+    onPrevClick?.(calendar.previousMonth);
+  };
+
+  const handleNextClick = () => {
+    if (!calendar.nextMonth) return;
+    calendar.goToNextMonth();
+    onNextClick?.(calendar.nextMonth);
+  };
+
   const Button = components?.Button ?? DefaultButton;
   const Chevron = components?.Chevron ?? DefaultChevron;
 
@@ -40,7 +54,7 @@ export function Nav() {
         disabled={calendar.previousMonth ? undefined : true}
         aria-label={labelPrevious(calendar.previousMonth, { locale })}
         aria-controls={id}
-        onClick={calendar.goToPreviousMonth}
+        onClick={handlePreviousClick}
       >
         <Chevron />
       </Button>
@@ -52,7 +66,7 @@ export function Nav() {
         disabled={calendar.nextMonth ? undefined : true}
         aria-label={labelNext(calendar.nextMonth, { locale })}
         aria-controls={id}
-        onClick={calendar.goToNextMonth}
+        onClick={handleNextClick}
       >
         <Chevron orientation="right" />
       </Button>


Test patch:
diff --git a/src/components/Nav.test.tsx b/src/components/Nav.test.tsx
new file mode 100644
index 000000000..e0a8c7c89
--- /dev/null
+++ b/src/components/Nav.test.tsx
@@ -0,0 +1,25 @@
+import React from "react";
+
+import { nextButton, previousButton } from "@/test/elements";
+import { render } from "@/test/render";
+import { user } from "@/test/user";
+
+import { Nav } from "./Nav";
+
+describe("when clicking the next button", () => {
+  test("should call the onNextClick callback", async () => {
+    const onNextClick = jest.fn();
+    render(<Nav />, { onNextClick });
+    await user.click(nextButton());
+    expect(onNextClick).toHaveBeenCalled();
+  });
+});
+
+describe("when clicking the previous button", () => {
+  test("should call the onPrevClick callback", async () => {
+    const onPrevClick = jest.fn();
+    render(<Nav />, { onPrevClick });
+    await user.click(previousButton());
+    expect(onPrevClick).toHaveBeenCalled();
+  });
+});
Repository: gpbl/react-day-picker
Pull request #2295 (2024-07-22 23:38:33)

fix: range mode not updating when selected prop changes


Patch:
diff --git a/src/selection/useRange.tsx b/src/selection/useRange.tsx
index bb2ea0ed9..592350a6e 100644
--- a/src/selection/useRange.tsx
+++ b/src/selection/useRange.tsx
@@ -36,6 +36,11 @@ export function useRange<T extends DayPickerProps>(
     }
   }, [required, selected, mode]);
 
+  // Update the selected date if the `selected` prop changes.
+  React.useEffect(() => {
+    setSelected(initiallySelected);
+  }, [initiallySelected]);
+
   const isSelected = (date: Date) =>
     selected && rangeIncludesDate(selected, date, false, dateLib);
 


Test patch:
diff --git a/src/selection/useRange.test.tsx b/src/selection/useRange.test.tsx
index 476b20f5a..ac6679185 100644
--- a/src/selection/useRange.test.tsx
+++ b/src/selection/useRange.test.tsx
@@ -1,4 +1,6 @@
 /* eslint-disable @typescript-eslint/no-explicit-any */
+import { DateRange, DayPickerProps } from "react-day-picker/types";
+
 import { act, renderHook } from "@/test/render";
 
 import { dateLib } from "../lib";
@@ -21,6 +23,31 @@ describe("useRange", () => {
     expect(result.current.selected).toEqual(initiallySelected);
   });
 
+  test("update the selected range when the initially selected value changes", () => {
+    const initiallySelected: DateRange = {
+      from: new Date(2023, 6, 1),
+      to: new Date(2023, 6, 5)
+    };
+    const { result, rerender } = renderHook(
+      (props) => useRange(props, dateLib),
+      {
+        initialProps: {
+          mode: "range",
+          selected: initiallySelected,
+          required: false
+        } as DayPickerProps
+      }
+    );
+
+    rerender({
+      mode: "range",
+      selected: undefined,
+      required: false
+    });
+
+    expect(result.current.selected).toEqual(undefined);
+  });
+
   test("update the selected range on select", () => {
     const initiallySelected = {
       from: new Date(2023, 6, 1),