Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
add helper function to get used dscanner config
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Apr 30, 2020
1 parent c9a2c29 commit c57d494
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions source/workspaced/com/dscanner.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module workspaced.com.dscanner;
import std.algorithm;
import std.array;
import std.conv;
import std.experimental.logger;
import std.file;
import std.json;
import std.stdio;
Expand Down Expand Up @@ -38,7 +39,7 @@ class DscannerComponent : ComponentWrapper
/// Asynchronously lints the file passed.
/// If you provide code then the code will be used and file will be ignored.
Future!(DScannerIssue[]) lint(string file = "", string ini = "dscanner.ini",
scope const(char)[] code = "")
scope const(char)[] code = "", bool skipWorkspacedPaths = false)
{
auto ret = new Future!(DScannerIssue[]);
gthreads.create({
Expand All @@ -47,11 +48,7 @@ class DscannerComponent : ComponentWrapper
{
if (code.length && !file.length)
file = "stdin";
auto config = defaultStaticAnalysisConfig();
if (getConfigPath("dscanner.ini", ini))
stderr.writeln("Overriding Dscanner ini with workspace-d dscanner.ini config file");
if (ini.exists)
readINIFile(config, ini);
auto config = getConfig(ini, skipWorkspacedPaths);
if (!code.length)
code = readText(file);
DScannerIssue[] issues;
Expand Down Expand Up @@ -97,6 +94,46 @@ class DscannerComponent : ComponentWrapper
return ret;
}

/// Gets the used D-Scanner config, optionally reading from a given
/// dscanner.ini file.
/// Params:
/// ini = an ini to load. Only reading from it if it exists. If this is
/// relative, this function will try both in getcwd and in the
/// instance.cwd, if an instance is set.
/// skipWorkspacedPaths = if true, don't attempt to override the given ini
/// with workspace-d user configs.
StaticAnalysisConfig getConfig(string ini = "dscanner.ini",
bool skipWorkspacedPaths = false)
{
import std.path : buildPath;

auto config = defaultStaticAnalysisConfig();
if (!skipWorkspacedPaths && getConfigPath("dscanner.ini", ini))
{
static bool didWarn = false;
if (!didWarn)
{
warning("Overriding Dscanner ini with workspace-d dscanner.ini config file");
didWarn = true;
}
}
string cwd = getcwd;
if (refInstance !is null)
cwd = refInstance.cwd;

if (ini.exists)
{
readINIFile(config, ini);
}
else
{
auto p = buildPath(cwd, ini);
if (p != ini && p.exists)
readINIFile(config, p);
}
return config;
}

private const(Module) parseModule(string file, ubyte[] code, RollbackAllocator* p,
ref StringCache cache, ref const(Token)[] tokens, ref DScannerIssue[] issues)
{
Expand Down

0 comments on commit c57d494

Please sign in to comment.