Skip to content

Commit 1ad7e61

Browse files
authored
feat(glossaries): user glossary commands (#1475)
Allows user-defined glossary reference commands, as a server config. This is stored under the 'experimental.glossaryReferenceCommands' key in the server configuration (from the texlab crate, file server/options.rs) Changed crates/files: texlab/src/server/options.rs: new 'glossary_reference_commands' key as a vector in the ExperimentalOptions struct ; texlab/src/util/from_proto.rs: extend the SyntaxConfig of the server configuration using the new 'glossary_reference_commands' key ; parser/src/config.rs: new 'glossary_reference_commands' key in the SyntaxConfig structure + the glossary reference commands from the latex/lexer/commands.rs file in the same crate have been moved to a static array here ; parser/src/latex/lexer/commands.rs: the classify() command now looks in the new 'config.glossary_reference_commands' for glossary references ;
1 parent cdbe6a8 commit 1ad7e61

File tree

5 files changed

+88
-9
lines changed

5 files changed

+88
-9
lines changed

crates/completion/src/tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,3 +2341,31 @@ fn test_custom_label_multiple_prefix_ref() {
23412341
"#]],
23422342
);
23432343
}
2344+
2345+
#[test]
2346+
fn test_custom_glossary_reference_command() {
2347+
let mut config = SyntaxConfig::default();
2348+
config.glossary_reference_commands.insert("glsed".to_string());
2349+
2350+
check_with_syntax_config(
2351+
config,
2352+
r#"
2353+
%! main.tex
2354+
\newglossaryentry{foo}{
2355+
name={Foo Bar Baz},
2356+
description={The trio of default variable names.}
2357+
}
2358+
2359+
\glsed{}
2360+
|"#,
2361+
expect![[r#"
2362+
[
2363+
GlossaryEntry(
2364+
GlossaryEntryData {
2365+
name: "foo",
2366+
},
2367+
),
2368+
]
2369+
"#]],
2370+
);
2371+
}

crates/parser/src/config.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct SyntaxConfig {
88
pub enum_environments: FxHashSet<String>,
99
pub verbatim_environments: FxHashSet<String>,
1010
pub citation_commands: FxHashSet<String>,
11+
pub glossary_reference_commands: FxHashSet<String>,
1112
pub label_definition_commands: FxHashSet<String>,
1213
pub label_definition_prefixes: Vec<(String, String)>,
1314
pub label_reference_commands: FxHashSet<String>,
@@ -37,6 +38,11 @@ impl Default for SyntaxConfig {
3738
.map(ToString::to_string)
3839
.collect();
3940

41+
let glossary_reference_commands = DEFAULT_GLOSSARY_REFERENCE_COMMANDS
42+
.iter()
43+
.map(ToString::to_string)
44+
.collect();
45+
4046
let label_definition_commands = DEFAULT_LABEL_DEFINITION_COMMANDS
4147
.iter()
4248
.map(ToString::to_string)
@@ -69,6 +75,7 @@ impl Default for SyntaxConfig {
6975
enum_environments,
7076
verbatim_environments,
7177
citation_commands,
78+
glossary_reference_commands,
7279
label_definition_commands,
7380
label_definition_prefixes,
7481
label_reference_commands,
@@ -193,6 +200,52 @@ static DEFAULT_CITATION_COMMANDS: &[&str] = &[
193200
"citeA*",
194201
];
195202

203+
static DEFAULT_GLOSSARY_REFERENCE_COMMANDS: &[&str] = &[
204+
"gls",
205+
"Gls",
206+
"GLS",
207+
"glspl",
208+
"Glspl",
209+
"GLSpl",
210+
"glsdisp",
211+
"glslink",
212+
"glstext",
213+
"Glstext",
214+
"GLStext",
215+
"glsfirst",
216+
"Glsfirst",
217+
"GLSfirst",
218+
"glsplural",
219+
"Glsplural",
220+
"GLSplural",
221+
"glsfirstplural",
222+
"Glsfirstplural",
223+
"GLSfirstplural",
224+
"glsname",
225+
"Glsname",
226+
"GLSname",
227+
"glssymbol",
228+
"Glssymbol",
229+
"glsdesc",
230+
"Glsdesc",
231+
"GLSdesc",
232+
"glsuseri",
233+
"Glsuseri",
234+
"GLSuseri",
235+
"glsuserii",
236+
"Glsuserii",
237+
"glsuseriii",
238+
"glsuseriv",
239+
"Glsuseriv",
240+
"GLSuseriv",
241+
"glsuserv",
242+
"Glsuserv",
243+
"GLSuserv",
244+
"glsuservi",
245+
"Glsuservi",
246+
"GLSuservi"
247+
];
248+
196249
static DEFAULT_LABEL_DEFINITION_COMMANDS: &[&str] = &["label", "zlabel"];
197250

198251
static DEFAULT_LABEL_DEFINITION_PREFIXES: &[(&str, &str)] = &[];

crates/parser/src/latex/lexer/commands.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ pub fn classify(name: &str, config: &SyntaxConfig) -> CommandName {
5050
| "DeclareCommandCopy" => CommandName::NewCommandDefinition,
5151
"DeclareMathOperator" | "DeclareMathOperator*" => CommandName::MathOperator,
5252
"newglossaryentry" => CommandName::GlossaryEntryDefinition,
53-
"gls" | "Gls" | "GLS" | "glspl" | "Glspl" | "GLSpl" | "glsdisp" | "glslink" | "glstext"
54-
| "Glstext" | "GLStext" | "glsfirst" | "Glsfirst" | "GLSfirst" | "glsplural"
55-
| "Glsplural" | "GLSplural" | "glsfirstplural" | "Glsfirstplural" | "GLSfirstplural"
56-
| "glsname" | "Glsname" | "GLSname" | "glssymbol" | "Glssymbol" | "glsdesc" | "Glsdesc"
57-
| "GLSdesc" | "glsuseri" | "Glsuseri" | "GLSuseri" | "glsuserii" | "Glsuserii"
58-
| "glsuseriii" | "glsuseriv" | "Glsuseriv" | "GLSuseriv" | "glsuserv" | "Glsuserv"
59-
| "GLSuserv" | "glsuservi" | "Glsuservi" | "GLSuservi" => {
60-
CommandName::GlossaryEntryReference
61-
}
6253
"newacronym" | "newacro" | "acrodef" | "acro" | "newacroindefinite"
6354
| "acrodefindefinite" | "acroindefinite" | "acroplural" | "newacroplural"
6455
| "acrodefplural" => CommandName::AcronymDefinition,
@@ -100,6 +91,7 @@ pub fn classify(name: &str, config: &SyntaxConfig) -> CommandName {
10091
"numberline" => CommandName::TocNumberLine,
10192

10293
_ if config.citation_commands.contains(name) => CommandName::Citation,
94+
_ if config.glossary_reference_commands.contains(name) => CommandName::GlossaryEntryReference,
10395
_ if config.label_definition_commands.contains(name) => CommandName::LabelDefinition,
10496
_ if config.label_reference_commands.contains(name) => CommandName::LabelReference,
10597
_ if config.label_reference_range_commands.contains(name) => {

crates/texlab/src/server/options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub struct ExperimentalOptions {
156156
pub enum_environments: Vec<String>,
157157
pub verbatim_environments: Vec<String>,
158158
pub citation_commands: Vec<String>,
159+
pub glossary_reference_commands: Vec<String>,
159160
pub label_definition_commands: Vec<String>,
160161
pub label_definition_prefixes: Vec<(String, String)>,
161162
pub label_reference_commands: Vec<String>,

crates/texlab/src/util/from_proto.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ pub fn config(value: Options) -> Config {
387387
.citation_commands
388388
.extend(value.experimental.citation_commands);
389389

390+
config
391+
.syntax
392+
.glossary_reference_commands
393+
.extend(value.experimental.glossary_reference_commands);
394+
390395
config
391396
.syntax
392397
.label_definition_commands

0 commit comments

Comments
 (0)