Skip to content

Commit 7857e75

Browse files
authored
Merge pull request #2873 from qtLex/fix/IllegalStateExceptionInCreateVariablesByName
Fix/illegal state exception in create variables by name
2 parents 76db08d + ed59d58 commit 7857e75

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/VariableSymbolComputer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.antlr.v4.runtime.tree.ParseTree;
3838
import org.antlr.v4.runtime.tree.TerminalNode;
3939
import org.eclipse.lsp4j.Range;
40+
import org.eclipse.lsp4j.SymbolKind;
4041

4142
import java.util.ArrayList;
4243
import java.util.Collections;
@@ -129,6 +130,11 @@ public ParseTree visitParam(BSLParser.ParamContext ctx) {
129130
return ctx;
130131
}
131132

133+
// При ошибках в разборе может получиться, что два параметра с одним именем в модуле
134+
if (currentMethod.getSymbolKind() == SymbolKind.Module && moduleVariables.containsKey(ctx.IDENTIFIER().getText())) {
135+
return ctx;
136+
}
137+
132138
var variable = VariableSymbol.builder()
133139
.name(ctx.IDENTIFIER().getText().intern())
134140
.scope(currentMethod)
@@ -141,7 +147,11 @@ public ParseTree visitParam(BSLParser.ParamContext ctx) {
141147
.build();
142148
variables.add(variable);
143149

144-
currentMethodVariables.put(ctx.IDENTIFIER().getText(), ctx.IDENTIFIER().getText());
150+
if (currentMethod.getSymbolKind() == SymbolKind.Module) {
151+
moduleVariables.put(ctx.IDENTIFIER().getText(), ctx.IDENTIFIER().getText());
152+
} else {
153+
currentMethodVariables.put(ctx.IDENTIFIER().getText(), ctx.IDENTIFIER().getText());
154+
}
145155
return ctx;
146156
}
147157

src/test/resources/references/ReferenceIndexFillerVariableTest.bsl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,34 @@
4848

4949
КонецФункции
5050

51+
#Если Клиент Тогда
52+
53+
Процедура Выполнить(Значение0)
54+
55+
Значение0 = 1;
56+
57+
Если Истина Тогда
58+
59+
Возврат 10;
60+
61+
КонецЕсли;
62+
63+
КонецПроцедуры
64+
65+
#Иначе
66+
67+
Функция Выполнить(Значение0)
68+
69+
Значение0 = 1;
70+
71+
Если Истина Тогда
72+
73+
Возврат 10;
74+
75+
КонецЕсли;
76+
77+
КонецФункции
78+
79+
#КонецЕсли
80+
5181
Метод(Модуль, Модуль2);

0 commit comments

Comments
 (0)