Parse existing begin commands too.

This commit is contained in:
Shane Kilkelly 2016-03-17 12:07:21 +00:00
parent eebd25351d
commit d655e99439

View file

@ -109,14 +109,28 @@ define () ->
return names
return names
BEGIN_COMMAND_REGEX = /^\\begin{(\w+)}.*$/gm
parseBeginCommandNames = (text) ->
names = []
iterations = 0
while match = BEGIN_COMMAND_REGEX.exec(text)
names.push match[1]
iterations += 1
if iterations >= 1000
return names
return names
class SnippetManager
getCompletions: (editor, session, pos, prefix, callback) ->
# console.log ">> get snippet completions", editor, session, pos, prefix
docText = session.getValue()
customEnvironmentNames = parseCustomEnvironmentNames(docText)
beginCommandNames = parseBeginCommandNames(docText)
# console.log customEnvironmentNames
parsedNames = _.union(customEnvironmentNames, beginCommandNames)
snippets = staticSnippets.concat(
customEnvironmentNames.map (name) ->
parsedNames.map (name) ->
{
caption: "\\begin{#{name}}..."
snippet: """
@ -125,7 +139,6 @@ define () ->
\\end{#{name}}
"""
meta: "env"
}
)
callback null, snippets