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
18 changes: 14 additions & 4 deletions lsp/source/served/lsp/jsonrpc.d
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ class RPCProcessor : Fiber

StopWatch sw;
sw.start();
// a timed-out wait must release its slot too, or prepareWait can never
// reuse it
scope (failure)
responseTokens[i].handled = true;
while (!responseTokens[i].got)
{
if (timeout != Duration.max
Expand Down Expand Up @@ -953,22 +957,28 @@ struct WindowFunctions
}

/// Runs window/showMessageRequest which typically shows a message box with possible action buttons to click. Returns the action which got clicked or one with null title if it has been dismissed.
MessageActionItem requestMessage(MessageType type, string message, MessageActionItem[] actions)
///
/// Params:
/// timeout = how long to wait for an answer; throws once it elapses. Clients
/// are not required to ever answer.
MessageActionItem requestMessage(MessageType type, string message,
MessageActionItem[] actions, Duration timeout = Duration.max)
{
auto res = rpc.sendRequest("window/showMessageRequest",
ShowMessageRequestParams(type, message, actions.opt));
ShowMessageRequestParams(type, message, actions.opt), timeout);
if (!res.resultJson.length || res.resultJson == `null`)
return MessageActionItem(null);
return res.resultJson.deserializeJson!MessageActionItem;
}

/// ditto
string requestMessage(MessageType type, string message, string[] actions)
string requestMessage(MessageType type, string message, string[] actions,
Duration timeout = Duration.max)
{
MessageActionItem[] a = new MessageActionItem[actions.length];
foreach (i, action; actions)
a[i] = MessageActionItem(action);
return requestMessage(type, message, a).title;
return requestMessage(type, message, a, timeout).title;
}

/// Runs a function and shows a UI message on failure and logs the error.
Expand Down
55 changes: 45 additions & 10 deletions source/served/extension.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import served.utils.translate;

public import served.utils.async;

import core.time : msecs, seconds;
import core.time : minutes, msecs, seconds;

import std.algorithm : any, canFind, endsWith, map, remove;
import std.array : appender, array;
Expand Down Expand Up @@ -451,7 +451,20 @@ void doGlobalStartup(UserConfiguration config)
if (!backend.has!DCDComponent)
actions.length--;

auto res = rpc.window.requestMessage(MessageType.error, outdatedMessage, actions);
// some clients never answer; without a timeout this fiber would
// live for the rest of the process
enum promptTimeout = 10.minutes;

string res;
try
res = rpc.window.requestMessage(MessageType.error,
outdatedMessage, actions, promptTimeout);
catch (Exception e)
{
warningf("No answer to the DCD update prompt after %s, "
~ "giving up: %s", promptTimeout, e.msg);
return;
}

if (res == action)
spawnFiber("updateDCD", (&updateDCD).toDelegate);
Expand Down Expand Up @@ -766,9 +779,19 @@ void delayedProjectActivation(WorkspaceD.Instance instance, string workspaceRoot
}
auto loadButton = translate!"d.served.tooManySubprojects.load";
auto skipButton = translate!"d.served.tooManySubprojects.skip";
auto res = rpc.window.requestMessage(MessageType.warning,
translate!"d.served.tooManySubprojects.path"(root.dir),
[loadButton, skipButton]);

// some clients never answer; empty res skips, as dismissing would
enum promptTimeout = 10.minutes;

string res;
try
res = rpc.window.requestMessage(MessageType.warning,
translate!"d.served.tooManySubprojects.path"(root.dir),
[loadButton, skipButton], promptTimeout);
catch (Exception e)
warningf("No answer to the subproject load prompt for %s after "
~ "%s, skipping it: %s", root.dir, promptTimeout, e.msg);

if (res != loadButton)
goto case ManyProjectsAction.skip;
break;
Expand Down Expand Up @@ -833,11 +856,23 @@ void delayedProjectActivation(WorkspaceD.Instance instance, string workspaceRoot
missingList = missingList[0 .. comma + 1] ~ " ...";
}

auto res = rpc.window.requestMessage(
MessageType.info,
translate!"d.dub.downloadMissingMsg"(missingList),
[upgrade, always, never]
);
// some clients never answer; empty res downloads nothing, as
// dismissing would
enum promptTimeout = 10.minutes;

string res;
try
res = rpc.window.requestMessage(
MessageType.info,
translate!"d.dub.downloadMissingMsg"(missingList),
[upgrade, always, never],
promptTimeout
);
catch (Exception e)
warningf("No answer to the missing dependency prompt "
~ "after %s, not downloading: %s", promptTimeout,
e.msg);

if (res == always)
{
rpc.notifyMethod("coded/updateSetting", UpdateSettingParams("forceDownloadDependencies",
Expand Down
Loading