From 60af7441bf8c916a09783d6b26b79a33a7413b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20K=C3=BChl?= Date: Wed, 13 May 2015 16:41:52 +0200 Subject: [PATCH] Fix handling of multiple completion scopes When the YAML front matter contains no "completion-scope", the expression `[front_matter["completion-scope"]]` evaluates to `[nil]`, which is truthy, so the rest of the chain is not evaluated and the snippet is assigned `completion_scopes` of `[nil]`. As it happens, `[nil]` is serialised as `BAgw`. When a code snippet containing that "completion scope" is present, Xcode crashes as soon as I try to enter any text in a place where a snippet might be admissible. This change replaces the chain of `||` operators with a `case` block. This leads to some ugly repetition in the resulting code, but at least it doesn't crash Xcode. ;-) --- lib/xcodesnippet/commands/install.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/xcodesnippet/commands/install.rb b/lib/xcodesnippet/commands/install.rb index 826457d..36a0415 100644 --- a/lib/xcodesnippet/commands/install.rb +++ b/lib/xcodesnippet/commands/install.rb @@ -57,7 +57,11 @@ def extract_front_matter! end @snippet.title = front_matter["title"] || "" @snippet.summary = front_matter["summary"] || "" - @snippet.completion_scopes = [front_matter["completion-scope"]] || front_matter["completion-scopes"] || "All" + @snippet.completion_scopes = case + when front_matter["completion-scope"] then [front_matter["completion-scope"]] + when front_matter["completion-scopes"] then front_matter["completion-scopes"] + else "All" + end @snippet.identifier = SecureRandom.uuid().upcase @snippet.is_user_snippet = true @snippet.version = 0