Search in sources :

Example 1 with CreateFileOptions

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

the class ChangeUtil method convertCreateCompilationUnitChange.

private static void convertCreateCompilationUnitChange(WorkspaceEdit edit, CreateCompilationUnitChange change) {
    ICompilationUnit unit = change.getCu();
    CreateFile createFile = new CreateFile();
    createFile.setUri(JDTUtils.toURI(unit));
    createFile.setOptions(new CreateFileOptions(false, true));
    edit.getDocumentChanges().add(Either.forRight(createFile));
    InsertEdit textEdit = new InsertEdit(0, change.getPreview());
    convertTextEdit(edit, unit, textEdit);
}
Also used : CreateFile(org.eclipse.lsp4j.CreateFile) CreateFileOptions(org.eclipse.lsp4j.CreateFileOptions) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) InsertEdit(org.eclipse.text.edits.InsertEdit)

Example 2 with CreateFileOptions

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

the class ChangeUtil method convertCreateFileChange.

private static void convertCreateFileChange(WorkspaceEdit edit, CreateFileChange createFileChange) {
    CreateFile createFile = new CreateFile();
    createFile.setUri(ResourceUtils.fixURI(createFileChange.getPath().toFile().toURI()));
    createFile.setOptions(new CreateFileOptions(false, true));
    edit.getDocumentChanges().add(Either.forRight(createFile));
}
Also used : CreateFile(org.eclipse.lsp4j.CreateFile) CreateFileOptions(org.eclipse.lsp4j.CreateFileOptions)

Example 3 with CreateFileOptions

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

the class ChangeUtil method convertRenamePackcageChange.

private static void convertRenamePackcageChange(WorkspaceEdit edit, RenamePackageChange packageChange) throws CoreException {
    IPackageFragment pack = (IPackageFragment) packageChange.getModifiedElement();
    IPath newPackageFragment = new Path(packageChange.getNewName().replace('.', IPath.SEPARATOR));
    IPath oldPackageFragment = new Path(packageChange.getOldName().replace('.', IPath.SEPARATOR));
    IPath newPackagePath = pack.getResource().getLocation().removeLastSegments(oldPackageFragment.segmentCount()).append(newPackageFragment);
    if (packageChange.getRenameSubpackages()) {
        IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
        String oldPrefix = packageChange.getOldName();
        for (IPackageFragment currentPackage : allPackages) {
            String newPkgName = packageChange.getNewName() + currentPackage.getElementName().substring(oldPrefix.length());
            // update package's declaration
            convertPackageUpdateEdit(currentPackage.getCompilationUnits(), newPkgName, edit);
        }
        RenameFile renameFile = new RenameFile();
        renameFile.setNewUri(ResourceUtils.fixURI(newPackagePath.toFile().toURI()));
        renameFile.setOldUri(ResourceUtils.fixURI(pack.getResource().getRawLocationURI()));
        edit.getDocumentChanges().add(Either.forRight(renameFile));
    } else {
        // update package's declaration
        convertPackageUpdateEdit(pack.getCompilationUnits(), packageChange.getNewName(), edit);
        CreateFile createFile = new CreateFile();
        createFile.setUri(ResourceUtils.fixURI(newPackagePath.append(TEMP_FILE_NAME).toFile().toURI()));
        createFile.setOptions(new CreateFileOptions(false, true));
        edit.getDocumentChanges().add(Either.forRight(createFile));
        for (ICompilationUnit unit : pack.getCompilationUnits()) {
            RenameFile cuResourceChange = new RenameFile();
            cuResourceChange.setOldUri(ResourceUtils.fixURI(unit.getResource().getLocationURI()));
            IPath newCUPath = newPackagePath.append(unit.getPath().lastSegment());
            cuResourceChange.setNewUri(ResourceUtils.fixURI(newCUPath.toFile().toURI()));
            edit.getDocumentChanges().add(Either.forRight(cuResourceChange));
        }
        // Workaround: https://github.com/Microsoft/language-server-protocol/issues/272
        DeleteFile deleteFile = new DeleteFile();
        deleteFile.setUri(ResourceUtils.fixURI(newPackagePath.append(TEMP_FILE_NAME).toFile().toURI()));
        deleteFile.setOptions(new DeleteFileOptions(false, true));
        edit.getDocumentChanges().add(Either.forRight(deleteFile));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) CreateFile(org.eclipse.lsp4j.CreateFile) CreateFileOptions(org.eclipse.lsp4j.CreateFileOptions) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) DeleteFileOptions(org.eclipse.lsp4j.DeleteFileOptions) RenameFile(org.eclipse.lsp4j.RenameFile) DeleteFile(org.eclipse.lsp4j.DeleteFile)

Aggregations

CreateFile (org.eclipse.lsp4j.CreateFile)3 CreateFileOptions (org.eclipse.lsp4j.CreateFileOptions)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 DeleteFile (org.eclipse.lsp4j.DeleteFile)1 DeleteFileOptions (org.eclipse.lsp4j.DeleteFileOptions)1 RenameFile (org.eclipse.lsp4j.RenameFile)1 InsertEdit (org.eclipse.text.edits.InsertEdit)1