From 707b0585c6df96acfc8a57b9ef620f083c7e098c Mon Sep 17 00:00:00 2001 From: James Yu Date: Wed, 26 Jun 2024 15:42:48 +0100 Subject: [PATCH] Fix #4303 Support new command macros by etoolbox --- src/completion/completer/macro.ts | 4 ++-- src/completion/completer/reference.ts | 3 ++- src/parse/newcommandfinder.ts | 4 ++-- src/parse/parser/unified-defs.ts | 29 +++++++++++++++------------ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/completion/completer/macro.ts b/src/completion/completer/macro.ts index 6a7fb266b..0f63d5725 100644 --- a/src/completion/completer/macro.ts +++ b/src/completion/completer/macro.ts @@ -221,7 +221,7 @@ function parseAst(node: Ast.Node, filePath: string, defined?: Set): CmdE let name = '' let args = '' if (node.type === 'macro' && - ['renewcommand', 'newcommand'].includes(node.content) && + ['renewcommand', 'newcommand', 'newrobustcmd', 'renewrobustcmd'].includes(node.content) && node.args?.[2]?.content?.[0]?.type === 'macro') { // \newcommand{\fix}[3][]{\chdeleted{#2}\chadded[comment={#1}]{#3}} // \newcommand\WARNING{\textcolor{red}{WARNING}} @@ -243,7 +243,7 @@ function parseAst(node: Ast.Node, filePath: string, defined?: Set): CmdE args = (node.args?.[2].openMark === '[' ? '[]' : '{}') + '{}'.repeat(parseInt(node.args?.[1].content?.[0].content) - 1) } } else if (node.type === 'macro' && - ['providecommand', 'DeclareMathOperator', 'DeclareRobustCommand'].includes(node.content) && + ['providecommand', 'providerobustcmd', 'DeclareMathOperator', 'DeclareRobustCommand'].includes(node.content) && node.args?.[1]?.content?.[0]?.type === 'macro') { found = true name = node.args[1].content[0].content diff --git a/src/completion/completer/reference.ts b/src/completion/completer/reference.ts index 04b00eeae..a43cc5ba1 100644 --- a/src/completion/completer/reference.ts +++ b/src/completion/completer/reference.ts @@ -136,7 +136,8 @@ function parseAst(node: Ast.Node, nodeStack: Ast.Node[], filePath: string, lines ['renewcommand', 'newcommand', 'providecommand', 'DeclareMathOperator', 'renewenvironment', 'newenvironment', 'NewDocumentCommand', 'RenewDocumentCommand', 'ProvideDocumentCommand', 'DeclareDocumentCommand', 'NewDocumentEnvironment', 'RenewDocumentEnvironment', 'ProvideDocumentEnvironment', 'DeclareDocumentEnvironment', - 'NewExpandableDocumentCommand', 'RenewExpandableDocumentCommand', 'ProvideExpandableDocumentCommand', 'DeclareExpandableDocumentCommand' + 'NewExpandableDocumentCommand', 'RenewExpandableDocumentCommand', 'ProvideExpandableDocumentCommand', 'DeclareExpandableDocumentCommand', + 'newrobustcmd', 'renewrobustcmd', 'providerobustcmd' ].includes(node.content)) { // Do not scan labels inside \newcommand, \newenvironment & co return [] diff --git a/src/parse/newcommandfinder.ts b/src/parse/newcommandfinder.ts index da3cf8d6d..829aa231b 100644 --- a/src/parse/newcommandfinder.ts +++ b/src/parse/newcommandfinder.ts @@ -41,14 +41,14 @@ function parseAst(content: string, node: Ast.Node): string[] { // \newcommand{\fix}[3][]{\chdeleted{#2}\chadded[comment={#1}]{#3}} // \newcommand\WARNING{\textcolor{red}{WARNING}} const isNewCommand = node.type === 'macro' && - ['renewcommand', 'newcommand'].includes(node.content) && + ['newcommand', 'renewcommand', 'newrobustcmd', 'renewrobustcmd'].includes(node.content) && node.args?.[2]?.content?.[0]?.type === 'macro' // \DeclarePairedDelimiterX\braketzw[2]{\langle}{\rangle}{#1\,\delimsize\vert\,\mathopen{}#2} const isDeclarePairedDelimiter = node.type === 'macro' && ['DeclarePairedDelimiter', 'DeclarePairedDelimiterX', 'DeclarePairedDelimiterXPP'].includes(node.content) && node.args?.[0]?.content?.[0]?.type === 'macro' const isProvideCommand = node.type === 'macro' && - ['providecommand', 'DeclareMathOperator', 'DeclareRobustCommand'].includes(node.content) && + ['providecommand', 'providerobustcmd', 'DeclareMathOperator', 'DeclareRobustCommand'].includes(node.content) && node.args?.[1]?.content?.[0]?.type === 'macro' if (isNewCommand || isDeclarePairedDelimiter || isProvideCommand) { macros.push( diff --git a/src/parse/parser/unified-defs.ts b/src/parse/parser/unified-defs.ts index ee9643205..45df11c22 100644 --- a/src/parse/parser/unified-defs.ts +++ b/src/parse/parser/unified-defs.ts @@ -16,21 +16,24 @@ const MACROS: MacroInfoRecord = { subinputfrom: { signature: 'm m' }, subincludefrom: { signature: 'm m' }, // \label{some-label} - linelabel: { signature: 'o m'}, + linelabel: { signature: 'o m' }, // \newglossaryentry{vscode}{name=VSCode, description=Editor} - newglossaryentry: { signature: 'm m'}, - provideglossaryentry: { signature: 'm m'}, + newglossaryentry: { signature: 'm m' }, + provideglossaryentry: { signature: 'm m' }, // \newacronym[optional parameters]{lw}{LW}{LaTeX Workshop} - longnewglossaryentry: { signature: 'o m m m'}, - longprovideglossaryentry: { signature: 'o m m m'}, - newacronym: { signature: 'o m m m'}, - newabbreviation: { signature: 'o m m m'}, - newabbr: { signature: 'o m m m'}, - DeclareRobustCommand: { signature: 's +m o +o +m'}, - DeclareMathOperator: { signature: 's m m'}, - DeclarePairedDelimiter: { signature: 'm m m'}, - DeclarePairedDelimiterX: { signature: 'm o m m m'}, - DeclarePairedDelimiterXPP: { signature: 'm o m m m m m'}, + longnewglossaryentry: { signature: 'o m m m' }, + longprovideglossaryentry: { signature: 'o m m m' }, + newacronym: { signature: 'o m m m' }, + newabbreviation: { signature: 'o m m m' }, + newabbr: { signature: 'o m m m' }, + newrobustcmd: { signature: 's d<> +m o +o +m' }, + renewrobustcmd: { signature: 's d<> +m o +o +m' }, + providerobustcmd: { signature: 's +m o +o +m' }, + DeclareRobustCommand: { signature: 's +m o +o +m' }, + DeclareMathOperator: { signature: 's m m' }, + DeclarePairedDelimiter: { signature: 'm m m' }, + DeclarePairedDelimiterX: { signature: 'm o m m m' }, + DeclarePairedDelimiterXPP: { signature: 'm o m m m m m' }, } const ENVS: EnvInfoRecord = {}