Skip to content

Commit 1f4f4eb

Browse files
committed
Тип в VariableSymbol
1 parent 8b88ec9 commit 1f4f4eb

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,24 @@ public ParseTree visitParam(BSLParser.ParamContext ctx) {
146146
}
147147

148148
@Override
149-
public ParseTree visitLValue(BSLParser.LValueContext ctx) {
149+
public ParseTree visitAssignment(BSLParser.AssignmentContext ctx) {
150+
151+
var lValue = ctx.lValue();
152+
150153
if (
151-
ctx.getChildCount() > 1
152-
|| currentMethodVariables.containsKey(ctx.getText())
153-
|| moduleVariables.containsKey(ctx.getText())
154+
lValue.getChildCount() > 1
155+
|| currentMethodVariables.containsKey(lValue.getText())
156+
|| moduleVariables.containsKey(lValue.getText())
154157
) {
155-
return ctx;
158+
return lValue;
156159
}
157160

158-
updateVariablesCache(ctx.IDENTIFIER(), createDescription(ctx));
161+
var typeName = "";
162+
var newCtx = Trees.getNextNode(ctx.expression(), ctx.expression(), BSLParser.RULE_newExpression);
163+
if (newCtx instanceof BSLParser.NewExpressionContext) {
164+
typeName = ((BSLParser.NewExpressionContext) newCtx).typeName().getText();
165+
}
166+
updateVariablesCache(lValue.IDENTIFIER(), createDescription(lValue), typeName);
159167
return ctx;
160168
}
161169

@@ -239,7 +247,11 @@ private Optional<VariableDescription> createDescription(BSLParserRuleContext ctx
239247

240248
}
241249

242-
private void updateVariablesCache(TerminalNode node, Optional<VariableDescription> description) {
250+
private void updateVariablesCache(TerminalNode identifier, Optional<VariableDescription> description) {
251+
updateVariablesCache(identifier, description, "");
252+
}
253+
254+
private void updateVariablesCache(TerminalNode node, Optional<VariableDescription> description, String type) {
243255
var variable = VariableSymbol.builder()
244256
.name(node.getText().intern())
245257
.owner(documentContext)
@@ -249,6 +261,7 @@ private void updateVariablesCache(TerminalNode node, Optional<VariableDescriptio
249261
.kind(VariableKind.DYNAMIC)
250262
.scope(currentMethod)
251263
.description(description)
264+
.type(type)
252265
.build();
253266
variables.add(variable);
254267

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/VariableSymbol.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public class VariableSymbol implements SourceDefinedSymbol, Exportable, Describa
9696
*/
9797
Optional<VariableDescription> description;
9898

99+
@Builder.Default
100+
String type = "";
101+
99102
@Override
100103
public void accept(SymbolTreeVisitor visitor) {
101104
visitor.visitVariable(this);

src/test/java/com/github/_1c_syntax/bsl/languageserver/context/computer/VariableSymbolTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,13 @@ void testVariableKind() {
144144

145145
}
146146

147+
@Test
148+
void testVariableNewOS() {
149+
150+
documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/variableSymbolTest.os");
151+
variableSymbols = documentContext.getSymbolTree().getVariables();
152+
153+
assertThat(variableSymbols.get(0).getType()).isEqualTo("МойКласс");
154+
}
155+
147156
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Процедура В()
2+
А = Новый МойКласс();
3+
КонецПроцедуры

0 commit comments

Comments
 (0)