Search in sources :

Example 1 with Command

use of org.eclipse.lsp4j.Command in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method createImportCommand.

private Command createImportCommand(IDefinition definition) {
    String packageName = definition.getPackageName();
    if (packageName == null || packageName.isEmpty() || packageName.startsWith(PACKAGE_NAME_NO_IMPORT)) {
        return null;
    }
    String qualifiedName = definition.getQualifiedName();
    Command importCommand = new Command();
    importCommand.setTitle("Import " + qualifiedName);
    importCommand.setCommand(COMMAND_IMPORT);
    importCommand.setArguments(Arrays.asList(qualifiedName, importStartIndex, importEndIndex));
    return importCommand;
}
Also used : Command(org.eclipse.lsp4j.Command)

Example 2 with Command

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

the class CodeActionService method fixUnsortedMembers.

private Command fixUnsortedMembers(final Diagnostic d, final Document doc, final XtextResource res, final CodeActionParams params) {
    final IChangeSerializer.IModification<Resource> _function = (Resource copiedResource) -> {
        final Model model = IterableExtensions.<Model>head(Iterables.<Model>filter(copiedResource.getContents(), Model.class));
        EList<TypeDeclaration> _types = model.getTypes();
        for (final TypeDeclaration type : _types) {
            final Comparator<Member> _function_1 = (Member a, Member b) -> {
                String _name = a.getName();
                String _name_1 = b.getName();
                return (_name.compareTo(_name_1));
            };
            ECollections.<Member>sort(type.getMembers(), _function_1);
        }
    };
    final WorkspaceEdit edit = this.recordWorkspaceEdit(doc, res, _function);
    Command _command = new Command();
    final Procedure1<Command> _function_1 = (Command it) -> {
        it.setCommand("my.textedit.command");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Sort Members");
        it.setTitle(_builder.toString());
        it.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList(edit)));
    };
    return ObjectExtensions.<Command>operator_doubleArrow(_command, _function_1);
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Comparator(java.util.Comparator) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Command(org.eclipse.lsp4j.Command) Model(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) Member(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member)

Example 3 with Command

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

the class CodeActionService method getCodeActions.

@Override
public List<? extends Command> getCodeActions(final Document document, final XtextResource resource, final CodeActionParams params, final CancelIndicator indicator) {
    final ArrayList<Command> commands = CollectionLiterals.<Command>newArrayList();
    List<Diagnostic> _diagnostics = params.getContext().getDiagnostics();
    for (final Diagnostic d : _diagnostics) {
        String _code = d.getCode();
        if (_code != null) {
            switch(_code) {
                case TestLanguageValidator.INVALID_NAME:
                    Command _fixInvalidName = this.fixInvalidName(d, document, resource, params);
                    commands.add(_fixInvalidName);
                    break;
                case TestLanguageValidator.UNSORTED_MEMBERS:
                    Command _fixUnsortedMembers = this.fixUnsortedMembers(d, document, resource, params);
                    commands.add(_fixUnsortedMembers);
                    break;
            }
        }
    }
    return commands;
}
Also used : Command(org.eclipse.lsp4j.Command) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 4 with Command

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

the class CodeActionService method fixInvalidName.

private Command fixInvalidName(final Diagnostic d, final Document doc, final XtextResource res, final CodeActionParams params) {
    final String string = doc.getSubstring(d.getRange());
    Command _command = new Command();
    final Procedure1<Command> _function = (Command it) -> {
        it.setCommand("my.textedit.command");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Make \'");
        _builder.append(string);
        _builder.append("\' upper case");
        it.setTitle(_builder.toString());
        WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
        final Procedure1<WorkspaceEdit> _function_1 = (WorkspaceEdit it_1) -> {
            TextEdit _textEdit = new TextEdit();
            final Procedure1<TextEdit> _function_2 = (TextEdit it_2) -> {
                it_2.setNewText(StringExtensions.toFirstUpper(string));
                it_2.setRange(d.getRange());
            };
            TextEdit _doubleArrow = ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
            it_1.getChanges().put(params.getTextDocument().getUri(), Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_doubleArrow)));
        };
        WorkspaceEdit _doubleArrow = ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function_1);
        it.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList(_doubleArrow)));
    };
    return ObjectExtensions.<Command>operator_doubleArrow(_command, _function);
}
Also used : Command(org.eclipse.lsp4j.Command) TextEdit(org.eclipse.lsp4j.TextEdit) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit)

Example 5 with Command

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

the class CodeLensService method resolveCodeLens.

@Override
public CodeLens resolveCodeLens(final Document document, final XtextResource resource, final CodeLens codeLens, final CancelIndicator indicator) {
    Command _command = codeLens.getCommand();
    String _title = codeLens.getCommand().getTitle();
    String _plus = (_title + "(RESOLVED)");
    _command.setTitle(_plus);
    return codeLens;
}
Also used : Command(org.eclipse.lsp4j.Command)

Aggregations

Command (org.eclipse.lsp4j.Command)33 Range (org.eclipse.lsp4j.Range)11 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)8 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)8 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)8 ArrayList (java.util.ArrayList)7 CodeLens (org.eclipse.lsp4j.CodeLens)7 Position (org.eclipse.lsp4j.Position)7 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)7 Test (org.junit.Test)7 List (java.util.List)6 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)6 Diagnostic (org.eclipse.lsp4j.Diagnostic)6 Location (org.eclipse.lsp4j.Location)5 Path (java.nio.file.Path)4 CoreException (org.eclipse.core.runtime.CoreException)4 TextEdit (org.eclipse.lsp4j.TextEdit)4 Collections (java.util.Collections)3 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)3 URI (java.net.URI)2