use of org.eclipse.lsp4j.MessageParams in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method actionScriptRenameWithNode.
private CompletableFuture<WorkspaceEdit> actionScriptRenameWithNode(RenameParams params, IASNode offsetNode) {
if (offsetNode == null) {
//we couldn't find a node at the specified location
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
IDefinition definition = null;
if (offsetNode instanceof IDefinitionNode) {
IDefinitionNode definitionNode = (IDefinitionNode) offsetNode;
IExpressionNode expressionNode = definitionNode.getNameExpressionNode();
definition = expressionNode.resolve(currentProject);
} else if (offsetNode instanceof IIdentifierNode) {
IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
definition = identifierNode.resolve(currentProject);
}
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 CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
WorkspaceEdit result = renameDefinition(definition, params.getNewName());
return CompletableFuture.completedFuture(result);
}
use of org.eclipse.lsp4j.MessageParams in project eclipse.jdt.ls by eclipse.
the class JavaClientConnection method showNotificationMessage.
/**
* Sends the message to the client, to be displayed on a UI element.
*
* @param type
* @param msg
*/
public void showNotificationMessage(MessageType type, String msg) {
MessageParams $ = new MessageParams();
$.setMessage(msg);
$.setType(type);
client.showMessage($);
}
use of org.eclipse.lsp4j.MessageParams in project sts4 by spring-projects.
the class LanguageServerHarness method intialize.
public InitializeResult intialize(File workspaceRoot) throws Exception {
server = factory.call();
int parentPid = random.nextInt(40000) + 1000;
InitializeParams initParams = new InitializeParams();
if (workspaceRoot != null) {
initParams.setRootPath(workspaceRoot.toString());
initParams.setRootUri(UriUtil.toUri(workspaceRoot).toString());
}
initParams.setProcessId(parentPid);
ClientCapabilities clientCap = new ClientCapabilities();
TextDocumentClientCapabilities textCap = new TextDocumentClientCapabilities();
CompletionCapabilities completionCap = new CompletionCapabilities(new CompletionItemCapabilities(true));
textCap.setCompletion(completionCap);
clientCap.setTextDocument(textCap);
WorkspaceClientCapabilities workspaceCap = new WorkspaceClientCapabilities();
workspaceCap.setApplyEdit(true);
ExecuteCommandCapabilities exeCap = new ExecuteCommandCapabilities();
exeCap.setDynamicRegistration(true);
workspaceCap.setExecuteCommand(exeCap);
clientCap.setWorkspace(workspaceCap);
initParams.setCapabilities(clientCap);
initResult = getServer().initialize(initParams).get();
if (getServer() instanceof LanguageClientAware) {
((LanguageClientAware) getServer()).connect(new STS4LanguageClient() {
@Override
public void telemetryEvent(Object object) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
// TODO Auto-generated method stub
return CompletableFuture.completedFuture(new MessageActionItem("Some Message Request Answer"));
}
@Override
public void showMessage(MessageParams messageParams) {
// TODO Auto-generated method stub
}
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
receiveDiagnostics(diagnostics);
}
@Override
public void highlight(HighlightParams highlights) {
receiveHighlights(highlights);
}
@Override
public void logMessage(MessageParams message) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
return Mono.fromCallable(() -> {
perform(params.getEdit());
return new ApplyWorkspaceEditResponse(true);
}).toFuture();
}
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
return CompletableFuture.completedFuture(null);
}
@Override
public void progress(ProgressParams progressEvent) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
for (Editor editor : activeEditors) {
if (editor.getUri().equals(cursorMovement.getUri())) {
editor.setCursor(cursorMovement.getPosition());
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
}
}
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
}
@Override
public CompletableFuture<ProjectResponse> project(String uri) {
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params) {
return CompletableFuture.completedFuture("ok");
}
@Override
public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams classpathListenerParams) {
return CompletableFuture.completedFuture("ok");
}
});
}
getServer().initialized();
return initResult;
}
use of org.eclipse.lsp4j.MessageParams in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method mxmlRename.
private CompletableFuture<WorkspaceEdit> mxmlRename(RenameParams params, IMXMLTagData offsetTag) {
IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
if (definition != null) {
if (isInsideTagPrefix(offsetTag, currentOffset)) {
//ignore the tag's prefix
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
WorkspaceEdit result = renameDefinition(definition, params.getNewName());
return CompletableFuture.completedFuture(result);
}
if (languageClient != null) {
MessageParams message = new MessageParams();
message.setType(MessageType.Info);
message.setMessage("You cannot rename this element.");
languageClient.showMessage(message);
}
return CompletableFuture.completedFuture(new WorkspaceEdit(new HashMap<>()));
}
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;
}
Aggregations