-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
renv
setup - Provide users with an easy solution for renv errors
#2560
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e5d582
Add additional checks and rely on renv package when lockfile requirem…
marcosnav eb00b69
Handle renv issues and suggested commands on the UI
marcosnav 44918ec
Update a few tests to work with windows paths system
marcosnav a870cb0
PR feedback
marcosnav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright (C) 2025 by Posit Software, PBC. | ||
|
||
import { describe, expect, beforeEach, test, vi } from "vitest"; | ||
import { window } from "vscode"; | ||
import { | ||
showErrorMessageWithTroubleshoot, | ||
showInformationMsg, | ||
taskWithProgressMsg, | ||
runTerminalCommand, | ||
} from "./window"; | ||
|
||
const terminalMock = { | ||
sendText: vi.fn(), | ||
show: vi.fn(), | ||
exitStatus: { | ||
code: 0, | ||
}, | ||
}; | ||
|
||
vi.mock("vscode", () => { | ||
// mock Disposable | ||
const disposableMock = vi.fn(); | ||
disposableMock.prototype.dispose = vi.fn(); | ||
|
||
// mock window | ||
const windowMock = { | ||
showErrorMessage: vi.fn(), | ||
showWarningMessage: vi.fn(), | ||
showInformationMessage: vi.fn(), | ||
withProgress: vi.fn().mockImplementation((_, progressCallback) => { | ||
progressCallback(); | ||
}), | ||
createTerminal: vi.fn().mockImplementation(() => { | ||
terminalMock.sendText = vi.fn(); | ||
terminalMock.show = vi.fn(); | ||
return terminalMock; | ||
}), | ||
onDidCloseTerminal: vi.fn().mockImplementation((fn) => { | ||
setTimeout(() => fn(terminalMock), 100); | ||
return new disposableMock(); | ||
}), | ||
}; | ||
|
||
return { | ||
Disposable: disposableMock, | ||
window: windowMock, | ||
ProgressLocation: { | ||
SourceControl: 1, | ||
Window: 10, | ||
Notification: 15, | ||
}, | ||
}; | ||
}); | ||
|
||
describe("Consumers of vscode window", () => { | ||
beforeEach(() => { | ||
terminalMock.exitStatus.code = 0; | ||
}); | ||
|
||
test("showErrorMessageWithTroubleshoot", () => { | ||
showErrorMessageWithTroubleshoot("Bad things happened"); | ||
expect(window.showErrorMessage).toHaveBeenCalledWith( | ||
"Bad things happened. See [Troubleshooting docs](https://github.com/posit-dev/publisher/blob/main/docs/troubleshooting.md) for help.", | ||
); | ||
|
||
showErrorMessageWithTroubleshoot( | ||
"Bad things happened.", | ||
"one", | ||
"two", | ||
"three", | ||
); | ||
expect(window.showErrorMessage).toHaveBeenCalledWith( | ||
"Bad things happened. See [Troubleshooting docs](https://github.com/posit-dev/publisher/blob/main/docs/troubleshooting.md) for help.", | ||
"one", | ||
"two", | ||
"three", | ||
); | ||
}); | ||
|
||
test("showInformationMsg", () => { | ||
showInformationMsg("Good thing happened"); | ||
expect(window.showInformationMessage).toHaveBeenCalledWith( | ||
"Good thing happened", | ||
); | ||
|
||
showInformationMsg("Good thing happened", "one", "two", "three"); | ||
expect(window.showInformationMessage).toHaveBeenCalledWith( | ||
"Good thing happened", | ||
"one", | ||
"two", | ||
"three", | ||
); | ||
}); | ||
|
||
test("taskWithProgressMsg", () => { | ||
const taskMock = vi.fn(); | ||
taskWithProgressMsg( | ||
"Running a task with a progress notification", | ||
taskMock, | ||
); | ||
expect(window.withProgress).toHaveBeenCalledWith( | ||
{ | ||
location: 15, | ||
title: "Running a task with a progress notification", | ||
cancellable: false, | ||
}, | ||
expect.any(Function), | ||
); | ||
expect(taskMock).toHaveBeenCalled(); | ||
}); | ||
|
||
describe("runTerminalCommand", () => { | ||
test("showing the terminal", async () => { | ||
await runTerminalCommand("stat somefile.txt", true); | ||
expect(terminalMock.sendText).toHaveBeenCalledWith("stat somefile.txt"); | ||
expect(terminalMock.show).toHaveBeenCalled(); | ||
// For terminals that we open, we don't track close events | ||
expect(window.onDidCloseTerminal).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test("NOT showing the terminal", async () => { | ||
await runTerminalCommand("stat somefile.txt"); | ||
expect(terminalMock.sendText).toHaveBeenCalledWith("stat somefile.txt"); | ||
// For terminals that we DO NOT open, we DO track close events | ||
expect(terminalMock.show).not.toHaveBeenCalled(); | ||
expect(window.onDidCloseTerminal).toHaveBeenCalled(); | ||
}); | ||
|
||
test("catch non zero exit status", async () => { | ||
terminalMock.exitStatus.code = 1; | ||
try { | ||
await runTerminalCommand("stat somefile.txt"); | ||
} catch (_) { | ||
expect(terminalMock.sendText).toHaveBeenCalledWith("stat somefile.txt"); | ||
// For terminals that we DO NOT open, we DO track close events | ||
expect(terminalMock.show).not.toHaveBeenCalled(); | ||
expect(window.onDidCloseTerminal).toHaveBeenCalled(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Copyright (C) 2025 by Posit Software, PBC. | ||
|
||
import { window } from "vscode"; | ||
import { window, ProgressLocation, Progress, CancellationToken } from "vscode"; | ||
|
||
export function showErrorMessageWithTroubleshoot( | ||
message: string, | ||
|
@@ -14,3 +14,67 @@ export function showErrorMessageWithTroubleshoot( | |
" See [Troubleshooting docs](https://github.com/posit-dev/publisher/blob/main/docs/troubleshooting.md) for help."; | ||
return window.showErrorMessage(msg, ...items); | ||
} | ||
|
||
export function showInformationMsg(msg: string, ...items: string[]) { | ||
return window.showInformationMessage(msg, ...items); | ||
} | ||
|
||
type taskFunc = <T>(p: Progress<T>, t: CancellationToken) => Promise<void>; | ||
const progressCallbackHandlerFactory = | ||
( | ||
task: taskFunc, | ||
cancellable: boolean = false, | ||
onCancel?: () => void, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: could we combine the |
||
): taskFunc => | ||
(progress, token) => { | ||
if (cancellable && onCancel) { | ||
token.onCancellationRequested(() => { | ||
onCancel(); | ||
}); | ||
} | ||
return task(progress, token); | ||
}; | ||
|
||
export function taskWithProgressMsg( | ||
msg: string, | ||
task: taskFunc, | ||
cancellable: boolean = false, | ||
onCancel?: () => void, | ||
) { | ||
return window.withProgress( | ||
{ | ||
location: ProgressLocation.Notification, | ||
title: msg, | ||
cancellable, | ||
}, | ||
progressCallbackHandlerFactory(task, cancellable, onCancel), | ||
); | ||
} | ||
|
||
export function runTerminalCommand( | ||
cmd: string, | ||
show: boolean = false, | ||
): Promise<void> { | ||
const term = window.createTerminal(); | ||
term.sendText(cmd); | ||
|
||
// If terminal is shown, there is no need to track exit status for it | ||
// everything will be visible on it. | ||
if (show) { | ||
term.show(); | ||
return Promise.resolve(); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
const disposeToken = window.onDidCloseTerminal((closedTerminal) => { | ||
if (closedTerminal === term) { | ||
disposeToken.dispose(); | ||
if (term.exitStatus && term.exitStatus.code === 0) { | ||
resolve(); | ||
} else { | ||
reject(); | ||
} | ||
} | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding a test here. I should have done it with the introduction of the function 😅