fixing command duplication issue during suggestion

This commit is contained in:
Nate Stemen 2017-08-16 17:40:01 +01:00
parent 6e9b1c602b
commit f253b7e8cb
2 changed files with 92 additions and 94 deletions

View file

@ -1,75 +1,4 @@
define () ->
noArgumentCommands = [
'item', 'hline', 'lipsum', 'centering', 'noindent', 'textwidth', 'draw',
'maketitle', 'newpage', 'verb', 'bibliography', 'fi', 'hfill', 'par',
'in', 'sum', 'cdot', 'alpha', 'ldots', 'else', 'linewidth', 'left',
'right', 'today', 'clearpage', 'newline', 'endinput', 'mu',
'tableofcontents', 'vfill', 'bigskip', 'fill', 'cleardoublepage'
]
singleArgumentCommands = [
'chapter', 'usepackage', 'section', 'label', 'textbf', 'subsection',
'vspace', 'cite', 'textit', 'documentclass', 'includegraphics', 'input',
'emph','caption', 'ref', 'title', 'author', 'texttt', 'include',
'hspace', 'bibitem', 'url', 'large', 'subsubsection', 'textsc', 'date',
'footnote', 'small', 'thanks', 'underline', 'graphicspath', 'pageref',
'section*', 'subsection*', 'subsubsection*', 'sqrt', 'text',
'normalsize', 'Large', 'paragraph', 'pagestyle', 'thispagestyle',
'bibliographystyle'
]
doubleArgumentCommands = [
'newcommand', 'frac', 'renewcommand', 'setlength', 'href', 'newtheorem'
]
tripleArgumentCommands = [
'addcontentsline', 'newacronym', 'multicolumn'
]
special = ['LaTeX', 'TeX']
noArgumentCommands = for com in noArgumentCommands
{
caption: "\\#{com}"
snippet: "\\#{com}"
meta: "cmd"
}
singleArgumentCommands = for com in singleArgumentCommands
{
caption: "\\#{com}{}"
snippet: "\\#{com}{$1}"
meta: "cmd"
}
doubleArgumentCommands = for com in doubleArgumentCommands
{
caption: "\\#{com}{}{}"
snippet: "\\#{com}{$1}{$2}"
meta: "cmd"
}
tripleArgumentCommands = for com in tripleArgumentCommands
{
caption: "\\#{com}{}{}{}"
snippet: "\\#{com}{$1}{$2}{$3}"
meta: "cmd"
}
special = for cmd in special
if cmd == 'TeX'
{
caption: "\\TeX{}"
snippet: "\\TeX{}"
meta: "cmd"
}
else if com == 'LaTeX'
{
caption: "\\LaTeX{}"
snippet: "\\LaTeX{}"
meta: "cmd"
}
staticCommands = [].concat(
noArgumentCommands,
singleArgumentCommands,
doubleArgumentCommands,
tripleArgumentCommands,
special
)
environments = [
"abstract",
"align", "align*",
@ -178,9 +107,6 @@ define () ->
"""
}]
staticSnippets = staticSnippets.concat staticCommands
parseCustomEnvironments = (text) ->
re = /^\\newenvironment{(\w+)}.*$/gm
result = []
@ -192,7 +118,6 @@ define () ->
return result
return result
parseBeginCommands = (text) ->
re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm
result = []

View file

@ -1,4 +1,75 @@
define [], () ->
noArgumentCommands = [
'item', 'hline', 'lipsum', 'centering', 'noindent', 'textwidth', 'draw',
'maketitle', 'newpage', 'verb', 'bibliography', 'fi', 'hfill', 'par',
'in', 'sum', 'cdot', 'alpha', 'ldots', 'else', 'linewidth', 'left',
'right', 'today', 'clearpage', 'newline', 'endinput', 'mu',
'tableofcontents', 'vfill', 'bigskip', 'fill', 'cleardoublepage'
]
singleArgumentCommands = [
'chapter', 'usepackage', 'section', 'label', 'textbf', 'subsection',
'vspace', 'cite', 'textit', 'documentclass', 'includegraphics', 'input',
'emph','caption', 'ref', 'title', 'author', 'texttt', 'include',
'hspace', 'bibitem', 'url', 'large', 'subsubsection', 'textsc', 'date',
'footnote', 'small', 'thanks', 'underline', 'graphicspath', 'pageref',
'section*', 'subsection*', 'subsubsection*', 'sqrt', 'text',
'normalsize', 'Large', 'paragraph', 'pagestyle', 'thispagestyle',
'bibliographystyle'
]
doubleArgumentCommands = [
'newcommand', 'frac', 'renewcommand', 'setlength', 'href', 'newtheorem'
]
tripleArgumentCommands = [
'addcontentsline', 'newacronym', 'multicolumn'
]
special = ['LaTeX', 'TeX']
rawCommands = [].concat(
noArgumentCommands,
singleArgumentCommands,
doubleArgumentCommands,
tripleArgumentCommands,
special
)
noArgumentCommands = for cmd in noArgumentCommands
{
caption: "\\#{cmd}"
snippet: "\\#{cmd}"
meta: "cmd"
}
singleArgumentCommands = for cmd in singleArgumentCommands
{
caption: "\\#{cmd}{}"
snippet: "\\#{cmd}{$1}"
meta: "cmd"
}
doubleArgumentCommands = for cmd in doubleArgumentCommands
{
caption: "\\#{cmd}{}{}"
snippet: "\\#{cmd}{$1}{$2}"
meta: "cmd"
}
tripleArgumentCommands = for cmd in tripleArgumentCommands
{
caption: "\\#{cmd}{}{}{}"
snippet: "\\#{cmd}{$1}{$2}{$3}"
meta: "cmd"
}
special = for cmd in special
{
caption: "\\#{cmd}{}"
snippet: "\\#{cmd}{}"
meta: "cmd"
}
staticCommands = [].concat(
noArgumentCommands,
singleArgumentCommands,
doubleArgumentCommands,
tripleArgumentCommands,
special
)
class Parser
constructor: (@doc, @prefix) ->
@ -95,26 +166,28 @@ define [], () ->
commands = parser.parse()
completions = []
for command in commands
caption = "\\#{command[0]}"
score = if caption == prefix then 99 else 50
snippet = caption
i = 1
_.times command[1], () ->
snippet += "[${#{i}}]"
caption += "[]"
i++
_.times command[2], () ->
snippet += "{${#{i}}}"
caption += "{}"
i++
completions.push {
caption: caption
snippet: snippet
meta: "cmd"
score: score
}
if command[0] not in rawCommands
caption = "\\#{command[0]}"
score = if caption == prefix then 99 else 50
snippet = caption
i = 1
_.times command[1], () ->
snippet += "[${#{i}}]"
caption += "[]"
i++
_.times command[2], () ->
snippet += "{${#{i}}}"
caption += "{}"
i++
completions.push {
caption: caption
snippet: snippet
meta: "cmd"
score: score
}
completions = completions.concat staticCommands
callback null, completions
callback(null, completions)
loadCommandsFromDoc: (doc) ->
parser = new Parser(doc)