Skip to content

Commit 5e6cd8b

Browse files
Support constant operators symbol detection
Signed-off-by: PoorlyDefinedBehaviour <brunotj2015@hotmail.com>
1 parent be5077e commit 5e6cd8b

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

src/symbols/tlaSymbols.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ export class TlaDocumentSymbolsProvider implements vscode.DocumentSymbolProvider
306306
charIdx += COMMA_LEN;
307307
continue;
308308
}
309-
if (rest !== '' && !isCommentStart(rest)) {
309+
310+
// Given a constant operator like Foo(_, _, ...), match the parentheses and everything inside of it
311+
const isConstantOperator = /^(\(((\s*_\s*,|\s*_\s*)\s*)+\))$/.test(rest);
312+
313+
if (rest !== '' && !isCommentStart(rest) &&!isConstantOperator) {
310314
module.simpleListSymbolKind = undefined;
311315
return false;
312316
}
@@ -317,7 +321,11 @@ export class TlaDocumentSymbolsProvider implements vscode.DocumentSymbolProvider
317321
new vscode.Location(docUri, new vscode.Position(lineNum, charIdx))
318322
));
319323
charIdx += name.length + spaces.length + COMMA_LEN;
320-
if (rest !== '') {
324+
if (isConstantOperator) {
325+
// Skip '(...)' in constant operators e.g. Foo(_, _)
326+
charIdx += rest.length;
327+
}
328+
if (rest !== '' && !isConstantOperator) {
321329
module.simpleListSymbolKind = undefined;
322330
break; // There were no comma after the name
323331
}

tests/suite/symbols/tlaSymbols.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,84 @@ suite('TLA Symbols Provider Test Suite', () => {
5252
]);
5353
});
5454

55+
test('Finds items in CONSTANT operators', () => {
56+
const cases = [
57+
{
58+
input: [
59+
'CONSTANTS Baz(_)'
60+
],
61+
expected: [
62+
symConst('Baz', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10)))
63+
]
64+
},
65+
{
66+
input: [
67+
'CONSTANTS Baz( _ )'
68+
],
69+
expected: [
70+
symConst('Baz', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10)))
71+
]
72+
},
73+
{
74+
input: [
75+
'CONSTANTS Baz(_, _)'
76+
],
77+
expected: [
78+
symConst('Baz', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10)))
79+
]
80+
},
81+
{
82+
input: [
83+
'CONSTANTS Foo(_), Bar'
84+
],
85+
expected: [
86+
symConst('Foo', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10))),
87+
symConst('Bar', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 18)))
88+
]
89+
},
90+
{
91+
input: [
92+
'CONSTANTS Bar, Foo(_)'
93+
],
94+
expected: [
95+
symConst('Bar', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10))),
96+
symConst('Foo', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 18)))
97+
]
98+
},
99+
{
100+
input: [
101+
'CONSTANTS Foo(_, _), Bar'
102+
],
103+
expected: [
104+
symConst('Foo', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10))),
105+
symConst('Bar', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 20)))
106+
]
107+
},
108+
{
109+
input: [
110+
'CONSTANTS Bar, Foo(_, _)'
111+
],
112+
expected: [
113+
symConst('Bar', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10))),
114+
symConst('Foo', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 18)))
115+
]
116+
},
117+
{
118+
input: [
119+
'CONSTANTS Bar, Foo(_, _, _), Baz'
120+
],
121+
expected: [
122+
symConst('Bar', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 10))),
123+
symConst('Foo', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 18))),
124+
symConst('Baz', ROOT_CONTAINER_NAME, loc(doc.uri, pos(0, 29))),
125+
]
126+
}
127+
];
128+
for (const {input, expected} of cases) {
129+
return assertSymbols(doc, input, expected);
130+
}
131+
});
132+
55133
test('Finds items in VARIABLE', () => {
56134
return assertSymbols(doc, [
57135
'VARIABLE Foo, Bar'

0 commit comments

Comments
 (0)