Skip to content

Commit a870cb0

Browse files
committed
PR feedback
1 parent 44918ec commit a870cb0

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

extensions/vscode/src/utils/window.test.ts

+43-16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const terminalMock = {
1717
},
1818
};
1919

20+
const cancelTokenMock = {
21+
onCancellationRequested: vi.fn(),
22+
};
23+
2024
vi.mock("vscode", () => {
2125
// mock Disposable
2226
const disposableMock = vi.fn();
@@ -28,7 +32,7 @@ vi.mock("vscode", () => {
2832
showWarningMessage: vi.fn(),
2933
showInformationMessage: vi.fn(),
3034
withProgress: vi.fn().mockImplementation((_, progressCallback) => {
31-
progressCallback();
35+
progressCallback(_, cancelTokenMock);
3236
}),
3337
createTerminal: vi.fn().mockImplementation(() => {
3438
terminalMock.sendText = vi.fn();
@@ -92,21 +96,44 @@ describe("Consumers of vscode window", () => {
9296
);
9397
});
9498

95-
test("taskWithProgressMsg", () => {
96-
const taskMock = vi.fn();
97-
taskWithProgressMsg(
98-
"Running a task with a progress notification",
99-
taskMock,
100-
);
101-
expect(window.withProgress).toHaveBeenCalledWith(
102-
{
103-
location: 15,
104-
title: "Running a task with a progress notification",
105-
cancellable: false,
106-
},
107-
expect.any(Function),
108-
);
109-
expect(taskMock).toHaveBeenCalled();
99+
describe("taskWithProgressMsg", () => {
100+
test("not cancellable", () => {
101+
const taskMock = vi.fn();
102+
taskWithProgressMsg(
103+
"Running a task with a progress notification",
104+
taskMock,
105+
);
106+
expect(window.withProgress).toHaveBeenCalledWith(
107+
{
108+
location: 15,
109+
title: "Running a task with a progress notification",
110+
cancellable: false,
111+
},
112+
expect.any(Function),
113+
);
114+
expect(taskMock).toHaveBeenCalled();
115+
expect(cancelTokenMock.onCancellationRequested).not.toHaveBeenCalled();
116+
});
117+
118+
test("cancellable", () => {
119+
const taskMock = vi.fn();
120+
taskWithProgressMsg(
121+
"Running a task with a progress notification",
122+
taskMock,
123+
() => {},
124+
);
125+
expect(window.withProgress).toHaveBeenCalledWith(
126+
{
127+
location: 15,
128+
title: "Running a task with a progress notification",
129+
cancellable: true,
130+
},
131+
expect.any(Function),
132+
);
133+
// Cancel listener is registered
134+
expect(taskMock).toHaveBeenCalled();
135+
expect(cancelTokenMock.onCancellationRequested).toHaveBeenCalled();
136+
});
110137
});
111138

112139
describe("runTerminalCommand", () => {

extensions/vscode/src/utils/window.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ export function showInformationMsg(msg: string, ...items: string[]) {
2121

2222
type taskFunc = <T>(p: Progress<T>, t: CancellationToken) => Promise<void>;
2323
const progressCallbackHandlerFactory =
24-
(
25-
task: taskFunc,
26-
cancellable: boolean = false,
27-
onCancel?: () => void,
28-
): taskFunc =>
24+
(task: taskFunc, onCancel?: () => void): taskFunc =>
2925
(progress, token) => {
30-
if (cancellable && onCancel) {
26+
if (onCancel) {
3127
token.onCancellationRequested(() => {
3228
onCancel();
3329
});
@@ -38,16 +34,15 @@ const progressCallbackHandlerFactory =
3834
export function taskWithProgressMsg(
3935
msg: string,
4036
task: taskFunc,
41-
cancellable: boolean = false,
4237
onCancel?: () => void,
4338
) {
4439
return window.withProgress(
4540
{
4641
location: ProgressLocation.Notification,
4742
title: msg,
48-
cancellable,
43+
cancellable: onCancel !== undefined,
4944
},
50-
progressCallbackHandlerFactory(task, cancellable, onCancel),
45+
progressCallbackHandlerFactory(task, onCancel),
5146
);
5247
}
5348

internal/inspect/dependencies/renv/manifest_packages.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (m *defaultPackageMapper) GetManifestPackages(
195195
lockfile, err := ReadLockfile(lockfilePath)
196196
if err != nil {
197197
if errors.Is(err, os.ErrNotExist) {
198-
return nil, m.renvEnvironmentCheck(base, log)
198+
return nil, m.renvEnvironmentCheck(log)
199199
}
200200
return nil, err
201201
}
@@ -260,7 +260,6 @@ func (m *defaultPackageMapper) GetManifestPackages(
260260
}
261261

262262
func (m *defaultPackageMapper) renvEnvironmentCheck(
263-
base util.AbsolutePath,
264263
log logging.Logger,
265264
) *types.AgentError {
266265
rInterpreter, err := m.rInterpreterFactory()

0 commit comments

Comments
 (0)