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

Remove unused rename popup command #40790

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -32,11 +32,6 @@ public interface InitializationOptions {
*/
String KEY_ENABLE_SEMANTIC_TOKENS = "enableSemanticHighlighting";

/**
* Whether the client supports rename popup.
*/
String KEY_RENAME_SUPPORT = "supportRenamePopup";

/**
* Whether the client supports {@link org.eclipse.lsp4j.Position} based rename popup.
*/
Expand Down Expand Up @@ -66,13 +61,6 @@ public interface InitializationOptions {
*/
boolean isEnableSemanticTokens();

/**
* Returns if the client supports rename popup.
*
* @return True if supported, false otherwise
*/
boolean isRefactorRenameSupported();

/**
* Returns if the client supports {@link org.eclipse.lsp4j.Position} based rename.
* @return True if supported, false otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ private InitializationOptions parseInitializationOptions(Map<String, Object> ini
Boolean.parseBoolean(String.valueOf(semanticTokensSupport));
initializationOptions.setEnableSemanticTokens(enableSemanticTokens);

Object renameSupport = initOptions.get(InitializationOptions.KEY_RENAME_SUPPORT);
boolean enableRenameSupport = renameSupport != null &&
Boolean.parseBoolean(String.valueOf(renameSupport));
initializationOptions.setSupportRenamePopup(enableRenameSupport);

Object quickPickSupport = initOptions.get(InitializationOptions.KEY_QUICKPICK_SUPPORT);
boolean enableQuickPickSupport = quickPickSupport != null &&
Boolean.parseBoolean(String.valueOf(quickPickSupport));
Expand Down Expand Up @@ -210,7 +205,6 @@ public static class InitializationOptionsImpl implements InitializationOptions {

private boolean supportBalaScheme = false;
private boolean enableSemanticTokens = false;
private boolean supportRenamePopup = false;
private boolean supportQuickPick = false;
private boolean enableLSLightWeightMode = false;
private boolean supportPositionalRenamePopup = false;
Expand All @@ -232,11 +226,6 @@ public void setEnableSemanticTokens(boolean enableSemanticTokens) {
this.enableSemanticTokens = enableSemanticTokens;
}

@Override
public boolean isRefactorRenameSupported() {
return supportRenamePopup;
}

@Override
public boolean isPositionalRefactorRenameSupported() {
return supportPositionalRenamePopup;
Expand All @@ -246,10 +235,6 @@ public void setSupportPositionalRenamePopup(boolean supportPositionalRenamePopup
this.supportPositionalRenamePopup = supportPositionalRenamePopup;
}

public void setSupportRenamePopup(boolean supportRenamePopup) {
this.supportRenamePopup = supportRenamePopup;
}

@Override
public boolean isQuickPickSupported() {
return supportQuickPick;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
import io.ballerina.compiler.api.symbols.TypeSymbol;
import io.ballerina.compiler.api.symbols.UnionTypeSymbol;
import io.ballerina.compiler.api.symbols.WorkerSymbol;
import io.ballerina.compiler.syntax.tree.SyntaxTree;
import io.ballerina.tools.diagnostics.Diagnostic;
import org.ballerinalang.annotation.JavaSPIService;
import org.ballerinalang.langserver.codeaction.CodeActionNodeValidator;
import org.ballerinalang.langserver.codeaction.CodeActionUtil;
import org.ballerinalang.langserver.common.ImportsAcceptor;
import org.ballerinalang.langserver.common.constants.CommandConstants;
import org.ballerinalang.langserver.common.utils.CommonUtil;
import org.ballerinalang.langserver.common.utils.NameUtil;
import org.ballerinalang.langserver.common.utils.PositionUtil;
import org.ballerinalang.langserver.commons.CodeActionContext;
Expand Down Expand Up @@ -58,7 +56,6 @@
public class CreateVariableCodeAction implements DiagnosticBasedCodeActionProvider {

public static final String NAME = "Create Variable";
private static final String RENAME_COMMAND = "Rename Variable";

/**
* {@inheritDoc}
Expand Down Expand Up @@ -110,8 +107,8 @@ public List<CodeAction> getCodeActions(Diagnostic diagnostic,
}

CodeAction codeAction = CodeActionUtil.createCodeAction(commandTitle, edits, uri, CodeActionKind.QuickFix);
addRenamePopup(context, edits, variableEdit, codeAction, createVarTextEdits.renamePositions.get(i),
createVarTextEdits.varRenamePosition.get(i), createVarTextEdits.imports.size());
addRenamePopup(context, codeAction, createVarTextEdits.varRenamePosition.get(i),
createVarTextEdits.imports.size());
actions.add(codeAction);
}
return actions;
Expand Down Expand Up @@ -215,8 +212,7 @@ public CreateVariableOut(String name, List<String> types, List<TextEdit> edits,
}
}

public void addRenamePopup(CodeActionContext context, List<TextEdit> textEdits, TextEdit variableEdit,
CodeAction codeAction, int renameOffset,
public void addRenamePopup(CodeActionContext context, CodeAction codeAction,
Position varRenamePosition, int newImportsCount) {
LSClientCapabilities lsClientCapabilities = context.languageServercontext().get(LSClientCapabilities.class);
if (lsClientCapabilities.getInitializationOptions().isPositionalRefactorRenameSupported()) {
Expand All @@ -225,45 +221,6 @@ public void addRenamePopup(CodeActionContext context, List<TextEdit> textEdits,
List.of(context.fileUri(),
new Position(varRenamePosition.getLine() + newImportsCount,
varRenamePosition.getCharacter()))));
return;
}

Optional<SyntaxTree> syntaxTree = context.currentSyntaxTree();
if (!lsClientCapabilities.getInitializationOptions().isRefactorRenameSupported() || syntaxTree.isEmpty()) {
return;
}
/*
Ex: class Test {
function testFunc() returns error? {
int testResult = check test();
}
}
1. startPos gives the start position of the variable type "int".
2. If any text edits are applied before the variable creation edit, the length of those edits is added to the
"sum". In the above example, the length of "error?" will be added.
3. renameOffset gives the length of the variable type and the white space between the variable type and the
variable. In the example, the renameOffset will be the length of "int ".
*/

int startPos = CommonUtil.getTextEdit(syntaxTree.get(), variableEdit).range().startOffset();
int sum = 0;
for (TextEdit textEdit : textEdits) {
io.ballerina.tools.text.TextEdit edits = CommonUtil.getTextEdit(syntaxTree.get(), textEdit);
int startOffset = edits.range().startOffset();
int endOffset = edits.range().endOffset();
if (startOffset < startPos) {
sum = sum + edits.text().length();
if (startOffset < endOffset) {
int returnTypeLength = endOffset - startOffset;
sum = sum - returnTypeLength;
}
}
}

startPos = startPos + sum + renameOffset;

codeAction.setCommand(
new Command(CommandConstants.RENAME_COMMAND_TITLE_FOR_VARIABLE, CommandConstants.RENAME_COMMAND,
List.of(context.fileUri(), startPos)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public List<CodeAction> getCodeActions(Diagnostic diagnostic,
createVarTextEdits.imports.stream().filter(edit -> !edits.contains(edit)).forEach(edits::add);

CodeAction codeAction = CodeActionUtil.createCodeAction(commandTitle, edits, uri, CodeActionKind.QuickFix);
addRenamePopup(context, edits, createVarTextEdits.edits.get(0), codeAction,
createVarTextEdits.renamePositions.get(0), createVarTextEdits.varRenamePosition.get(0),
addRenamePopup(context, codeAction, createVarTextEdits.varRenamePosition.get(0),
createVarTextEdits.imports.size());
return Collections.singletonList(codeAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ public List<CodeAction> getCodeActions(Diagnostic diagnostic,
positionDetails.matchedNode(), context));
edits.addAll(importsAcceptor.getNewImportTextEdits());

int renamePosition = modifiedTextEdits.renamePositions.get(0);
CodeAction codeAction = CodeActionUtil.createCodeAction(CommandConstants.CREATE_VAR_ADD_CHECK_TITLE,
edits, uri, CodeActionKind.QuickFix);
addRenamePopup(context, edits, modifiedTextEdits.edits.get(0), codeAction, renamePosition,
modifiedTextEdits.varRenamePosition.get(0), modifiedTextEdits.imports.size());
addRenamePopup(context, codeAction, modifiedTextEdits.varRenamePosition.get(0),
modifiedTextEdits.imports.size());
return Collections.singletonList(codeAction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ public class CommandConstants {

public static final String CHANGE_TO_SUBTYPE_OF_RAW_TEMPLATE_TITLE = "Convert to '%s' template";

public static final String RENAME_COMMAND = "ballerina.action.rename";

public static final String POSITIONAL_RENAME_COMMAND = "ballerina.action.positional.rename";

public static final String EXTRACT_COMMAND = "ballerina.action.extract";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,40 +404,6 @@ protected boolean validateAndModifyArguments(JsonObject actualCommand,
List<TextEdit> actualEdits,
TestConfig testConfig) {
//Validate the args of rename command
if (CommandConstants.RENAME_COMMAND.equals(actualCommand.get("command").getAsString())) {
if (actualArgs.size() == 2) {
Optional<String> actualFilePath =
PathUtil.getPathFromURI(actualArgs.get(0).getAsString())
.map(path -> path.toUri().toString().replace(sourceRoot.toUri().toString(), ""));
int actualRenamePosition = actualArgs.get(1).getAsInt();
String expectedFilePath = expArgs.get(0).getAsString();
int expectedRenamePosition = expArgs.get(1).getAsInt();
if (actualFilePath.isPresent()) {
String actualPath = actualFilePath.get();
if (actualFilePath.get().startsWith("/") || actualFilePath.get().startsWith("\\")) {
actualPath = actualFilePath.get().substring(1);
}
if (sourceRoot.resolve(actualPath).equals(sourceRoot.resolve(expectedFilePath)) &&
actualRenamePosition == expectedRenamePosition) {
return true;
}
JsonArray newArgs = new JsonArray();
newArgs.add(actualArgs.get(0).getAsString());
newArgs.add(actualRenamePosition);

//Replace the args of the actual command to update the test config
actualCommand.add("arguments", newArgs);
}
}
return false;
} else if ("ballerina.action.extract".equals(actualCommand.get("command").getAsString())) {
if (actualArgs.size() == 3 && validateExtractCmd(actualCommand, actualArgs, expArgs, sourceRoot)) {
return true;
}
return actualArgs.size() == 4 && validateExtractCmd(actualCommand, actualArgs, expArgs, sourceRoot)
&& actualArgs.get(3).getAsJsonObject().equals(expArgs.get(3).getAsJsonObject());
}

if (CommandConstants.POSITIONAL_RENAME_COMMAND.equals(actualCommand.get("command").getAsString())) {
if (actualArgs.size() == 2) {
Optional<String> actualFilePath =
Expand Down Expand Up @@ -465,6 +431,12 @@ protected boolean validateAndModifyArguments(JsonObject actualCommand,
}
}
return false;
} else if ("ballerina.action.extract".equals(actualCommand.get("command").getAsString())) {
if (actualArgs.size() == 3 && validateExtractCmd(actualCommand, actualArgs, expArgs, sourceRoot)) {
return true;
}
return actualArgs.size() == 4 && validateExtractCmd(actualCommand, actualArgs, expArgs, sourceRoot)
&& actualArgs.get(3).getAsJsonObject().equals(expArgs.get(3).getAsJsonObject());
}

for (JsonElement actualArg : actualArgs) {
Expand Down
Loading