Skip to content

Commit f1c47cc

Browse files
committed
TypeName в документКонтекст
1 parent 7b9fbaf commit f1c47cc

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class DocumentContext {
114114

115115
private final Lazy<String[]> contentList = new Lazy<>(this::computeContentList, computeLock);
116116
private final Lazy<ModuleType> moduleType = new Lazy<>(this::computeModuleType, computeLock);
117+
private final Lazy<String> typeName = new Lazy<>(this::computeTypeName, computeLock);
117118
private final Lazy<Map<SupportConfiguration, SupportVariant>> supportVariants
118119
= new Lazy<>(this::computeSupportVariants, computeLock);
119120
private final Lazy<ComplexityData> cognitiveComplexityData
@@ -234,6 +235,10 @@ public ModuleType getModuleType() {
234235
return moduleType.getOrCompute();
235236
}
236237

238+
public String getTypeName() {
239+
return typeName.getOrCompute();
240+
}
241+
237242
public Map<SupportConfiguration, SupportVariant> getSupportVariants() {
238243
return supportVariants.getOrCompute();
239244
}
@@ -342,12 +347,16 @@ private SymbolTree computeSymbolTree() {
342347
return new SymbolTreeComputer(this).compute();
343348
}
344349

345-
346350
private ModuleType computeModuleType() {
347351

348352
return new ModuleTypeComputer(this).computeModuleType();
349353
}
350354

355+
private String computeTypeName() {
356+
357+
return new ModuleTypeComputer(this).computeTypeName();
358+
}
359+
351360
private Map<SupportConfiguration, SupportVariant> computeSupportVariants() {
352361
return context.getConfiguration().getModuleSupport(uri);
353362
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2525
import com.github._1c_syntax.bsl.languageserver.context.FileType;
2626
import com.github._1c_syntax.bsl.languageserver.context.ModuleType;
27+
import org.apache.commons.io.FilenameUtils;
28+
29+
import java.nio.file.Paths;
2730

2831
public class ModuleTypeComputer {
2932

@@ -62,5 +65,14 @@ private ModuleType computeOS() {
6265
return ModuleType.UNKNOWN;
6366
}
6467
}
68+
69+
public String computeTypeName() {
70+
if (documentContext.getModuleType() == ModuleType.Module
71+
|| documentContext.getModuleType() == ModuleType.Class) {
72+
// to do убрать FilenameUtils
73+
return FilenameUtils.getBaseName(Paths.get(documentContext.getUri()).toString());
74+
}
75+
return "";
76+
}
6577
}
6678

src/test/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContextTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,17 @@ void testEOF() {
239239
assertThat(lastToken.getType()).isEqualTo(Lexer.EOF);
240240
assertThat(lastToken.getChannel()).isEqualTo(Lexer.HIDDEN);
241241
}
242+
243+
@Test
244+
void testOSTypes(){
245+
246+
// given
247+
var documentContext = getDocumentContext("./src/test/resources/metadata/oscript/Классы/ТестовыйКласс.os");
248+
// when
249+
var typeName = documentContext.getTypeName();
250+
// then
251+
assertThat(typeName).isEqualTo("ТестовыйКласс");
252+
253+
}
254+
242255
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Переменная = Новый ТестовыйКласс;
3+
4+
Другая = 1 + Переменная;

src/test/resources/metadata/oscript/Классы/ТестовыйКласс.os

Whitespace-only changes.

src/test/resources/metadata/oscript/Модули/ТестовыйМодуль.os

Whitespace-only changes.

0 commit comments

Comments
 (0)