only suggest one document environment in project

This commit is contained in:
Nate Stemen 2018-06-05 10:08:27 -04:00
parent 63482e0ea0
commit 863128a030
2 changed files with 29 additions and 5 deletions

View file

@ -34,8 +34,7 @@ define [
enableLiveAutocompletion: false
})
commandCompleter = new CommandManager(@metadataManager)
CommandCompleter = new CommandManager(@metadataManager)
SnippetCompleter = new EnvironmentManager()
PackageCompleter = new PackageManager(@metadataManager, Helpers)
@ -153,7 +152,7 @@ define [
callback null, result
@editor.completers = [
commandCompleter
CommandCompleter
SnippetCompleter
PackageCompleter
ReferencesCompleter

View file

@ -23,7 +23,7 @@ define () ->
"thebibliography"
]
environmentNames = snippetNames.concat environments
environmentNames = snippetNames.concat(environments)
staticSnippets = for env in environments
{
@ -122,6 +122,18 @@ define () ->
meta: "env"
}]
documentSnippet = {
caption: "\\begin{document}..."
snippet: """
\\begin{document}
$1
\\end{document}
"""
meta: "env"
}
staticSnippets.push(documentSnippet)
parseCustomEnvironments = (text) ->
re = /^\\newenvironment{(\w+)}.*$/gm
result = []
@ -138,18 +150,31 @@ define () ->
result = []
iterations = 0
while match = re.exec(text)
if match[1] not in environmentNames
if match[1] not in environmentNames and match[1] != "document"
result.push {name: match[1], whitespace: match[2]}
iterations += 1
if iterations >= 1000
return result
return result
hasDocumentEnvironment = (text) ->
re = /^\\begin{document}/m
envs = []
iterations = 0
return re.exec(text) != null
class EnvironmentManager
getCompletions: (editor, session, pos, prefix, callback) ->
docText = session.getValue()
customEnvironments = parseCustomEnvironments(docText)
beginCommands = parseBeginCommands(docText)
if hasDocumentEnvironment(docText)
ind = staticSnippets.indexOf(documentSnippet)
if ind != -1
staticSnippets.splice(ind, 1)
else
staticSnippets.push documentSnippet
parsedItemsMap = {}
for environment in customEnvironments
parsedItemsMap[environment.name] = environment