mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Eat interpolated variables in TextMate snippets
Someday we'll actually shell out to fill in their values, but for now, we just replace them with an empty string.
This commit is contained in:
@@ -47,14 +47,6 @@ describe "Snippets extension", ->
|
||||
|
||||
"""
|
||||
|
||||
"tab stop placeholders":
|
||||
prefix: "t4"
|
||||
body: """
|
||||
go here ${1:first
|
||||
think a while}, and then here ${2:second}
|
||||
|
||||
"""
|
||||
|
||||
"nested tab stops":
|
||||
prefix: "t5"
|
||||
body: '${1:"${2:key}"}: ${3:value}'
|
||||
@@ -128,16 +120,6 @@ describe "Snippets extension", ->
|
||||
expect(buffer.lineForRow(2)).toBe "go here next:(abc) and finally go here:( )"
|
||||
expect(editor.activeEditSession.getAnchors().length).toBe anchorCountBefore
|
||||
|
||||
describe "when the tab stops have placeholder text", ->
|
||||
it "auto-fills the placeholder text and highlights it when navigating to that tab stop", ->
|
||||
editor.insertText 't4'
|
||||
editor.trigger 'snippets:expand'
|
||||
expect(buffer.lineForRow(0)).toBe 'go here first'
|
||||
expect(buffer.lineForRow(1)).toBe 'think a while, and then here second'
|
||||
expect(editor.getSelectedBufferRange()).toEqual [[0, 8], [1, 13]]
|
||||
editor.trigger keydownEvent('tab', target: editor[0])
|
||||
expect(editor.getSelectedBufferRange()).toEqual [[1, 29], [1, 35]]
|
||||
|
||||
describe "when tab stops are nested", ->
|
||||
it "destroys the inner tab stop if the outer tab stop is modified", ->
|
||||
buffer.setText('')
|
||||
@@ -305,7 +287,7 @@ describe "Snippets extension", ->
|
||||
expect(Worker.prototype.terminate).toHaveBeenCalled()
|
||||
expect(Worker.prototype.terminate.calls.length).toBe 1
|
||||
|
||||
describe "Snippet body parser", ->
|
||||
describe "snippet body parser", ->
|
||||
it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", ->
|
||||
bodyTree = snippets.getBodyParser().parse """
|
||||
the quick brown $1fox ${2:jumped ${3:over}
|
||||
@@ -328,3 +310,16 @@ describe "Snippets extension", ->
|
||||
{ index: 4, content: ["lazy"] },
|
||||
" dog"
|
||||
]
|
||||
|
||||
it "removes interpolated variables in placeholder text (we don't currently support it)", ->
|
||||
bodyTree = snippets.getBodyParser().parse """
|
||||
module ${1:ActiveRecord::${TM_FILENAME/(?:\\A|_)([A-Za-z0-9]+)(?:\\.rb)?/(?2::\\u$1)/g}}
|
||||
"""
|
||||
|
||||
expect(bodyTree).toEqual [
|
||||
"module ",
|
||||
{
|
||||
"index": 1,
|
||||
"content": ["ActiveRecord::", ""]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -2,10 +2,6 @@ bodyContent = content:(tabStop / bodyContentText)* { return content; }
|
||||
bodyContentText = text:bodyContentChar+ { return text.join(''); }
|
||||
bodyContentChar = !tabStop char:. { return char; }
|
||||
|
||||
placeholderContent = content:(tabStop / placeholderContentText)* { return content; }
|
||||
placeholderContentText = text:placeholderContentChar+ { return text.join(''); }
|
||||
placeholderContentChar = !tabStop char:[^}] { return char; }
|
||||
|
||||
tabStop = simpleTabStop / tabStopWithPlaceholder
|
||||
simpleTabStop = '$' index:[0-9]+ {
|
||||
return { index: parseInt(index), content: [] };
|
||||
@@ -13,3 +9,13 @@ simpleTabStop = '$' index:[0-9]+ {
|
||||
tabStopWithPlaceholder = '${' index:[0-9]+ ':' content:placeholderContent '}' {
|
||||
return { index: parseInt(index), content: content };
|
||||
}
|
||||
placeholderContent = content:(tabStop / variable / placeholderContentText)* { return content; }
|
||||
placeholderContentText = text:placeholderContentChar+ { return text.join(''); }
|
||||
placeholderContentChar = !tabStop !variable char:[^}] { return char; }
|
||||
|
||||
variable = '${' variableContent '}' {
|
||||
return ''; // we eat variables and do nothing with them for now
|
||||
}
|
||||
variableContent = content:(variable / variableContentText)* { return content; }
|
||||
variableContentText = text:variableContentChar+ { return text.join(''); }
|
||||
variableContentChar = !variable char:[^}] { return char; }
|
||||
|
||||
Reference in New Issue
Block a user