Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/os class module type #3113

Draft
wants to merge 23 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8b88ec9
Свой ModuleType
asosnoviy Jun 19, 2022
1f4f4eb
Тип в VariableSymbol
asosnoviy Jun 19, 2022
7b9fbaf
Ховер типа переменной
asosnoviy Jun 20, 2022
f1c47cc
TypeName в документКонтекст
asosnoviy Jun 20, 2022
906a841
Переход к модулю класса
asosnoviy Jun 20, 2022
3256a32
Переход к модулю
asosnoviy Jun 20, 2022
8254cfa
npe fix
asosnoviy Jun 21, 2022
0196b26
Игры с кириличискими путями
asosnoviy Jun 21, 2022
aea805f
bump libraries
theshadowco Mar 28, 2023
c5b8dd5
Merge remote-tracking branch 'origin/develop' into feature/osClassMod…
theshadowco Mar 28, 2023
9483ffc
микрофиксы
theshadowco Mar 28, 2023
4058a27
Merge remote-tracking branch 'origin/develop' into feature/osClassMod…
asosnoviy Jul 26, 2023
c12af1d
Заглушка на неожиданный null
asosnoviy Jul 28, 2023
5e33760
не знаю что это
asosnoviy Jul 28, 2023
7992f30
rebase и восстановил работоспособность костылем
theshadowco Dec 26, 2023
fee008e
Откат ошибок ребейза
nixel2007 Dec 26, 2023
fdff4f1
Вынес логику работы с DocumentState в публичный интерфейс, рефакторин…
nixel2007 Dec 26, 2023
2d30dca
Merge branch 'develop' into feature/osClassModuleType
nixel2007 Dec 26, 2023
d69dde6
TODO + License
nixel2007 Dec 26, 2023
863d672
Уточнен состав референса для модулей и классов оскрипта
nixel2007 Jan 3, 2024
f51c2f0
Merge branch 'develop' into feature/osClassModuleType
nixel2007 Jan 3, 2024
040cd86
Happy new year
nixel2007 Jan 3, 2024
137731f
Merge branch 'develop' into feature/osClassModuleType
nixel2007 Apr 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class BSLLanguageServer implements LanguageServer, ProtocolExtension {
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {

clientCapabilitiesHolder.setCapabilities(params.getCapabilities());

setConfigurationRoot(params);

var factory = new NamedForkJoinWorkerThreadFactory("populate-context-");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void onDestroy() {
}

@Override
public CompletableFuture<Either<List<? extends SymbolInformation>,List<? extends WorkspaceSymbol>>> symbol(WorkspaceSymbolParams params) {
public CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> symbol(WorkspaceSymbolParams params) {
return CompletableFuture.supplyAsync(
() -> Either.forRight(symbolProvider.getSymbols(params)),
executorService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void addStatement(BSLParserRuleContext statement) {

@Override
public Optional<BSLParserRuleContext> getAst() {
if(statements.isEmpty()) {
if (statements.isEmpty()) {
return super.getAst();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CfgEdge walkNext(CfgEdgeType edgeType) {
.filter(x -> x.getType() == edgeType)
.findAny();

if(edgeOrNot.isPresent()) {
if (edgeOrNot.isPresent()) {
currentNode = graph.getEdgeTarget(edgeOrNot.get());
return edgeOrNot.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private List<File> findFilesForFormatting(String[] filePaths) {
continue;
}

if(srcDir.toFile().isDirectory()) {
if (srcDir.toFile().isDirectory()) {
files.addAll(FileUtils.listFiles(srcDir.toFile(), new String[]{"bsl", "os"}, true));
} else {
files.add(srcDir.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

import static com.github._1c_syntax.bsl.languageserver.providers.DiagnosticProvider.SOURCE;


@Component
public class DisableDiagnosticTriggeringSupplier implements CodeActionSupplier {

Expand Down Expand Up @@ -83,14 +82,14 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
.stream()
.filter(token -> token.getLine() == selectedLineNumber)
.max(Comparator.comparingInt(Token::getCharPositionInLine))
.ifPresent(token -> {
if (params.getRange().getStart().getLine() == params.getRange().getEnd().getLine()) {
result.addAll(getDisableActionForLine(params, documentContext, token));
} else {
result.addAll(getDisableActionForRange(params, documentContext, token));
.ifPresent((Token token) -> {
if (params.getRange().getStart().getLine() == params.getRange().getEnd().getLine()) {
result.addAll(getDisableActionForLine(params, documentContext, token));
} else {
result.addAll(getDisableActionForRange(params, documentContext, token));
}
}
}
);
);
}

result.addAll(
Expand Down Expand Up @@ -176,13 +175,13 @@ private List<CodeAction> actionDisableDiagnostic(Function<String, CodeAction> fu
private List<TextEdit> createInRegionTextEdits(String diagnosticName, Token last, CodeActionParams params) {
List<TextEdit> edits = new ArrayList<>();

Range disableRange = Ranges.create(
var disableRange = Ranges.create(
params.getRange().getStart().getLine(),
0,
params.getRange().getStart().getLine(),
0
);
TextEdit disableTextEdit = new TextEdit(disableRange, String.format("// BSLLS%s-off%n", diagnosticName));
var disableTextEdit = new TextEdit(disableRange, String.format("// BSLLS%s-off%n", diagnosticName));
edits.add(disableTextEdit);

Range enableRange = Ranges.create(
Expand All @@ -191,13 +190,13 @@ private List<TextEdit> createInRegionTextEdits(String diagnosticName, Token last
params.getRange().getEnd().getLine(),
last.getCharPositionInLine() + last.getText().length()
);
TextEdit enableTextEdit = new TextEdit(enableRange, String.format("%n// BSLLS%s-on%n", diagnosticName));
var enableTextEdit = new TextEdit(enableRange, String.format("%n// BSLLS%s-on%n", diagnosticName));
edits.add(enableTextEdit);
return edits;
}

private List<TextEdit> createInFileTextEdits(String diagnosticName) {
TextEdit textEdit = new TextEdit(
var textEdit = new TextEdit(
Ranges.create(0, 0, 0, 0),
String.format("// BSLLS%s-off%n", diagnosticName)
);
Expand All @@ -206,10 +205,10 @@ private List<TextEdit> createInFileTextEdits(String diagnosticName) {

private CodeAction createCodeAction(String title, List<TextEdit> edits, DocumentContext documentContext) {
Map<String, List<TextEdit>> changes = Map.of(documentContext.getUri().toString(), edits);
WorkspaceEdit edit = new WorkspaceEdit();
var edit = new WorkspaceEdit();
edit.setChanges(changes);

CodeAction codeAction = new CodeAction(title);
var codeAction = new CodeAction(title);
codeAction.setDiagnostics(new ArrayList<>());
codeAction.setKind(CodeActionKind.Refactor);
codeAction.setEdit(edit);
Expand All @@ -225,15 +224,14 @@ private String getMessage(String key, Object... args) {
}

private static List<TextEdit> createInLineTextEdits(String diagnosticName, Token last, CodeActionParams params) {
Range range = Ranges.create(
var range = Ranges.create(
params.getRange().getStart().getLine(),
last.getCharPositionInLine() + last.getText().length(),
params.getRange().getStart().getLine(),
last.getCharPositionInLine() + last.getText().length()
);

TextEdit textEdit = new TextEdit(range, String.format(" // BSLLS%s-off", diagnosticName));
var textEdit = new TextEdit(range, String.format(" // BSLLS%s-off", diagnosticName));
return Collections.singletonList(textEdit);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public <T extends Either<String, Integer>> Optional<Class<? extends QuickFixProv
T diagnosticCode
) {
return Optional.ofNullable(
diagnosticInfos.get(DiagnosticCode.getStringValue(diagnosticCode))
)
diagnosticInfos.get(DiagnosticCode.getStringValue(diagnosticCode))
)
.map(DiagnosticInfo::getDiagnosticClass)
.filter(QuickFixProvider.class::isAssignableFrom)
.map(aClass -> (Class<? extends QuickFixProvider>) aClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ private static Map<String, Object> getParameterConfiguration(
) {
Map<String, Object> parameterConfiguration;
try {
JavaType type = mapper.getTypeFactory().constructType(new TypeReference<Map<String, Object>>() {});
JavaType type = mapper.getTypeFactory().constructType(new TypeReference<Map<String, Object>>() {
});
parameterConfiguration = mapper.readValue(mapper.treeAsTokens(parameterConfig), type);
} catch (IOException e) {
LOGGER.error("Can't deserialize parameter configuration", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github._1c_syntax.bsl.languageserver.context.computer.CyclomaticComplexityComputer;
import com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticComputer;
import com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticIgnoranceComputer;
import com.github._1c_syntax.bsl.languageserver.context.computer.ModuleTypeComputer;
import com.github._1c_syntax.bsl.languageserver.context.computer.QueryComputer;
import com.github._1c_syntax.bsl.languageserver.context.computer.SymbolTreeComputer;
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
Expand Down Expand Up @@ -70,7 +71,6 @@
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;
import static org.antlr.v4.runtime.Token.DEFAULT_CHANNEL;
Expand Down Expand Up @@ -118,6 +118,7 @@ public class DocumentContext {

private final Lazy<String[]> contentList = new Lazy<>(this::computeContentList, computeLock);
private final Lazy<ModuleType> moduleType = new Lazy<>(this::computeModuleType, computeLock);
private final Lazy<String> typeName = new Lazy<>(this::computeTypeName, computeLock);
private final Lazy<ComplexityData> cognitiveComplexityData
= new Lazy<>(this::computeCognitiveComplexity, computeLock);
private final Lazy<ComplexityData> cyclomaticComplexityData
Expand Down Expand Up @@ -158,13 +159,13 @@ public List<Token> getTokens() {
}

public List<Token> getTokensFromDefaultChannel() {
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).collect(Collectors.toList());
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).toList();
}

public List<Token> getComments() {
return getTokens().stream()
.filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
.collect(Collectors.toList());
.toList();
}

public String getText(Range range) {
Expand Down Expand Up @@ -236,6 +237,10 @@ public ModuleType getModuleType() {
return moduleType.getOrCompute();
}

public String getTypeName() {
return typeName.getOrCompute();
}

public SupportVariant getSupportVariant() {
return getMdObject().map(MD::getSupportVariant).orElse(SupportVariant.NONE);
}
Expand Down Expand Up @@ -363,9 +368,14 @@ private SymbolTree computeSymbolTree() {
return new SymbolTreeComputer(this).compute();
}


private ModuleType computeModuleType() {
return context.getConfiguration().getModuleTypeByURI(uri);

return new ModuleTypeComputer(this).computeModuleType();
}

private String computeTypeName() {

return new ModuleTypeComputer(this).computeTypeName();
}

private ComplexityData computeCognitiveComplexity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2024
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* BSL Language Server is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* BSL Language Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BSL Language Server.
*/
package com.github._1c_syntax.bsl.languageserver.context;

/**
* Состояние документа в контексте.
*/
public enum DocumentState {
/**
* В документе отсутствует контент или он был очищен.
*/
WITHOUT_CONTENT,
/**
* В документе присутствует контент.
*/
WITH_CONTENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ServerContext {
= Collections.synchronizedMap(new HashMap<>());
private final ReadWriteLock contextLock = new ReentrantReadWriteLock();

private final Map<DocumentContext, State> states = new ConcurrentHashMap<>();
private final Map<DocumentContext, DocumentState> states = new ConcurrentHashMap<>();
private final Set<DocumentContext> openedDocuments = ConcurrentHashMap.newKeySet();

public void populateContext() {
Expand Down Expand Up @@ -214,12 +214,12 @@ public void openDocument(DocumentContext documentContext, String content, Intege
* @param documentContext документ, который необходимо перестроить.
*/
public void rebuildDocument(DocumentContext documentContext) {
if (states.get(documentContext) == State.WITH_CONTENT) {
if (states.get(documentContext) == DocumentState.WITH_CONTENT) {
return;
}

documentContext.rebuild();
states.put(documentContext, State.WITH_CONTENT);
states.put(documentContext, DocumentState.WITH_CONTENT);
}

/**
Expand All @@ -231,7 +231,11 @@ public void rebuildDocument(DocumentContext documentContext) {
*/
public void rebuildDocument(DocumentContext documentContext, String content, Integer version) {
documentContext.rebuild(content, version);
states.put(documentContext, State.WITH_CONTENT);
states.put(documentContext, DocumentState.WITH_CONTENT);
}

public DocumentState getDocumentState(DocumentContext documentContext) {
return states.get(documentContext);
}

/**
Expand All @@ -244,7 +248,7 @@ public void tryClearDocument(DocumentContext documentContext) {
return;
}

states.put(documentContext, State.WITHOUT_CONTENT);
states.put(documentContext, DocumentState.WITHOUT_CONTENT);
documentContext.clearSecondaryData();
}

Expand All @@ -255,7 +259,7 @@ public void tryClearDocument(DocumentContext documentContext) {
*/
public void closeDocument(DocumentContext documentContext) {
openedDocuments.remove(documentContext);
states.put(documentContext, State.WITHOUT_CONTENT);
states.put(documentContext, DocumentState.WITHOUT_CONTENT);
documentContext.clearSecondaryData();
}

Expand Down Expand Up @@ -332,18 +336,4 @@ private String getMessage(String key) {
return Resources.getResourceString(languageServerConfiguration.getLanguage(), getClass(), key);
}

/**
* Состояние документа в контексте.
*/
private enum State {
/**
* В документе отсутствует контент или он был очищен.
*/
WITHOUT_CONTENT,
/**
* В документе присутствует контент.
*/
WITH_CONTENT
}

}
Loading
Loading