org.eclipse.lsp4j.ApplyWorkspaceEditParams Java Examples

The following examples show how to use org.eclipse.lsp4j.ApplyWorkspaceEditParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LanguageClientImpl.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #2
Source File: IdeTestLanguageClient.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@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));
}
 
Example #3
Source File: N4JSCommandService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: N4JSCommandService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: N4JSCommandService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: DefaultLanguageClient.java    From lsp4intellij with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
    boolean response = WorkspaceEditHandler.applyEdit(params.getEdit(), "LSP edits");
    return CompletableFuture.supplyAsync(() -> new ApplyWorkspaceEditResponse(response));
}
 
Example #7
Source File: AbstractIdeTest.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean onServerRequest_applyEdit(ApplyWorkspaceEditParams params) {
	changeFilesOnDiskWithoutNotification(params.getEdit());
	return true;
}
 
Example #8
Source File: LanguageClientImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
    Utils.applyWorkspaceEdit(params.getEdit());
    return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
}
 
Example #9
Source File: ExecuteCommandProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
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();
        }
    });
}
 
Example #10
Source File: ExecuteCommandProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
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();
        }
    });
}
 
Example #11
Source File: CommandRegistryTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
	return noImpl3.applyEdit(params);
}
 
Example #12
Source File: LanguageClient.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * 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();
}
 
Example #13
Source File: JavaClientConnection.java    From eclipse.jdt.ls with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example #14
Source File: IdeTestLanguageClient.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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);