Skip to content

Commit c251a79

Browse files
committed
Наивная реализация разделения символов переменных на int и short варианты
1 parent 3a455a9 commit c251a79

File tree

6 files changed

+595
-129
lines changed

6 files changed

+595
-129
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ plugins {
2222
id("ru.vyarus.pom") version "2.2.1"
2323
id("com.gorylenko.gradle-git-properties") version "2.4.1"
2424
id("io.codearte.nexus-staging") version "0.30.0"
25+
id("me.champeau.jmh") version "0.6.6"
2526
}
2627

2728
repositories {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2022
5+
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.context.symbol;
23+
24+
import com.github._1c_syntax.bsl.languageserver.context.symbol.variable.VariableKind;
25+
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
26+
import org.eclipse.lsp4j.Range;
27+
import org.eclipse.lsp4j.SymbolKind;
28+
import org.openjdk.jmh.annotations.Benchmark;
29+
import org.openjdk.jmh.annotations.Fork;
30+
import org.openjdk.jmh.annotations.Level;
31+
import org.openjdk.jmh.annotations.Scope;
32+
import org.openjdk.jmh.annotations.Setup;
33+
import org.openjdk.jmh.annotations.State;
34+
import org.openjdk.jmh.annotations.Warmup;
35+
import org.openjdk.jmh.infra.Blackhole;
36+
37+
import java.util.Optional;
38+
import java.util.Random;
39+
40+
@State(Scope.Benchmark)
41+
public class VariableSymbolCreate {
42+
43+
private static final Random RANDOM = new Random();
44+
45+
private Range range;
46+
private Range variableNameRange;
47+
48+
// @Param("shortBased")
49+
boolean shortBased;
50+
51+
@Setup(Level.Invocation)
52+
public void setup() {
53+
var line = RANDOM.nextInt(60_000);
54+
range = Ranges.create(line, 0, line, 1);
55+
56+
line = RANDOM.nextInt(60_000);
57+
variableNameRange = Ranges.create(line, 0, line, 1);
58+
59+
var start = range.getStart();
60+
var end = range.getEnd();
61+
var variableNameRangeStart = variableNameRange.getStart();
62+
var variableNameRangeEnd = variableNameRange.getEnd();
63+
64+
shortBased = start.getLine() <= Short.MAX_VALUE
65+
&& end.getLine() <= Short.MAX_VALUE
66+
&& start.getCharacter() <= Short.MAX_VALUE
67+
&& end.getCharacter() <= Short.MAX_VALUE
68+
&& variableNameRangeStart.getLine() <= Short.MAX_VALUE
69+
&& variableNameRangeStart.getCharacter() <= Short.MAX_VALUE
70+
&& variableNameRangeEnd.getCharacter() <= Short.MAX_VALUE;
71+
}
72+
73+
@Benchmark
74+
@Fork(value = 2, warmups = 2)
75+
@Warmup(time = 5, iterations = 3)
76+
public void createVariableSymbols(Blackhole bh) {
77+
var test = getVariableSymbolBuilder().build();
78+
79+
bh.consume(test);
80+
}
81+
82+
@Benchmark
83+
@Fork(value = 2, warmups = 2)
84+
@Warmup(time = 5, iterations = 3)
85+
public void createVariableSymbolsInt(Blackhole bh) {
86+
var test = getVariableSymbolBuilder().buildInt();
87+
88+
bh.consume(test);
89+
}
90+
91+
private VariableSymbolBuilder getVariableSymbolBuilder() {
92+
return VariableSymbol.builder()
93+
.name("test")
94+
.owner(null)
95+
.range(range)
96+
.variableNameRange(variableNameRange)
97+
.export(true)
98+
.kind(VariableKind.MODULE)
99+
.symbolKind(SymbolKind.Variable)
100+
.description(Optional.empty())
101+
.scope(null);
102+
}
103+
104+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2022
5+
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.context.symbol;
23+
24+
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
25+
import com.github._1c_syntax.bsl.languageserver.context.symbol.variable.VariableDescription;
26+
import com.github._1c_syntax.bsl.languageserver.context.symbol.variable.VariableKind;
27+
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
28+
import lombok.AccessLevel;
29+
import lombok.Builder;
30+
import lombok.EqualsAndHashCode;
31+
import lombok.Getter;
32+
import lombok.Setter;
33+
import lombok.ToString;
34+
import lombok.Value;
35+
import lombok.experimental.NonFinal;
36+
import org.eclipse.lsp4j.Range;
37+
import org.eclipse.lsp4j.SymbolKind;
38+
39+
import java.util.Collections;
40+
import java.util.List;
41+
import java.util.Optional;
42+
43+
@Value
44+
@NonFinal
45+
@Builder
46+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
47+
@ToString(exclude = {"children", "parent"})
48+
public class IntBasedVariableSymbol implements VariableSymbol {
49+
50+
/**
51+
* Имя переменной.
52+
*/
53+
@EqualsAndHashCode.Include
54+
String name;
55+
56+
/**
57+
* Область доступности символа. Метод или модуль.
58+
*/
59+
SourceDefinedSymbol scope;
60+
61+
/**
62+
* Тип символа. По умолчанию переменная.
63+
*/
64+
@Builder.Default
65+
byte symbolKind = (byte) SymbolKind.Variable.ordinal();
66+
67+
/**
68+
* Файл в котором располагается переменная.
69+
*/
70+
@EqualsAndHashCode.Include
71+
DocumentContext owner;
72+
73+
@Getter(AccessLevel.NONE)
74+
int startLine;
75+
@Getter(AccessLevel.NONE)
76+
int startCharacter;
77+
@Getter(AccessLevel.NONE)
78+
int endLine;
79+
@Getter(AccessLevel.NONE)
80+
int endCharacter;
81+
82+
@Getter(AccessLevel.NONE)
83+
int variableNameLine;
84+
@Getter(AccessLevel.NONE)
85+
int variableNameStartCharacter;
86+
@Getter(AccessLevel.NONE)
87+
int variableNameEndCharacter;
88+
89+
@Getter
90+
@Setter
91+
@Builder.Default
92+
@NonFinal
93+
Optional<SourceDefinedSymbol> parent = Optional.empty();
94+
95+
@Builder.Default
96+
List<SourceDefinedSymbol> children = Collections.emptyList();
97+
98+
/**
99+
* Тип переменной.
100+
*/
101+
byte kind;
102+
103+
/**
104+
* Признак экспортной переменной.
105+
*/
106+
boolean export;
107+
108+
/**
109+
* Описание переменной.
110+
*/
111+
Optional<VariableDescription> description;
112+
113+
public SymbolKind getSymbolKind() {
114+
return SymbolKind.values()[symbolKind];
115+
}
116+
117+
@Override
118+
public VariableKind getKind() {
119+
return VariableKind.values()[kind];
120+
}
121+
122+
@Override
123+
public Range getRange() {
124+
return Ranges.create(startLine, startCharacter, endLine, endCharacter);
125+
}
126+
127+
@Override
128+
@EqualsAndHashCode.Include
129+
public Range getVariableNameRange() {
130+
return Ranges.create(
131+
variableNameLine,
132+
variableNameStartCharacter,
133+
variableNameLine,
134+
variableNameEndCharacter
135+
);
136+
}
137+
138+
@Override
139+
public void accept(SymbolTreeVisitor visitor) {
140+
visitor.visitVariable(this);
141+
}
142+
143+
@Override
144+
public Range getSelectionRange() {
145+
return getVariableNameRange();
146+
}
147+
148+
}

0 commit comments

Comments
 (0)