diff options
author | Aaron Bockover <abock@microsoft.com> | 2019-04-30 23:47:30 +0300 |
---|---|---|
committer | Aaron Bockover <abock@microsoft.com> | 2019-04-30 23:47:30 +0300 |
commit | d87b1de77763fc4cbe562770aaf4b193ac09a1c9 (patch) | |
tree | bfc10db8f13ffc33189729699ae3a1194480d0c9 /main/src/addins/MonoDevelop.TextEditor | |
parent | d6f5f6a5df40a3d3702a8eb7bbc1dcc645bd763f (diff) |
Snippets: check for snippets directory before importing
Fixes a hard IDE crash. Handle possible exception points on a
per-snippet level as well.
Diffstat (limited to 'main/src/addins/MonoDevelop.TextEditor')
-rw-r--r-- | main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor.Cocoa/ExpansionManager.cs | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor.Cocoa/ExpansionManager.cs b/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor.Cocoa/ExpansionManager.cs index eaba6e8b2c..0d15cf2103 100644 --- a/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor.Cocoa/ExpansionManager.cs +++ b/main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor.Cocoa/ExpansionManager.cs @@ -15,25 +15,51 @@ namespace MonoDevelop.TextEditor.Cocoa [Export (typeof (IExpansionManager))] class ExpansionManager : IExpansionManager { - Dictionary<IContentType, List<ExpansionTemplate>> expansionTemplates = new Dictionary<IContentType, List<ExpansionTemplate>> (); - static string UserSnippetsPath { - get { - return UserProfile.Current.UserDataRoot.Combine ("Snippets"); - } - } + static string UserSnippetsPath { get; } = UserProfile.Current.UserDataRoot.Combine ("Snippets"); + + readonly Dictionary<IContentType, List<ExpansionTemplate>> expansionTemplates + = new Dictionary<IContentType, List<ExpansionTemplate>> (); + public IEnumerable<ExpansionTemplate> EnumerateExpansions (IContentType contentType, bool shortcutOnly, string[] snippetTypes, bool includeNullType, bool includeDuplicates) { List<ExpansionTemplate> templates = null; - lock (expansionTemplates) + lock (expansionTemplates) { if (expansionTemplates.TryGetValue (contentType, out templates)) return templates; + } + templates = new List<ExpansionTemplate> (); - foreach (var codeTemplate in CodeTemplateService.GetCodeTemplates (IdeServices.DesktopService.GetMimeTypeForContentType (contentType))) - templates.Add (Convert (codeTemplate)); - foreach (var snippetFile in Directory.EnumerateFiles (UserSnippetsPath, "*.snippet")) - templates.Add (new ExpansionTemplate (snippetFile)); + + foreach (var codeTemplate in CodeTemplateService.GetCodeTemplates ( + IdeServices.DesktopService.GetMimeTypeForContentType (contentType))) { + try { + templates.Add (Convert (codeTemplate)); + } catch (Exception e) { + LoggingService.LogError ("Exception converting Snippet to VS Expansion Template", e); + } + } + + if (Directory.Exists (UserSnippetsPath)) { + try { + foreach (var snippetFile in Directory.EnumerateFiles (UserSnippetsPath, "*.snippet")) { + try { + templates.Add (new ExpansionTemplate (snippetFile)); + } catch (Exception parseException) { + LoggingService.LogError ( + $"Unable to parse VS Expansion template: {snippetFile}", + parseException); + } + } + } catch (Exception enumerateException) { + LoggingService.LogError ( + $"Exception enumerating snippets directory: {UserSnippetsPath}", + enumerateException); + } + } + lock (expansionTemplates) expansionTemplates[contentType] = templates; + return templates; } |