use of org.eclipse.lsp4j.CodeActionContext in project eclipse.jdt.ls by eclipse.
the class AbstractQuickFixTest method evaluateCodeActions.
protected List<Command> evaluateCodeActions(ICompilationUnit cu) throws JavaModelException {
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
IProblem[] problems = astRoot.getProblems();
Range range = getRange(cu, problems);
CodeActionParams parms = new CodeActionParams();
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
parms.setTextDocument(textDocument);
parms.setRange(range);
CodeActionContext context = new CodeActionContext();
context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems)));
parms.setContext(context);
List<Command> commands = new CodeActionHandler().getCodeActionCommands(parms, new NullProgressMonitor());
if (this.ignoredCommands != null) {
List<Command> filteredList = new ArrayList<>();
for (Command command : commands) {
for (String str : this.ignoredCommands) {
if (command.getTitle().matches(str)) {
filteredList.add(command);
break;
}
}
}
commands.removeAll(filteredList);
}
return commands;
}
use of org.eclipse.lsp4j.CodeActionContext in project eclipse.jdt.ls by eclipse.
the class CodeActionHandlerTest method testCodeAction_removeUnterminatedString.
@Test
public void testCodeAction_removeUnterminatedString() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " void foo() {\n" + "String s = \"some str\n" + " }\n" + "}\n");
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = getRange(unit, "some str");
params.setRange(range);
params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnterminatedString), range))));
List<? extends Command> commands = server.codeAction(params).join();
Assert.assertNotNull(commands);
Assert.assertEquals(1, commands.size());
Command c = commands.get(0);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
use of org.eclipse.lsp4j.CodeActionContext in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method getCodeActions.
protected List<Command> getCodeActions(ICompilationUnit cu) throws JavaModelException {
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
IProblem[] problems = astRoot.getProblems();
Range range = getRange(cu, problems);
CodeActionParams parms = new CodeActionParams();
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
parms.setTextDocument(textDocument);
parms.setRange(range);
CodeActionContext context = new CodeActionContext();
context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems)));
parms.setContext(context);
return new CodeActionHandler().getCodeActionCommands(parms, new NullProgressMonitor());
}
use of org.eclipse.lsp4j.CodeActionContext in project sts4 by spring-projects.
the class LanguageServerHarness method getCodeActions.
public List<CodeAction> getCodeActions(TextDocumentInfo doc, Diagnostic problem) throws Exception {
CodeActionContext context = new CodeActionContext(ImmutableList.of(problem));
List<? extends Command> actions = getServer().getTextDocumentService().codeAction(new CodeActionParams(doc.getId(), problem.getRange(), context)).get();
return actions.stream().map((command) -> new CodeAction(this, command)).collect(Collectors.toList());
}
use of org.eclipse.lsp4j.CodeActionContext in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testCodeAction.
protected void testCodeAction(final Procedure1<? super AbstractLanguageServerTest.TestCodeActionConfiguration> configurator) {
try {
@Extension final AbstractLanguageServerTest.TestCodeActionConfiguration configuration = new AbstractLanguageServerTest.TestCodeActionConfiguration();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final String filePath = this.initializeContext(configuration).getUri();
CodeActionParams _codeActionParams = new CodeActionParams();
final Procedure1<CodeActionParams> _function = (CodeActionParams it) -> {
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
it.setTextDocument(_textDocumentIdentifier);
Range _range = new Range();
final Procedure1<Range> _function_1 = (Range it_1) -> {
int _line = configuration.getLine();
int _column = configuration.getColumn();
Position _position = new Position(_line, _column);
it_1.setStart(_position);
it_1.setEnd(it_1.getStart());
};
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
it.setRange(_doubleArrow);
CodeActionContext _codeActionContext = new CodeActionContext();
final Procedure1<CodeActionContext> _function_2 = (CodeActionContext it_1) -> {
it_1.setDiagnostics(this.getDiagnostics().get(filePath));
};
CodeActionContext _doubleArrow_1 = ObjectExtensions.<CodeActionContext>operator_doubleArrow(_codeActionContext, _function_2);
it.setContext(_doubleArrow_1);
};
CodeActionParams _doubleArrow = ObjectExtensions.<CodeActionParams>operator_doubleArrow(_codeActionParams, _function);
final CompletableFuture<List<Either<Command, CodeAction>>> result = this.languageServer.codeAction(_doubleArrow);
if ((configuration.assertCodeActions != null)) {
configuration.assertCodeActions.apply(result.get());
} else {
this.assertEquals(configuration.expectedCodeActions, this.toExpectation(result.get()));
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations