From 52b9b43fa38b8096f3e3dabac98ec726a9252d8f Mon Sep 17 00:00:00 2001
From: Peter Souter
Date: Fri, 11 Mar 2016 14:41:29 +0000
Subject: [PATCH] Fixes resources with variable name
Before it would not be highlighted correclty
---
grammars/puppet.cson | 9 +++++++++
spec/puppet-spec.coffee | 10 ++++++++++
2 files changed, 19 insertions(+)
diff --git a/grammars/puppet.cson b/grammars/puppet.cson
index d2a2f0e..461f88b 100644
--- a/grammars/puppet.cson
+++ b/grammars/puppet.cson
@@ -122,6 +122,15 @@
'match': '^\\s*(\\w+)\\s*{\\s*([\'"].+[\'"]):'
'name': 'meta.definition.resource.puppet'
}
+ {
+ 'match': '^\\s*(\\w+)\\s*{\\s*(\\$[a-zA-Z_]+)\\s*:'
+ 'captures':
+ '1':
+ 'name': 'storage.type.puppet'
+ '2':
+ 'name': 'entity.name.section.puppet'
+ 'name': 'meta.definition.resource.puppet'
+ }
{
'match': '\\b(case|if|else|elsif)(?!::)\\b'
'name': 'keyword.control.puppet'
diff --git a/spec/puppet-spec.coffee b/spec/puppet-spec.coffee
index 57cb1c1..893600d 100644
--- a/spec/puppet-spec.coffee
+++ b/spec/puppet-spec.coffee
@@ -37,3 +37,13 @@ describe "Puppet grammar", ->
it "tokenizes contain as an include function", ->
{tokens} = grammar.tokenizeLine('include foo')
expect(tokens[0]).toEqual value: 'include', scopes: ['source.puppet', 'meta.include.puppet', 'keyword.control.import.include.puppet']
+
+ it "tokenizes resource type and string title", ->
+ {tokens} = grammar.tokenizeLine("package {'foo':}")
+ expect(tokens[0]).toEqual value: 'package', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'storage.type.puppet']
+ expect(tokens[2]).toEqual value: "'foo'", scopes: ['source.puppet', 'meta.definition.resource.puppet', 'entity.name.section.puppet']
+
+ it "tokenizes resource type and variable title", ->
+ {tokens} = grammar.tokenizeLine("package {$foo:}")
+ expect(tokens[0]).toEqual value: 'package', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'storage.type.puppet']
+ expect(tokens[2]).toEqual value: '$foo', scopes: ['source.puppet', 'meta.definition.resource.puppet', 'entity.name.section.puppet']