Skip to content

Commit d125a93

Browse files
committed
lazily adjust linting command
1 parent fcca01f commit d125a93

File tree

1 file changed

+74
-7
lines changed
  • workspace-d/source/workspaced/com

1 file changed

+74
-7
lines changed

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

+74-7
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public struct CompileCommand
166166
string[] args;
167167
string output;
168168

169+
private bool argsAdjusted;
170+
169171
private static CompileCommand fromJson(JSONValue json)
170172
{
171173
import std.algorithm : map;
@@ -233,23 +235,88 @@ public struct CompileCommand
233235
return absolutePath(filename, directory);
234236
}
235237

236-
Future!(BuildIssue[]) run() const
238+
Future!(BuildIssue[]) run()
237239
{
238-
import std.algorithm : canFind, remove;
239240
import std.process : Config, execute;
240241

242+
if (!argsAdjusted)
243+
{
244+
argsAdjusted = true;
245+
adjustArgs();
246+
}
247+
241248
return Future!(BuildIssue[]).async({
242-
trace("stripping color from ", args);
243-
string[] program = args.dup.remove!(a => a.canFind("-color=on") || a.canFind(
244-
"-enable-color"));
245-
trace("running ", program);
246-
auto res = execute(program, null, Config.none, size_t.max, directory);
249+
trace("running ", args);
250+
auto res = execute(args, null, Config.none, size_t.max, directory);
247251
trace(res.status, " ", res.output);
248252
auto issues = parseBuildIssues(res.output);
249253
trace("found ", issues.length, " issue(s)!");
250254
return issues;
251255
});
252256
}
257+
258+
private void adjustArgs() nothrow
259+
{
260+
import std.algorithm : canFind, remove, startsWith;
261+
262+
// determine compiler
263+
const exe = args.length ? args[0].baseName : null;
264+
if (!exe)
265+
return;
266+
267+
const isDmd = exe.canFind("dmd");
268+
const isLdc = !isDmd && exe.canFind("ldc");
269+
const isGdc = !isDmd && !isLdc && exe.canFind("gdc");
270+
271+
if (!isDmd && !isLdc && !isGdc)
272+
return;
273+
274+
version (Posix)
275+
enum nulFile = "/dev/null";
276+
else version (Windows)
277+
enum nulFile = "NUL";
278+
279+
if (isDmd || isLdc)
280+
{
281+
const ofArg = isDmd ? "-of" : "--of=";
282+
const columnsArg = isDmd ? "-vcolumns" : "--vcolumns";
283+
bool foundColumns;
284+
285+
for (size_t i = 1; i < args.length; ++i)
286+
{
287+
if (args[i].startsWith(ofArg))
288+
{
289+
args[i] = ofArg ~ nulFile;
290+
}
291+
else if (args[i] == columnsArg)
292+
{
293+
foundColumns = true;
294+
}
295+
else if (isDmd && args[i].startsWith("-color"))
296+
{
297+
args[i] = "-color=off";
298+
}
299+
else if (isLdc && args[i].startsWith("--enable-color"))
300+
{
301+
args[i] = "--disable-color";
302+
}
303+
}
304+
305+
if (!foundColumns)
306+
args ~= columnsArg;
307+
}
308+
else if (isGdc)
309+
{
310+
for (size_t i = 1; i < args.length; ++i)
311+
{
312+
if (args[i] == "-o" && (i + 1) < args.length)
313+
{
314+
args[i + 1] = nulFile;
315+
break;
316+
}
317+
}
318+
}
319+
}
253320
}
254321

255322
void feedOptions(

0 commit comments

Comments
 (0)