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

Инлэй хинты по сложностям методов и команды для включения-выключения показа #3039

Merged
merged 12 commits into from
May 13, 2023
Merged
54 changes: 28 additions & 26 deletions docs/features/ConfigurationFile.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
package com.github._1c_syntax.bsl.languageserver.codelenses;

import com.github._1c_syntax.bsl.languageserver.commands.complexity.AbstractToggleComplexityInlayHintsCommandSupplier;
import com.github._1c_syntax.bsl.languageserver.commands.complexity.ToggleComplexityInlayHintsCommandArguments;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
Expand All @@ -30,7 +32,6 @@
import lombok.ToString;
import lombok.Value;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import java.beans.ConstructorProperties;
Expand All @@ -52,6 +53,7 @@ public abstract class AbstractMethodComplexityCodeLensSupplier
private static final int DEFAULT_COMPLEXITY_THRESHOLD = -1;

protected final LanguageServerConfiguration configuration;
private final AbstractToggleComplexityInlayHintsCommandSupplier commandSupplier;

@Override
public List<CodeLens> getCodeLenses(DocumentContext documentContext) {
Expand All @@ -69,8 +71,14 @@ public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, Co
var methodsComplexity = getMethodsComplexity(documentContext);
documentContext.getSymbolTree().getMethodSymbol(methodName).ifPresent((MethodSymbol methodSymbol) -> {
int complexity = methodsComplexity.get(methodSymbol);

var title = Resources.getResourceString(configuration.getLanguage(), getClass(), TITLE_KEY, complexity);
var command = new Command(title, "");
var arguments = new ToggleComplexityInlayHintsCommandArguments(
commandSupplier.getId(),
data
);

var command = commandSupplier.createCommand(title, arguments);

unresolved.setCommand(command);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.github._1c_syntax.bsl.languageserver.codelenses;

import com.github._1c_syntax.bsl.languageserver.commands.ToggleCognitiveComplexityInlayHintsCommandSupplier;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
Expand All @@ -34,8 +35,11 @@
@Component
public class CognitiveComplexityCodeLensSupplier extends AbstractMethodComplexityCodeLensSupplier {

public CognitiveComplexityCodeLensSupplier(LanguageServerConfiguration configuration) {
super(configuration);
public CognitiveComplexityCodeLensSupplier(
LanguageServerConfiguration configuration,
ToggleCognitiveComplexityInlayHintsCommandSupplier commandSupplier
) {
super(configuration, commandSupplier);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.github._1c_syntax.bsl.languageserver.codelenses;

import com.github._1c_syntax.bsl.languageserver.commands.ToggleCyclomaticComplexityInlayHintsCommandSupplier;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
Expand All @@ -34,8 +35,11 @@
@Component
public class CyclomaticComplexityCodeLensSupplier extends AbstractMethodComplexityCodeLensSupplier {

public CyclomaticComplexityCodeLensSupplier(LanguageServerConfiguration configuration) {
super(configuration);
public CyclomaticComplexityCodeLensSupplier(
LanguageServerConfiguration configuration,
ToggleCyclomaticComplexityInlayHintsCommandSupplier commandSupplier
) {
super(configuration, commandSupplier);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.lsp4j.Command;

import java.beans.Introspector;
import java.util.List;
import java.util.Optional;

/**
Expand Down Expand Up @@ -61,10 +62,11 @@ default String getId() {
* Создать DTO команды.
*
* @param title Заголовок команды.
* @param arguments Аргументы команды.
* @return Команда с заполненными заголовком и идентификатором команды.
*/
default Command createCommand(String title) {
return new Command(title, getId());
default Command createCommand(String title, T arguments) {
nixel2007 marked this conversation as resolved.
Show resolved Hide resolved
return new Command(title, getId(), List.of(arguments));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* 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.commands;

import com.github._1c_syntax.bsl.languageserver.commands.complexity.AbstractToggleComplexityInlayHintsCommandSupplier;
import com.github._1c_syntax.bsl.languageserver.inlayhints.CognitiveComplexityInlayHintSupplier;
import org.springframework.stereotype.Component;

/**
* Поставщик команды переключения подсказок когнитивной сложности.
*/
@Component
public class ToggleCognitiveComplexityInlayHintsCommandSupplier
extends AbstractToggleComplexityInlayHintsCommandSupplier {

public ToggleCognitiveComplexityInlayHintsCommandSupplier(
CognitiveComplexityInlayHintSupplier complexityInlayHintSupplier
) {
super(complexityInlayHintSupplier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* 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.commands;

import com.github._1c_syntax.bsl.languageserver.commands.complexity.AbstractToggleComplexityInlayHintsCommandSupplier;
import com.github._1c_syntax.bsl.languageserver.inlayhints.CyclomaticComplexityInlayHintSupplier;
import org.springframework.stereotype.Component;

/**
* Поставщик команды переключения подсказок цикломатической сложности.
*/
@Component
public class ToggleCyclomaticComplexityInlayHintsCommandSupplier
extends AbstractToggleComplexityInlayHintsCommandSupplier {

public ToggleCyclomaticComplexityInlayHintsCommandSupplier(
CyclomaticComplexityInlayHintSupplier complexityInlayHintSupplier
) {
super(complexityInlayHintSupplier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* 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.commands.complexity;

import com.github._1c_syntax.bsl.languageserver.commands.CommandSupplier;
import com.github._1c_syntax.bsl.languageserver.inlayhints.AbstractComplexityInlayHintSupplier;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

/**
* Базовый класс для поставщиков команды переключения подсказок сложности.
*/
@RequiredArgsConstructor
public abstract class AbstractToggleComplexityInlayHintsCommandSupplier
implements CommandSupplier<ToggleComplexityInlayHintsCommandArguments> {
nixel2007 marked this conversation as resolved.
Show resolved Hide resolved

private final AbstractComplexityInlayHintSupplier complexityInlayHintSupplier;

/**
* Получение класса аргументов команды.
*
* @return Класс аргументов команды.
*/
@Override
public Class<ToggleComplexityInlayHintsCommandArguments> getCommandArgumentsClass() {
return ToggleComplexityInlayHintsCommandArguments.class;
}

/**
* @inheritDoc
*/
@Override
public Optional<Object> execute(ToggleComplexityInlayHintsCommandArguments arguments) {
complexityInlayHintSupplier.toggleHints(arguments.getUri(), arguments.getMethodName());
return Optional.empty();
}

/**
* @inheritDoc
*/
@Override
public boolean needRefreshInlayHintsAfterExecuteCommand() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* 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.commands.complexity;

import com.github._1c_syntax.bsl.languageserver.codelenses.AbstractMethodComplexityCodeLensSupplier;
import com.github._1c_syntax.bsl.languageserver.commands.DefaultCommandArguments;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.Value;

import java.beans.ConstructorProperties;
import java.net.URI;

/**
* Аргументы команды для переключения отображения сложности метода во всплывающих подсказках.
*/
@Value
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ToggleComplexityInlayHintsCommandArguments extends DefaultCommandArguments {
/**
* Имя метода.
*/
String methodName;

@ConstructorProperties({"uri", "id", "methodName"})
public ToggleComplexityInlayHintsCommandArguments(URI uri, String id, String methodName) {
super(uri, id);
this.methodName = methodName;
}

public ToggleComplexityInlayHintsCommandArguments(
String id,
AbstractMethodComplexityCodeLensSupplier.ComplexityCodeLensData data
) {
this(data.getUri(), id, data.getMethodName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* 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.
*/
/**
* Служебные классы команд, связанные с показом сложности методов.
*/
@DefaultAnnotation(NonNull.class)
package com.github._1c_syntax.bsl.languageserver.commands.complexity;

import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
import edu.umd.cs.findbugs.annotations.NonNull;
Loading