Java Code Examples for org.eclipse.lsp4j.WorkspaceEdit#setChanges()

The following examples show how to use org.eclipse.lsp4j.WorkspaceEdit#setChanges() . 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: N4JSCodeActionService.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Applies all fixes of the same kind to the project containing the given URI.
 */
public WorkspaceEdit applyToProject(URI uri, String issueCode, String fixId, CancelIndicator cancelIndicator) {

	WorkspaceEdit result = new WorkspaceEdit();
	QuickFixImplementation quickfix = findOriginatingQuickfix(issueCode, fixId);
	if (quickfix == null) {
		return result;
	}

	Optional<? extends IN4JSProject> project = n4jsCore.findProject(uri);
	if (!project.isPresent()) {
		return result;
	}
	List<URI> urisInProject = Lists.newArrayList(
			IterableExtensions.flatMap(project.get().getSourceContainers(), sc -> sc));

	Map<String, List<TextEdit>> allEdits = new HashMap<>();
	for (URI currURI : urisInProject) {
		Map<String, List<TextEdit>> edits = doApplyToFile(currURI, issueCode, quickfix, cancelIndicator);
		allEdits.putAll(edits);
	}
	result.setChanges(allEdits);
	return result;
}
 
Example 2
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForAddImport(IDefinition definition, String fileText, String uri, ImportRange importRange)
{
    TextEdit textEdit = createTextEditForAddImport(definition.getQualifiedName(), fileText, importRange);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 3
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForAddImport(String qualfiedName, String fileText, String uri, ImportRange importRange)
{
    TextEdit textEdit = createTextEditForAddImport(qualfiedName, fileText, importRange);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 4
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForAddMXMLNamespace(String nsPrefix, String nsURI, String fileText, String fileURI, int startIndex, int endIndex)
{
    TextEdit textEdit = createTextEditForAddMXMLNamespace(nsPrefix, nsURI, fileText, startIndex, endIndex);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(fileURI, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 5
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForGenerateLocalVariable(
    IIdentifierNode identifierNode, String uri, String text)
{
    TextEdit textEdit = createTextEditForGenerateLocalVariable(identifierNode, text);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 6
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForGenerateFieldVariable(
    IIdentifierNode identifierNode, String uri, String text)
{
    TextEdit textEdit = createTextEditForGenerateFieldVariable(identifierNode, text);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 7
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForGenerateGetterAndSetter(
    IVariableNode variableNode, String uri, String text, boolean generateGetter, boolean generateSetter)
{
    TextEdit textEdit = createTextEditForGenerateGetterAndSetter(variableNode, text, generateGetter, generateSetter);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 8
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForGenerateCatch(
    ITryNode tryNode, String uri, String text, ICompilerProject project)
{
    TextEdit textEdit = createTextEditForGenerateCatch(tryNode, text, project);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 9
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForGenerateEventListener(
    IASNode context, String functionName, String eventClassName,
    String uri, String text, ICompilerProject project)
{
    List<TextEdit> textEdits = createTextEditsForGenerateEventListener(context, functionName, eventClassName, text, project);
    if (textEdits == null || textEdits.size() == 0)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    changes.put(uri, textEdits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 10
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForRemoveUnusedImport(String fileText, String uri, Range range)
{
    TextEdit textEdit = createTextEditForRemoveUnusedImport(fileText, range);
    if (textEdit == null)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    List<TextEdit> edits = new ArrayList<>();
    edits.add(textEdit);
    changes.put(uri, edits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 11
Source File: N4JSCodeActionService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Applies all fixes of the same kind to the file with the given URI.
 */
public WorkspaceEdit applyToFile(URI uri, String issueCode, String fixId, CancelIndicator cancelIndicator) {

	WorkspaceEdit result = new WorkspaceEdit();
	QuickFixImplementation quickfix = findOriginatingQuickfix(issueCode, fixId);
	if (quickfix == null) {
		return result;
	}

	Map<String, List<TextEdit>> edits = doApplyToFile(uri, issueCode, quickfix, cancelIndicator);
	result.setChanges(edits);
	return result;
}
 
Example 12
Source File: CodeActionAcceptor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Adds a quick-fix code action with the given title and text edits */
@Override
public void acceptQuickfixCodeAction(QuickfixContext context, String title, List<TextEdit> textEdits) {
	if (textEdits == null || textEdits.isEmpty()) {
		return;
	}

	String uri = context.options.getCodeActionParams().getTextDocument().getUri();
	Map<String, List<TextEdit>> changes = new HashMap<>();
	changes.put(uri, textEdits);
	WorkspaceEdit edit = new WorkspaceEdit();
	edit.setChanges(changes);
	acceptQuickfixCodeAction(context, title, edit, null);
}
 
Example 13
Source File: ChangeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void appendChanges(WorkspaceEdit root, WorkspaceEdit child, boolean ignoreResourceChange) {
	if (root == null || child == null) {
		return;
	}

	if (child.getChanges() != null && !child.getChanges().isEmpty()) {
		if (root.getChanges() == null) {
			root.setChanges(new LinkedHashMap<>());
		}

		for (Entry<String, List<org.eclipse.lsp4j.TextEdit>> entry : child.getChanges().entrySet()) {
			root.getChanges().computeIfAbsent(entry.getKey(), (key -> new ArrayList<>()));
			root.getChanges().get(entry.getKey()).addAll(entry.getValue());
		}
	}

	if (child.getDocumentChanges() != null && !child.getDocumentChanges().isEmpty()) {
		if (root.getDocumentChanges() == null) {
			root.setDocumentChanges(new ArrayList<>());
		}

		if (ignoreResourceChange) {
			root.getDocumentChanges().addAll(
				child.getDocumentChanges().stream().filter((change) -> change.isLeft()).collect(Collectors.toList())
			);
		} else {
			root.getDocumentChanges().addAll(child.getDocumentChanges());
		}
	}
}
 
Example 14
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForImplementInterface(
    IClassNode classNode, IInterfaceDefinition interfaceDefinition, String uri, String text, ICompilerProject project)
{
    List<TextEdit> textEdits = createTextEditsForImplementInterface(classNode, interfaceDefinition, text, project);
    if (textEdits == null || textEdits.size() == 0)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    changes.put(uri, textEdits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}
 
Example 15
Source File: CodeActionsUtils.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
public static WorkspaceEdit createWorkspaceEditForGenerateMethod(
    IFunctionCallNode functionCallNode, String uri, String text, ICompilerProject project)
{
    List<TextEdit> textEdits = createTextEditsForGenerateMethod(functionCallNode, text, project);
    if (textEdits == null || textEdits.size() == 0)
    {
        return null;
    }

    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    HashMap<String,List<TextEdit>> changes = new HashMap<>();
    changes.put(uri, textEdits);
    workspaceEdit.setChanges(changes);
    return workspaceEdit;
}