Skip to content

Commit

Permalink
Remove unused symbols (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Nov 23, 2023
1 parent 2336f29 commit b7cb4ef
Show file tree
Hide file tree
Showing 32 changed files with 2 additions and 564 deletions.
1 change: 0 additions & 1 deletion src/Snippetica.CodeGeneration.Common/EnvironmentKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Snippetica;

public enum EnvironmentKind
{
None,
VisualStudio,
VisualStudioCode,
}
100 changes: 0 additions & 100 deletions src/Snippetica.CodeGeneration.Common/IO/IOUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Snippetica.VisualStudio;

Expand Down Expand Up @@ -85,55 +84,6 @@ private static SaveOptions CreateSaveSettings()
};
}

public static void SaveSnippetsToSingleFile(
IEnumerable<Snippet> snippets,
string filePath,
bool onlyIfChanged = true)
{
if (snippets is null)
throw new ArgumentNullException(nameof(snippets));

SaveOptions settings = CreateSaveSettings();

string content = SnippetSerializer.CreateXml(snippets, settings);

if (!ShouldSave(filePath, content, Encoding.UTF8, onlyIfChanged))
return;

using (var fileStream = new FileStream(filePath, FileMode.Create))
{
Console.WriteLine($"saving file {filePath}");
SnippetSerializer.Serialize(fileStream, snippets, settings);
}
}

public static void SaveSnippetBrowserFile(IEnumerable<Snippet> snippets, string filePath)
{
snippets = snippets
.Where(f => !f.HasTag(KnownTags.ExcludeFromSnippetBrowser))
.Select(snippet =>
{
snippet = (Snippet)snippet.Clone();

string submenuShortcut = snippet.GetShortcutFromTitle();

snippet.RemoveShortcutFromTitle();

snippet.RemoveMetaKeywords();

snippet.Keywords.Add($"{KnownTags.MetaPrefix}Name {snippet.GetFileNameWithoutExtension()}");

if (!string.IsNullOrEmpty(submenuShortcut))
snippet.Keywords.Add($"{KnownTags.MetaPrefix}SubmenuShortcut {submenuShortcut}");

return snippet;
})
.OrderBy(f => f.Language.ToString())
.ThenBy(f => f.GetFileNameWithoutExtension());

SaveSnippetsToSingleFile(snippets, filePath);
}

public static void WriteAllText(
string filePath,
string content,
Expand Down Expand Up @@ -167,59 +117,9 @@ private static bool ShouldSave(string filePath, string content, Encoding encodin
return !string.Equals(content, content2, StringComparison.Ordinal);
}

public static void CleanOrCreateDirectory(string directoryPath)
{
if (Directory.Exists(directoryPath))
{
CleanDirectory(directoryPath);
}
else
{
CreateDirectory(directoryPath);
}
}

private static void CleanDirectory(string directoryPath)
{
DeleteDirectories(directoryPath);
DeleteFiles(directoryPath);
}

private static void DeleteFiles(string directoryPath)
{
foreach (string path in Directory.EnumerateFiles(directoryPath))
DeleteFile(path);
}

private static void DeleteDirectories(string directoryPath)
{
foreach (string path in Directory.EnumerateDirectories(directoryPath))
DeleteDirectory(path);
}

public static void DeleteFile(string path)
{
Console.WriteLine($"deleting file {path}");
File.Delete(path);
}

private static void DeleteDirectory(string path)
{
Console.WriteLine($"deleting directory {path}");
Directory.Delete(path);
}

public static void DeleteAndCreateDirectory(string directoryPath)
{
if (Directory.Exists(directoryPath))
DeleteDirectory(directoryPath);

CreateDirectory(directoryPath);
}

private static void CreateDirectory(string directoryPath)
{
Console.WriteLine($"creating directory {directoryPath}");
Directory.CreateDirectory(directoryPath);
}
}
14 changes: 0 additions & 14 deletions src/Snippetica.CodeGeneration.Common/IO/Utf8StringWriter.cs

This file was deleted.

29 changes: 0 additions & 29 deletions src/Snippetica.CodeGeneration.Common/KeywordDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Snippetica.VisualStudio;

