Search in sources :

Example 6 with MessageParams

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

the class ActionScriptTextDocumentService method renameDefinition.

private WorkspaceEdit renameDefinition(IDefinition definition, String newName) {
    if (definition == null) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename this element.");
            languageClient.showMessage(message);
        }
        return new WorkspaceEdit(new HashMap<>());
    }
    WorkspaceEdit result = new WorkspaceEdit();
    Map<String, List<TextEdit>> changes = new HashMap<>();
    result.setChanges(changes);
    if (definition.getContainingFilePath().endsWith(SWC_EXTENSION)) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename an element defined in a SWC file.");
            languageClient.showMessage(message);
        }
        return result;
    }
    if (definition instanceof IPackageDefinition) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename a package.");
            languageClient.showMessage(message);
        }
        return result;
    }
    IDefinition parentDefinition = definition.getParent();
    if (parentDefinition != null && parentDefinition instanceof IPackageDefinition) {
        if (languageClient != null) {
            MessageParams message = new MessageParams();
            message.setType(MessageType.Info);
            message.setMessage("You cannot rename this element.");
            languageClient.showMessage(message);
        }
        return result;
    }
    for (ICompilationUnit compilationUnit : compilationUnits) {
        if (compilationUnit == null || compilationUnit instanceof SWCCompilationUnit) {
            continue;
        }
        ArrayList<TextEdit> textEdits = new ArrayList<>();
        if (compilationUnit.getAbsoluteFilename().endsWith(MXML_EXTENSION)) {
            IMXMLDataManager mxmlDataManager = currentWorkspace.getMXMLDataManager();
            MXMLData mxmlData = (MXMLData) mxmlDataManager.get(fileSpecGetter.getFileSpecification(compilationUnit.getAbsoluteFilename()));
            IMXMLTagData rootTag = mxmlData.getRootTag();
            if (rootTag != null) {
                ArrayList<ISourceLocation> units = new ArrayList<>();
                findMXMLUnits(mxmlData.getRootTag(), definition, units);
                for (ISourceLocation otherUnit : units) {
                    TextEdit textEdit = new TextEdit();
                    textEdit.setNewText(newName);
                    Range range = LanguageServerUtils.getRangeFromSourceLocation(otherUnit);
                    if (range == null) {
                        continue;
                    }
                    textEdit.setRange(range);
                    textEdits.add(textEdit);
                }
            }
        }
        IASNode ast = null;
        try {
            ast = compilationUnit.getSyntaxTreeRequest().get().getAST();
        } catch (Exception e) {
        //safe to ignore
        }
        if (ast != null) {
            ArrayList<IIdentifierNode> identifiers = new ArrayList<>();
            findIdentifiers(ast, definition, identifiers);
            for (IIdentifierNode identifierNode : identifiers) {
                TextEdit textEdit = new TextEdit();
                textEdit.setNewText(newName);
                Range range = LanguageServerUtils.getRangeFromSourceLocation(identifierNode);
                if (range == null) {
                    continue;
                }
                textEdit.setRange(range);
                textEdits.add(textEdit);
            }
        }
        if (textEdits.size() == 0) {
            continue;
        }
        URI uri = Paths.get(compilationUnit.getAbsoluteFilename()).toUri();
        changes.put(uri.toString(), textEdits);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) IPackageDefinition(org.apache.flex.compiler.definitions.IPackageDefinition) MXMLData(org.apache.flex.compiler.internal.mxml.MXMLData) ArrayList(java.util.ArrayList) URI(java.net.URI) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASNode(org.apache.flex.compiler.tree.as.IASNode) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) MessageParams(org.eclipse.lsp4j.MessageParams) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData) IDefinition(org.apache.flex.compiler.definitions.IDefinition) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IMXMLDataManager(org.apache.flex.compiler.mxml.IMXMLDataManager) TextEdit(org.eclipse.lsp4j.TextEdit) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Example 7 with MessageParams

use of org.eclipse.lsp4j.MessageParams in project sonarlint-core by SonarSource.

the class SonarLintLanguageServer method error.

void error(String message, Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    client.logMessage(new MessageParams(MessageType.Error, message + "\n" + sw.toString()));
}
Also used : StringWriter(java.io.StringWriter) MessageParams(org.eclipse.lsp4j.MessageParams) PrintWriter(java.io.PrintWriter)

Example 8 with MessageParams

use of org.eclipse.lsp4j.MessageParams in project sts4 by spring-projects.

the class SimpleLanguageServer method onError.

public void onError(String message, Throwable error) {
    LanguageClient cl = this.client;
    if (cl != null) {
        if (error instanceof ShowMessageException)
            client.showMessage(((ShowMessageException) error).message);
        else {
            Log.log(message, error);
            MessageParams m = new MessageParams();
            m.setMessage(message);
            m.setType(MessageType.Error);
            client.showMessage(m);
        }
    }
}
Also used : LanguageClient(org.eclipse.lsp4j.services.LanguageClient) STS4LanguageClient(org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient) MessageParams(org.eclipse.lsp4j.MessageParams)

Example 9 with MessageParams

use of org.eclipse.lsp4j.MessageParams in project sts4 by spring-projects.

the class ShowMessageException method create.

private static ShowMessageException create(MessageType warning, String message, Exception cause) {
    MessageParams m = new MessageParams();
    m.setMessage(message);
    m.setType(warning);
    return new ShowMessageException(m, cause);
}
Also used : MessageParams(org.eclipse.lsp4j.MessageParams)

Example 10 with MessageParams

use of org.eclipse.lsp4j.MessageParams in project eclipse.jdt.ls by eclipse.

the class JavaClientConnection method logMessage.

/**
 * Sends the logMessage message back to the client as a notification
 * @param msg The message to send back to the client
 */
public void logMessage(MessageType type, String msg) {
    MessageParams $ = new MessageParams();
    $.setMessage(msg);
    $.setType(type);
    client.logMessage($);
}
Also used : MessageParams(org.eclipse.lsp4j.MessageParams)

Aggregations

MessageParams (org.eclipse.lsp4j.MessageParams)12 HashMap (java.util.HashMap)3 IDefinition (org.apache.flex.compiler.definitions.IDefinition)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 File (java.io.File)2 IIdentifierNode (org.apache.flex.compiler.tree.as.IIdentifierNode)2 CoreException (org.eclipse.core.runtime.CoreException)2 Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)2 STS4LanguageClient (org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)1