Skip to content

Commit

Permalink
Verily, the package doth cease to taketh configuration upon importati…
Browse files Browse the repository at this point in the history
…on. (#71)

* Remove TSKDoNotDelete Generation

- No longer can one's configuration be taken from them on import of this package.
- User must use `Preferences > External Tools > Generate config files for:` to generate their config files.

* Update README
  • Loading branch information
Chizaruu authored Aug 1, 2023
1 parent ae77e9e commit 427b7ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
46 changes: 15 additions & 31 deletions Editor/ConfigGeneration/ConfigGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public interface IConfigGenerator
string EditorConfigSettings { get; set; }
string ProjectDirectory { get; }
IFlagHandler FlagHandler { get; }
bool TskFileExists();
void Sync(bool force = false);
void Sync();
}

public class ConfigGeneration : IConfigGenerator
Expand Down Expand Up @@ -86,7 +85,7 @@ public class ConfigGeneration : IConfigGenerator
},
""omnisharp.useModernNet"": true,
""omnisharp.sdkIncludePrereleases"": false,
""omnisharp.organizeImportsOnFormat"": true,
""omnisharp.organizeImportsOnFormat"": true
}";

const string k_DefaultWorkspaceJson =
Expand Down Expand Up @@ -225,32 +224,17 @@ IFileIO fileIOProvider
m_FileIOProvider = new FileIOProvider();
}

public bool TskFileExists()
public void Sync()
{
var doNotDelete = Path.Combine(ProjectDirectory, "TSKDoNotDelete.txt");

if (m_FileIOProvider.Exists(doNotDelete))
return true;

m_FileIOProvider.WriteAllText(
doNotDelete,
"This file is used by the TSK VSCode Editor package. Deleting it will cause your configuration to be overwritten."
);

return false;
}

public void Sync(bool canForce = false)
{
WriteVSCodeSettingsFiles(canForce);
WriteWorkspaceFile(canForce);
WriteOmniSharpConfigFile(canForce);
WriteEditorConfigFile(canForce);
WriteVSCodeSettingsFiles();
WriteWorkspaceFile();
WriteOmniSharpConfigFile();
WriteEditorConfigFile();
}

void WriteVSCodeSettingsFiles(bool canForce = false)
void WriteVSCodeSettingsFiles()
{
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.VSCode) || canForce)
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.VSCode))
{
var vsCodeDirectory = Path.Combine(ProjectDirectory, ".vscode");

Expand All @@ -263,9 +247,9 @@ void WriteVSCodeSettingsFiles(bool canForce = false)
}
}

void WriteWorkspaceFile(bool canForce = false)
void WriteWorkspaceFile()
{
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.Workspace) || canForce)
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.Workspace))
{
var workspaceFile = Path.Combine(
ProjectDirectory,
Expand All @@ -276,19 +260,19 @@ void WriteWorkspaceFile(bool canForce = false)
}
}

void WriteOmniSharpConfigFile(bool canForce = false)
void WriteOmniSharpConfigFile()
{
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.OmniSharp) || canForce)
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.OmniSharp))
{
var omniSharpConfig = Path.Combine(ProjectDirectory, "omnisharp.json");

m_FileIOProvider.WriteAllText(omniSharpConfig, OmniSharpSettings);
}
}

void WriteEditorConfigFile(bool canForce = false)
void WriteEditorConfigFile()
{
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.EditorConfig) || canForce)
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.EditorConfig))
{
var editorConfig = Path.Combine(ProjectDirectory, ".editorconfig");

Expand Down
5 changes: 0 additions & 5 deletions Editor/VSCodeScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,6 @@ public void CreateIfDoesntExist()
{
m_ProjectGeneration.Sync();
}

if (!m_ConfigGeneration.TskFileExists())
{
m_ConfigGeneration.Sync(true);
}
}

public void SyncIfNeeded(
Expand Down

0 comments on commit 427b7ab

Please sign in to comment.