Skip to content

Commit 3c16010

Browse files
committed
support starting serve-d autocomplete with old DCD versions
1 parent fd92e12 commit 3c16010

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

source/served/backend/lazy_workspaced.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class LazyWorkspaceD : WorkspaceD
2626
return wasAccessed;
2727
}
2828

29+
bool isPending(string component) const
30+
{
31+
return lazyComponents.any!(c => c.info.name == component);
32+
}
33+
2934
void onLazyLoad(string component, LazyLoadHook hook)
3035
{
3136
foreach (com; instanceComponents)

source/served/extension.d

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,29 @@ void doGlobalStartup(UserConfiguration config)
445445
action = translate!"d.ext.compileProgram"("DCD");
446446
else
447447
action = translate!"d.ext.downloadProgram"("DCD");
448+
string continueAnyway = translate!"d.served.ignoreDCDUpdate";
448449

449-
auto res = rpc.window.requestMessage(MessageType.error, outdatedMessage, [
450-
action
451-
]);
450+
string[] actions = [action, continueAnyway];
451+
if (!backend.has!DCDComponent)
452+
actions.length--;
453+
454+
auto res = rpc.window.requestMessage(MessageType.error, outdatedMessage, actions);
452455

453456
if (res == action)
454457
spawnFiber("updateDCD", (&updateDCD).toDelegate);
458+
else if (res == continueAnyway)
459+
{
460+
import served.backend.lazy_workspaced : LazyWorkspaceD;
461+
462+
backend.get!DCDComponent.ignoreOutdatedForSession();
463+
dcdUpdating = false;
464+
foreach (instance; backend.instances) {
465+
if (auto lazyInstance = cast(LazyWorkspaceD.LazyInstance) instance) {
466+
if (!lazyInstance.isPending("dcd"))
467+
startDCDServer(instance, instance.cwd.uriFromFile);
468+
}
469+
}
470+
}
455471
});
456472
}
457473
}

views/de.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ d.coverage.tooltip: Testabdeckung in dieser Datei wurde aus der zugehörigen .ls
166166

167167
d.served.failDCD: Konnte DCD nicht starten. (Projekt={0}, Pfad={1}, {2})
168168
d.served.outdatedDCD: DCD ist veraltet. (gesucht={0}, installiert={1})
169+
d.served.ignoreDCDUpdate: Trotzdem verwenden
169170
d.served.failDscanner: Konnte DScanner nicht starten. (Projekt={0}, Pfad={1})
170171
d.served.tooManySubprojects.path: Nach Einstellung d.manyProjectsThreshold sind zu viele Projekte in dieser Projektmappe.\n\nSoll `{0}` geladen werden?
171172
d.served.tooManySubprojects.load: Alle Laden

views/en.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ d.coverage.tooltip: Coverage in this file generated from the according .lst file
172172

173173
d.served.failDCD: Could not start DCD. (root={0}, path={1}, {2})
174174
d.served.outdatedDCD: DCD is outdated. (target={0}, installed={1})
175+
d.served.ignoreDCDUpdate: Continue anyway
175176
d.served.failDscanner: Could not start DScanner. (root={0}, path={1})
176177
d.served.tooManySubprojects.path: There are too many subprojects in this project according to d.manyProjectsThreshold\n\nDo you want to load `{0}`?
177178
d.served.tooManySubprojects.load: Load

workspace-d/source/workspaced/com/dcd.d

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class DCDComponent : ComponentWrapper
4141
installedVersion = workspaced.globalConfiguration.get("dcd", "_installedVersion", "");
4242

4343
if (installedVersion.length
44-
&& this.clientPath == workspaced.globalConfiguration.get("dcd", "_clientPath", "")
45-
&& this.serverPath == workspaced.globalConfiguration.get("dcd", "_serverPath", ""))
44+
&& this.clientPath == workspaced.globalConfiguration.get("dcd", "_clientPath", "")
45+
&& this.serverPath == workspaced.globalConfiguration.get("dcd", "_serverPath", ""))
4646
{
4747
if (workspaced.globalConfiguration.get("dcd", "_usingInternal", false))
4848
client = new BuiltinDCDClient();
@@ -68,7 +68,8 @@ class DCDComponent : ComponentWrapper
6868
trace("Detected dcd-server ", serverPathInfo, installedVersion);
6969

7070
if (!checkVersion(installedVersion, BuiltinDCDClient.minSupportedServerInclusive)
71-
|| checkVersion(installedVersion, BuiltinDCDClient.maxSupportedServerExclusive))
71+
|| checkVersion(installedVersion, BuiltinDCDClient
72+
.maxSupportedServerExclusive))
7273
{
7374
trace("Using dcd-client instead of internal workspace-d client");
7475

@@ -93,19 +94,20 @@ class DCDComponent : ComponentWrapper
9394
assert(this.clientPath == clientPath);
9495
assert(this.serverPath == serverPath);
9596

96-
//dfmt off
9797
if (isOutdated)
9898
workspaced.messageHandler.warn(refInstance, "dcd",
9999
WarningId.dcdOutdated, "DCD is outdated");
100-
//dfmt on
101100

102101
workspaced.globalConfiguration.set("dcd", "_usingInternal",
103-
cast(ExternalDCDClient) client ? false : true);
102+
cast(ExternalDCDClient) client ? false : true);
104103
workspaced.globalConfiguration.set("dcd", "_clientPath", clientPath);
105104
workspaced.globalConfiguration.set("dcd", "_serverPath", serverPath);
106105
workspaced.globalConfiguration.set("dcd", "_installedVersion", installedVersion);
107106
}
108107