Expand All @@ -12,42 +11,14 @@ public class KeywordDefinition
{
private static readonly Version _formatVersion = new(1, 1, 0);

public static KeywordDefinition Default { get; } = new(null, null, null, null, false, Array.Empty<string>());

public KeywordDefinition(
string name,
string value,
string title,
string shortcut,
bool isDevelopment,
string[] tags)
{
Name = name;
Value = value;
Title = title;
Shortcut = shortcut;
IsDevelopment = isDevelopment;
Tags = new List<string>(tags);
}

public KeywordDefinition()
{
}

public string Name { get; init; }

public string Value { get; init; }

public string Title { get; init; }

public string Shortcut { get; init; }

public bool IsDevelopment { get; init; }

public List<string> Tags { get; init; }

public bool HasTag(string tag) => Tags.Contains(tag);

public Snippet ToSnippet()
{
string title = $"{Value} keyword";
Expand Down
5 changes: 0 additions & 5 deletions src/Snippetica.CodeGeneration.Common/KnownNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ namespace Snippetica;

public static class KnownNames
{
public const string ProductName = "Snippetica";
public const string ChangeLogFileName = "ChangeLog.md";
public const string SourceDirectoryName = "src";
public const string VisualStudioExtensionProjectName = ProductName + ".VisualStudio";
public const string VisualStudioCodeExtensionProjectName = ProductName + ".VisualStudioCode";
public const string AutoGeneration = "AutoGeneration";
public const string Dev = "Dev";
public const string DevSuffix = "." + Dev;
Expand Down
9 changes: 0 additions & 9 deletions src/Snippetica.CodeGeneration.Common/KnownTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,26 @@ public static class KnownTags
public const string BasicType = nameof(BasicType);
public const string Collection = nameof(Collection);
public const string Default = nameof(Default);
public const string Disabled = nameof(Disabled);
public const string Environment = nameof(Environment);
public const string ExcludeFromDocs = nameof(ExcludeFromDocs);
public const string ExcludeFromSnippetBrowser = nameof(ExcludeFromSnippetBrowser);
public const string ExcludeFromVisualStudio = nameof(ExcludeFromVisualStudio);
public const string ExcludeFromVisualStudioCode = nameof(ExcludeFromVisualStudioCode);
public const string GenerateXmlSnippets = nameof(GenerateXmlSnippets);
public const string Initializer = nameof(Initializer);
public const string Language = nameof(Language);
public const string NonUniqueShortcut = nameof(NonUniqueShortcut);
public const string NonUniqueTitle = nameof(NonUniqueTitle);
public const string NoQuickReference = nameof(NoQuickReference);
public const string ObsoleteShortcut = nameof(ObsoleteShortcut);
public const string ShortcutSuffix = nameof(ShortcutSuffix);
public const string TitleEndsWithUnderscore = nameof(TitleEndsWithUnderscore);
public const string TitleStartsWithShortcut = nameof(TitleStartsWithShortcut);
public const string TryParse = nameof(TryParse);
public const string Variable = nameof(Variable);
public const string VisualStudio = nameof(VisualStudio);

public const string MetaPrefix = "Meta-";
public const string GeneratePrefix = "Generate";

public const string GenerateAccessModifier = GeneratePrefix + "AccessModifier";
public const string GeneratePublicModifier = GeneratePrefix + "PublicModifier";
public const string GenerateInternalModifier = GeneratePrefix + "InternalModifier";
public const string GeneratePrivateModifier = GeneratePrefix + "PrivateModifier";
public const string GenerateProtectedModifier = GeneratePrefix + "ProtectedModifier";

public const string GenerateStaticModifier = GeneratePrefix + "StaticModifier";
public const string GenerateVirtualModifier = GeneratePrefix + "VirtualModifier";
Expand All @@ -48,7 +40,6 @@ public static class KnownTags
public const string GenerateConstModifier = GeneratePrefix + "ConstModifier";
public const string GenerateConstExprModifier = GeneratePrefix + "ConstExprModifier";
public const string GenerateInitializer = GeneratePrefix + "Initializer";
public const string GenerateXamlProperty = GeneratePrefix + "XamlProperty";
public const string GenerateType = GeneratePrefix + "Type";
public const string GenerateAlternativeShortcut = GeneratePrefix + "AlternativeShortcut";
public const string GenerateDeclarationAndDefinition = GeneratePrefix + "DeclarationAndDefinition";
Expand Down
2 changes: 0 additions & 2 deletions src/Snippetica.CodeGeneration.Common/LiteralIdentifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public static class LiteralIdentifiers
public const string Identifier = "_identifier";
public const string Initializer = "_initializer";
public const string Modifiers = "_modifiers";
public const string ParameterList = "_parameterList";
public const string Semicolon = "_semicolon";
public const string SubOrFunction = "_subOrFunction";
public const string Type = "_type";
public const string TypeParameterList = "_typeParameterList";
Expand Down
14 changes: 0 additions & 14 deletions src/Snippetica.CodeGeneration.Common/ModifierDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;

namespace Snippetica;

public class ModifierDefinition
{
public ModifierDefinition(string name, string keyword, string shortcut, string[] tags)
{
Name = name;
Keyword = keyword;
Shortcut = shortcut;
Tags = new List<string>(tags);
Kind = (ModifierKind)Enum.Parse(typeof(ModifierKind), Name);
}

public ModifierDefinition()
{
}

public string Name { get; init; }
public string Keyword { get; init; }
public string Shortcut { get; init; }
Expand Down
27 changes: 0 additions & 27 deletions src/Snippetica.CodeGeneration.Common/ShortcutInfo.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using Snippetica.VisualStudio;

namespace Snippetica;

public class ShortcutInfo
{
public ShortcutInfo(
string value,
string description,
string comment,
ShortcutKind kind,
IEnumerable<Language> languages,
IEnumerable<EnvironmentKind> environments,
IEnumerable<string> tags)
{
Value = value;
Description = description;
Comment = comment;
Kind = kind;
Environments = new List<EnvironmentKind>(environments.ToArray());
Languages = new List<Language>(languages.ToArray());
Tags = new List<string>(tags.ToArray());
}

public ShortcutInfo()
{
}

public string Value { get; set; }

public string Description { get; set; }
Expand All @@ -41,8 +18,4 @@ public ShortcutInfo()
public List<Language> Languages { get; set; }

public List<EnvironmentKind> Environments { get; set; }

public List<string> Tags { get; set; }

public bool HasTag(string value) => Tags.Contains(value);
}
22 changes: 0 additions & 22 deletions src/Snippetica.CodeGeneration.Common/SnippetDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,6 @@ public SnippetDirectory WithPath(string path)

public bool HasTag(string tag) => Tags.Any(f => f.Equals(tag, StringComparison.Ordinal));

public bool HasTags(params string[] tags)
{
foreach (string tag in tags)
{
if (!HasTag(tag))
return false;
}

return true;
}

public bool HasAnyTag(params string[] tags)
{
foreach (string tag in tags)
{
if (HasTag(tag))
return true;
}

return false;
}

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
Expand Down
Loading

0 comments on commit b7cb4ef

Please sign in to comment.