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 () -> 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 = [ environments = [
"abstract", "abstract",
"align", "align*", "align", "align*",
@ -178,9 +107,6 @@ define () ->
""" """
}] }]
staticSnippets = staticSnippets.concat staticCommands
parseCustomEnvironments = (text) -> parseCustomEnvironments = (text) ->
re = /^\\newenvironment{(\w+)}.*$/gm re = /^\\newenvironment{(\w+)}.*$/gm
result = [] result = []
@ -192,7 +118,6 @@ define () ->
return result return result
return result return result
parseBeginCommands = (text) -> parseBeginCommands = (text) ->
re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm re = /^\\begin{(\w+)}.*\n([\t ]*).*$/gm
result = [] result = []

View file

@ -1,4 +1,75 @@
define [], () -> 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 class Parser
constructor: (@doc, @prefix) -> constructor: (@doc, @prefix) ->
@ -95,6 +166,7 @@ define [], () ->
commands = parser.parse() commands = parser.parse()
completions = [] completions = []
for command in commands for command in commands
if command[0] not in rawCommands
caption = "\\#{command[0]}" caption = "\\#{command[0]}"
score = if caption == prefix then 99 else 50 score = if caption == prefix then 99 else 50
snippet = caption snippet = caption
@ -113,8 +185,9 @@ define [], () ->
meta: "cmd" meta: "cmd"
score: score score: score
} }
completions = completions.concat staticCommands
callback null, completions callback(null, completions)
loadCommandsFromDoc: (doc) -> loadCommandsFromDoc: (doc) ->
parser = new Parser(doc) parser = new Parser(doc)