Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.

Check for DScanner global configuration #54 #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions source/dls/tools/analysis_tool.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import dls.tools.tool : Tool;

private immutable diagnosticSource = "D-Scanner";

private enum CONFIG_FILE_NAME = "dscanner.ini";
version (linux) version = useXDG;
version (BSD) version = useXDG;
version (FreeBSD) version = useXDG;
version (OSX) version = useXDG;

//dfmt off
private enum DScannerWarnings : string
{
Expand Down Expand Up @@ -215,6 +221,37 @@ class AnalysisTool : Tool
_analysisConfigs.remove(workspaceUri.path);
}

/**
* Locates the default configuration file
* (Taken from DScanner source)
*/
string getDefaultConfigurationLocation()
{
import std.process : environment;
import std.exception : enforce;
import std.path : buildPath;
version (useXDG)
{
string configDir = environment.get("XDG_CONFIG_HOME", null);
if (configDir is null)
{
configDir = environment.get("HOME", null);
enforce(configDir !is null, "Both $XDG_CONFIG_HOME and $HOME are unset");
configDir = buildPath(configDir, ".config", "dscanner", CONFIG_FILE_NAME);
}
else
configDir = buildPath(configDir, "dscanner", CONFIG_FILE_NAME);
return configDir;
}
else version(Windows)
{
string configDir = environment.get("APPDATA", null);
enforce(configDir !is null, "%APPDATA% is unset");
configDir = buildPath(configDir, "dscanner", CONFIG_FILE_NAME);
return configDir;
}
}

void updateAnalysisConfig(const Uri workspaceUri)
{
import dls.protocol.logger : logger;
Expand All @@ -231,6 +268,13 @@ class AnalysisTool : Tool
{
logger.info("Updating config from file %s", configPath);
readINIFile(conf, configPath);
} else {
static import std.process;
immutable defaultConfigurationPath = getDefaultConfigurationLocation;
if (exists(defaultConfigurationPath)){
logger.info("Updating config from file %s", defaultConfigurationPath);
readINIFile(conf, defaultConfigurationPath);
}
}

_analysisConfigPaths[workspaceUri.path] = configPath;
Expand Down Expand Up @@ -511,3 +555,4 @@ class AnalysisTool : Tool
return new WorkspaceEdit(changes.nullable, documentChanges.nullable);
}
}