108+
// using both static and __gshared because it didn't work without both for me, but I couldn't isolate it
109+
static __gshared bool ignoreOutdatedThisSession = false; // @suppress(dscanner.unnecessary.duplicate_attribute)
110+
109111
/// Returns: true if DCD version is less than latestKnownVersion or if server and client mismatch or if it doesn't exist.
110112
bool isOutdated()
111113
{
@@ -123,19 +125,28 @@ class DCDComponent : ComponentWrapper
123125
}
124126
}
125127

128+
if (ignoreOutdatedThisSession)
129+
return false;
130+
126131
if (installedVersion.isLocallyCompiledDCD)
127132
return false;
128133

129134
return !checkVersion(installedVersion, latestKnownVersion);
130135
}
131136

137+
/// During the runtime of this serve-d run, ignore DCD outdated warnings.
138+
void ignoreOutdatedForSession()
139+
{
140+
ignoreOutdatedThisSession = true;
141+
}
142+
132143
/// Returns: The current detected installed version of dcd-client.
133144
/// Ends with `"-workspaced-builtin"` if this is using the builtin
134145
/// client.
135146
string clientInstalledVersion() @property const
136147
{
137-
return cast(ExternalDCDClient) client ? installedVersion :
138-
BuiltinDCDClient.clientVersion ~ "-workspaced-builtin";
148+
return cast(ExternalDCDClient) client ? installedVersion
149+
: BuiltinDCDClient.clientVersion ~ "-workspaced-builtin";
139150
}
140151

141152
/// Returns: The current detected installed version of dcd-server. `null` if
@@ -208,7 +219,8 @@ class DCDComponent : ComponentWrapper
208219

209220
client.runningPort = port;
210221
client.socketFile = buildPath(tempDir,
211-
"workspace-d-sock" ~ thisProcessID.to!string ~ "-" ~ uniform!ulong.to!string(36));
222+
"workspace-d-sock" ~ thisProcessID.to!string ~ "-"
223+
~ uniform!ulong.to!string(36));
212224

213225
string[] serverArgs;
214226
static if (platformSupportsDCDUnixSockets)
@@ -218,7 +230,7 @@ class DCDComponent : ComponentWrapper
218230

219231
trace("Start dcd-server ", serverArgs);
220232
serverPipes = raw(serverArgs ~ imports,
221-
Redirect.stdin | Redirect.stderr | Redirect.stdoutToStderr);
233+
Redirect.stdin | Redirect.stderr | Redirect.stdoutToStderr);
222234
while (!serverPipes.stderr.eof)
223235
{
224236
string line = serverPipes.stderr.readln();
@@ -361,8 +373,11 @@ class DCDComponent : ComponentWrapper
361373
}
362374

363375
ret.finish(client.requestSymbolSearch(query)
364-
.map!(a => DCDSearchResult(a.symbolFilePath,
365-
cast(int)a.symbolLocation, [cast(char) a.kind].idup)).array);
376+
.map!(a => DCDSearchResult(
377+
a.symbolFilePath,
378+
cast(int) a.symbolLocation,
379+
[cast(char) a.kind].idup
380+
)).array);
366381
}
367382
catch (Throwable t)
368383
{
@@ -382,7 +397,9 @@ class DCDComponent : ComponentWrapper
382397
void addImports(string[] imports)
383398
{
384399
imports.sort!"a<b";
385-
knownImports = multiwayUnion([knownImports.filterNonEmpty, imports.filterNonEmpty]).array;
400+
knownImports = multiwayUnion([
401+
knownImports.filterNonEmpty, imports.filterNonEmpty
402+
]).array;
386403
updateImports();
387404
}
388405

@@ -596,7 +613,7 @@ class DCDComponent : ComponentWrapper
596613
{
597614
calltips ~= item.definition;
598615
symbols ~= DCDCompletions.Symbol(item.symbolFilePath,
599-
cast(int)item.symbolLocation, item.documentation);
616+
cast(int) item.symbolLocation, item.documentation);
600617
}
601618
completions._calltips = calltips.data;
602619
completions._symbols = symbols.data;
@@ -608,9 +625,9 @@ class DCDComponent : ComponentWrapper
608625
foreach (item; c.completions)
609626
{
610627
identifiers ~= DCDIdentifier(item.identifier,
611-
item.kind == char.init ? "" : [cast(char)item.kind].idup,
628+
item.kind == char.init ? "" : [cast(char) item.kind].idup,
612629
item.definition, item.symbolFilePath,
613-
cast(int)item.symbolLocation, item.documentation,
630+
cast(int) item.symbolLocation, item.documentation,
614631
item.typeOf);
615632
}
616633
completions._identifiers = identifiers.data;
@@ -680,12 +697,14 @@ private:
680697

681698
auto raw(string[] args, Redirect redirect = Redirect.all)
682699
{
683-
return pipeProcess(args, redirect, null, Config.none, refInstance ? instance.cwd : null);
700+
return pipeProcess(args, redirect, null, Config.none, refInstance
701+
? instance.cwd : null);
684702
}
685703

686704
auto rawExec(string[] args)
687705
{
688-
return execute(args, null, Config.none, size_t.max, refInstance ? instance.cwd : null);
706+
return execute(args, null, Config.none, size_t.max, refInstance
707+
? instance.cwd : null);
689708
}
690709

691710
bool isSocketRunning(string socket)

0 commit comments

Comments
 (0)