Java源码示例:org.eclipse.lsp4j.ApplyWorkspaceEditParams
示例1
@Override
public final CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
CompletableFuture<ApplyWorkspaceEditResponse> future = new CompletableFuture<>();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
LSPIJUtils.applyWorkspaceEdit(params.getEdit());
future.complete(new ApplyWorkspaceEditResponse(true));
});
return future;
}
示例2
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
boolean applied = false;
synchronized (listeners) {
for (IIdeTestLanguageClientListener l : listeners) {
applied |= l.onServerRequest_applyEdit(params);
}
}
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(applied));
}
示例3
/**
* Fix the issues of the same kind in the entire file.
*/
@ExecutableCommandHandler(COMPOSITE_FIX_FILE)
public Void fixAllInFile(String title, String code, String fixId, CodeActionParams codeActionParams,
ILanguageServerAccess access, CancelIndicator cancelIndicator) {
String uriString = codeActionParams.getTextDocument().getUri();
URI uri = uriExtensions.toUri(uriString);
WorkspaceEdit edit = codeActionService.applyToFile(uri, code, fixId, cancelIndicator);
access.getLanguageClient().applyEdit(new ApplyWorkspaceEditParams(edit, title));
return null;
}
示例4
/**
* Fix the issues of the same kind in the entire project.
*/
@ExecutableCommandHandler(COMPOSITE_FIX_PROJECT)
public Void fixAllInProject(String title, String code, String fixId, CodeActionParams codeActionParams,
ILanguageServerAccess access, CancelIndicator cancelIndicator) {
String uriString = codeActionParams.getTextDocument().getUri();
URI uri = uriExtensions.toUri(uriString);
WorkspaceEdit edit = codeActionService.applyToProject(uri, code, fixId, cancelIndicator);
access.getLanguageClient().applyEdit(new ApplyWorkspaceEditParams(edit, title));
return null;
}
示例5
private Void doOrganizeImports(String uriString, ILanguageServerAccess.Context context,
LanguageClient languageClient, CancelIndicator cancelIndicator) {
Resource resource = context.getResource();
if (!(resource instanceof N4JSResource)) {
return null;
}
Script script = ((N4JSResource) resource).getScript();
Document document = context.getDocument();
// compute imports to be added for unresolved references
List<ImportDescriptor> importsToBeAdded = new ArrayList<>();
List<ReferenceResolution> resolutions = importHelper
.findResolutionsForAllUnresolvedReferences(script, cancelIndicator);
for (ReferenceResolution resolution : resolutions) {
if (resolution.importToBeAdded != null) {
importsToBeAdded.add(resolution.importToBeAdded);
}
}
// organize all imports (existing and new ones)
List<TextEdit> edits = importOrganizer.organizeImports(document, script, importsToBeAdded, cancelIndicator);
WorkspaceEdit workspaceEdit = new WorkspaceEdit(Collections.singletonMap(uriString, edits));
ApplyWorkspaceEditParams params = new ApplyWorkspaceEditParams(workspaceEdit, "Organize Imports");
languageClient.applyEdit(params);
return null;
}
示例6
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
boolean response = WorkspaceEditHandler.applyEdit(params.getEdit(), "LSP edits");
return CompletableFuture.supplyAsync(() -> new ApplyWorkspaceEditResponse(response));
}
示例7
@Override
public boolean onServerRequest_applyEdit(ApplyWorkspaceEditParams params) {
changeFilesOnDiskWithoutNotification(params.getEdit());
return true;
}
示例8
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
Utils.applyWorkspaceEdit(params.getEdit());
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
}
示例9
private CompletableFuture<Object> executeAddImportCommand(ExecuteCommandParams params)
{
return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
{
cancelToken.checkCanceled();
compilerWorkspace.startBuilding();
try
{
cancelToken.checkCanceled();
List<Object> args = params.getArguments();
String qualifiedName = ((JsonPrimitive) args.get(0)).getAsString();
String uri = ((JsonPrimitive) args.get(1)).getAsString();
int line = ((JsonPrimitive) args.get(2)).getAsInt();
int character = ((JsonPrimitive) args.get(3)).getAsInt();
if(qualifiedName == null)
{
return new Object();
}
Path pathForImport = LanguageServerCompilerUtils.getPathFromLanguageServerURI(uri);
if(pathForImport == null)
{
return new Object();
}
WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderDataForSourceFile(pathForImport);
if(folderData == null || folderData.project == null)
{
return new Object();
}
String text = fileTracker.getText(pathForImport);
if(text == null)
{
return new Object();
}
int currentOffset = LanguageServerCompilerUtils.getOffsetFromPosition(new StringReader(text), new Position(line, character));
ImportRange importRange = null;
if(uri.endsWith(FILE_EXTENSION_MXML))
{
MXMLData mxmlData = workspaceFolderManager.getMXMLDataForPath(pathForImport, folderData);
IMXMLTagData offsetTag = MXMLDataUtils.getOffsetMXMLTag(mxmlData, currentOffset);
importRange = ImportRange.fromOffsetTag(offsetTag, currentOffset);
}
else
{
IASNode offsetNode = workspaceFolderManager.getOffsetNode(pathForImport, currentOffset, folderData);
importRange = ImportRange.fromOffsetNode(offsetNode);
}
WorkspaceEdit workspaceEdit = CodeActionsUtils.createWorkspaceEditForAddImport(
qualifiedName, text, uri, importRange);
if(workspaceEdit == null)
{
//no edit required
return new Object();
}
ApplyWorkspaceEditParams editParams = new ApplyWorkspaceEditParams();
editParams.setEdit(workspaceEdit);
languageClient.applyEdit(editParams);
return new Object();
}
finally
{
compilerWorkspace.doneBuilding();
}
});
}
示例10
private CompletableFuture<Object> executeAddMXMLNamespaceCommand(ExecuteCommandParams params)
{
return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
{
cancelToken.checkCanceled();
compilerWorkspace.startBuilding();
try
{
cancelToken.checkCanceled();
List<Object> args = params.getArguments();
String nsPrefix = ((JsonPrimitive) args.get(0)).getAsString();
String nsUri = ((JsonPrimitive) args.get(1)).getAsString();
String uri = ((JsonPrimitive) args.get(2)).getAsString();
int startIndex = ((JsonPrimitive) args.get(3)).getAsInt();
int endIndex = ((JsonPrimitive) args.get(4)).getAsInt();
if(nsPrefix == null || nsUri == null)
{
return new Object();
}
Path pathForImport = LanguageServerCompilerUtils.getPathFromLanguageServerURI(uri);
if(pathForImport == null)
{
return new Object();
}
String text = fileTracker.getText(pathForImport);
if(text == null)
{
return new Object();
}
WorkspaceEdit workspaceEdit = CodeActionsUtils.createWorkspaceEditForAddMXMLNamespace(nsPrefix, nsUri, text, uri, startIndex, endIndex);
if(workspaceEdit == null)
{
//no edit required
return new Object();
}
ApplyWorkspaceEditParams editParams = new ApplyWorkspaceEditParams();
editParams.setEdit(workspaceEdit);
languageClient.applyEdit(editParams);
return new Object();
}
finally
{
compilerWorkspace.doneBuilding();
}
});
}
示例11
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
return noImpl3.applyEdit(params);
}
示例12
/**
* The workspace/applyEdit request is sent from the server to the client to modify resource on the client side.
*/
@JsonRequest("workspace/applyEdit")
default CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
throw new UnsupportedOperationException();
}
示例13
/**
* Sends a message to client to apply the given workspace edit.
* This is available since LSP v3.0 should be used
* only by checking the ClientCapabilities.
*
* @param edit
*/
public boolean applyWorkspaceEdit(WorkspaceEdit edit){
ApplyWorkspaceEditParams $ = new ApplyWorkspaceEditParams();
$.setEdit(edit);
ApplyWorkspaceEditResponse response = client.applyEdit($).join();
return response.isApplied();
}
示例14
/**
* Invoked when the LSP server sends the {@link LanguageClient#applyEdit(ApplyWorkspaceEditParams)
* workspace/applyEdit} request to the client during an {@link AbstractIdeTest N4JS IDE test}.
* <p>
* NOTE: will be invoked from one of the server's worker threads!
*
* @return <code>true</code> iff the workspace edit was applied.
*/
public boolean onServerRequest_applyEdit(ApplyWorkspaceEditParams params);