Search in sources :

Example 1 with CodeAction

use of org.eclipse.lsp4j.CodeAction in project xtext-core by eclipse.

the class CodeActionService method fixUnsortedMembers.

private CodeAction fixUnsortedMembers(Diagnostic d, ICodeActionService2.Options options) {
    WorkspaceEdit wsEdit = recordWorkspaceEdit(options, (Resource copiedResource) -> {
        Model model = Iterables.getFirst(Iterables.filter(copiedResource.getContents(), Model.class), null);
        if (model != null) {
            for (TypeDeclaration type : Iterables.filter(model.getElements(), TypeDeclaration.class)) {
                ECollections.sort(type.getMembers(), (Member a, Member b) -> a.getName().compareTo(b.getName()));
            }
        }
    });
    CodeAction codeAction = new CodeAction();
    codeAction.setTitle("Sort Members");
    codeAction.setDiagnostics(Lists.newArrayList(d));
    codeAction.setEdit(wsEdit);
    return codeAction;
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) Member(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member)

Example 2 with CodeAction

use of org.eclipse.lsp4j.CodeAction 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);
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CodeAction(org.eclipse.lsp4j.CodeAction) FoldingRange(org.eclipse.lsp4j.FoldingRange) Range(org.eclipse.lsp4j.Range) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) Extension(org.eclipse.xtext.xbase.lib.Extension) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 3 with CodeAction

use of org.eclipse.lsp4j.CodeAction in project xtext-core by eclipse.

the class QuickFixCodeActionService method createFix.

private CodeAction createFix(DiagnosticResolution resolution, Diagnostic error) {
    CodeAction codeAction = new CodeAction();
    codeAction.setDiagnostics(Collections.singletonList(error));
    codeAction.setTitle(resolution.getLabel());
    codeAction.setEdit(resolution.apply());
    codeAction.setKind(CodeActionKind.QuickFix);
    return codeAction;
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction)

Aggregations

CodeAction (org.eclipse.lsp4j.CodeAction)3 List (java.util.List)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)1 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)1 Command (org.eclipse.lsp4j.Command)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 FoldingRange (org.eclipse.lsp4j.FoldingRange)1 Position (org.eclipse.lsp4j.Position)1 Range (org.eclipse.lsp4j.Range)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)1 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)1 Endpoint (org.eclipse.lsp4j.jsonrpc.Endpoint)1 Member (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member)1 Model (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model)1 TypeDeclaration (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1