use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class AbstractQuickFixTest method assertCodeActionExists.
protected void assertCodeActionExists(ICompilationUnit cu, Expected expected) throws Exception {
List<Command> codeActionCommands = evaluateCodeActions(cu);
for (Command c : codeActionCommands) {
String actual = evaluateCodeActionCommand(c);
if (expected.content.equals(actual)) {
assertEquals(expected.name, c.getTitle());
return;
}
}
String res = "";
for (Command command : codeActionCommands) {
if (res.length() > 0) {
res += '\n';
}
res += command.getTitle();
}
assertEquals("Not found.", expected.name, res);
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class AbstractQuickFixTest method assertCodeActions.
protected void assertCodeActions(ICompilationUnit cu, Expected... expected) throws Exception {
List<Command> codeActionCommands = evaluateCodeActions(cu);
if (codeActionCommands.size() != expected.length) {
String res = "";
for (Command command : codeActionCommands) {
res += " '" + command.getTitle() + "'";
}
assertEquals("Number of code actions: " + res, expected.length, codeActionCommands.size());
}
int k = 0;
String aStr = "", eStr = "", testContent = "";
for (Command c : codeActionCommands) {
String actual = evaluateCodeActionCommand(c);
Expected e = expected[k++];
if (!e.name.equals(c.getTitle()) || !e.content.equals(actual)) {
aStr += '\n' + c.getTitle() + '\n' + actual;
eStr += '\n' + e.name + '\n' + e.content;
}
testContent += generateTest(actual, c.getTitle(), k);
}
if (aStr.length() > 0) {
aStr += '\n' + testContent;
}
assertEquals(eStr, aStr);
}
use of org.eclipse.lsp4j.Command in project xtext-core by eclipse.
the class CodeActionService method fixInvalidName.
private Command fixInvalidName(Diagnostic d, ICodeActionService2.Options options) {
String string = options.getDocument().getSubstring(d.getRange());
Command command = new Command();
command.setCommand("my.textedit.command");
command.setTitle("Make '" + string + "' upper case (Command)");
WorkspaceEdit workspaceEdit = new WorkspaceEdit();
TextEdit textEdit = new TextEdit();
textEdit.setNewText(StringExtensions.toFirstUpper(string));
textEdit.setRange(d.getRange());
workspaceEdit.getChanges().put(options.getCodeActionParams().getTextDocument().getUri(), Lists.newArrayList(textEdit));
command.setArguments(Lists.newArrayList(workspaceEdit));
return command;
}
use of org.eclipse.lsp4j.Command in project xtext-core by eclipse.
the class AbstractLanguageServerTest method _toExpectation.
protected String _toExpectation(final CodeAction it) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("title : ");
String _title = it.getTitle();
_builder.append(_title);
_builder.newLineIfNotEmpty();
_builder.append("kind : ");
String _kind = it.getKind();
_builder.append(_kind);
_builder.newLineIfNotEmpty();
_builder.append("command : ");
Command _command = it.getCommand();
_builder.append(_command);
_builder.newLineIfNotEmpty();
{
boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getDiagnostics());
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("codes : ");
final Function1<Diagnostic, Object> _function = (Diagnostic it_1) -> {
return it_1.getCode().get();
};
String _join = IterableExtensions.join(ListExtensions.<Diagnostic, Object>map(it.getDiagnostics(), _function), ",");
_builder.append(_join);
}
}
_builder.newLineIfNotEmpty();
_builder.append("edit : ");
String _expectation = this.toExpectation(it.getEdit());
_builder.append(_expectation);
_builder.newLineIfNotEmpty();
return _builder.toString();
}
use of org.eclipse.lsp4j.Command in project ballerina by ballerina-lang.
the class BallerinaTextDocumentService method codeAction.
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
return CompletableFuture.supplyAsync(() -> {
List<Command> commands = new ArrayList<>();
String topLevelNodeType = CommonUtil.topLevelNodeTypeInLine(params.getTextDocument(), params.getRange().getStart(), documentManager);
if (topLevelNodeType != null) {
commands.add(CommandUtil.getDocGenerationCommand(topLevelNodeType, params.getTextDocument().getUri(), params.getRange().getStart().getLine()));
commands.add(CommandUtil.getAllDocGenerationCommand(params.getTextDocument().getUri()));
} else if (!params.getContext().getDiagnostics().isEmpty()) {
params.getContext().getDiagnostics().forEach(diagnostic -> {
commands.addAll(CommandUtil.getCommandsByDiagnostic(diagnostic, params, lSPackageCache));
});
}
return commands;
});
}
Aggregations