Skip to content

Commit abf1205

Browse files
committed
feat: implement rstudioapi::showPrompt() and rstudioapi::askForPassword() for sess package
Ported changes from PR #1694 to dev branch, targeting sess package instead of legacy R/session/. Added handlers in session.ts and helpers in rstudioapi.ts.
1 parent 1a247cc commit abf1205

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

sess/R/rstudioapi.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,14 @@ patch_rstudioapi <- function() {
388388
readRStudioPreference = readRStudioPreference,
389389
getConsoleEditorContext = .sess_not_yet_implemented,
390390
sourceMarkers = .sess_not_yet_implemented,
391-
showPrompt = .sess_not_yet_implemented,
391+
showPrompt = function(title, message, default = NULL) {
392+
response <- request_client("rstudioapi/show_prompt", args = list(title = title, message = message, default = default))
393+
response$response
394+
},
395+
askForPassword = function(prompt = "Please enter your password") {
396+
response <- request_client("rstudioapi/ask_for_password", args = list(prompt = prompt))
397+
response$response
398+
},
392399
showQuestion = .sess_not_yet_implemented,
393400
updateDialog = .sess_not_yet_implemented,
394401
openProject = .sess_not_yet_implemented,

src/rstudioapi.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ export function showDialog(message: string): void {
144144

145145
}
146146

147+
export async function showPrompt(
148+
title: string, message: string, defaultValue?: string
149+
): Promise<{ response: string | null }> {
150+
const result = await window.showInputBox({
151+
title: title,
152+
prompt: message,
153+
value: defaultValue ?? '',
154+
});
155+
return { response: result ?? null };
156+
}
157+
158+
export async function askForPassword(
159+
prompt: string
160+
): Promise<{ response: string | null }> {
161+
const result = await window.showInputBox({
162+
prompt: prompt,
163+
password: true,
164+
});
165+
return { response: result ?? null };
166+
}
167+
147168
export async function navigateToFile(file: string, line: number, column: number): Promise<void>{
148169

149170
const targetDocument = await workspace.openTextDocument(Uri.file(file));

src/session.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,12 @@ async function handleRequest(message: Record<string, unknown>, ws: ExtWebSocket)
831831
rstudioapi.showDialog(String(params.message));
832832
result = true;
833833
break;
834+
case 'rstudioapi/show_prompt':
835+
result = await rstudioapi.showPrompt(String(params.title), String(params.message), params.default as string | undefined);
836+
break;
837+
case 'rstudioapi/ask_for_password':
838+
result = await rstudioapi.askForPassword(String(params.prompt));
839+
break;
834840
case 'rstudioapi/navigate_to_file':
835841
await rstudioapi.navigateToFile(String(params.file), Number(params.line), Number(params.column));
836842
result = true;

0 commit comments

Comments
 (0)