mirror of https://gitee.com/makejava/EasyCode.git
文件对比加入代码格式化支持
This commit is contained in:
parent
f937aea970
commit
1acaa4838b
|
@ -1,7 +1,8 @@
|
|||
package com.sjhy.plugin.entity;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
|
@ -62,9 +63,10 @@ public class SaveFile {
|
|||
// 构建文件对象
|
||||
PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
|
||||
LOG.assertTrue(content != null);
|
||||
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
|
||||
// 换行符统一使用\n
|
||||
this.file = psiFileFactory.createFileFromText(fileName, FileTypes.UNKNOWN, content.replace("\r", ""));
|
||||
this.virtualFile = new LightVirtualFile(fileName, content.replace("\r", ""));
|
||||
this.file = psiFileFactory.createFileFromText(fileName, fileType, content.replace("\r", ""));
|
||||
this.virtualFile = new LightVirtualFile(fileName, fileType, content.replace("\r", ""));
|
||||
this.reformat = reformat;
|
||||
this.operateTitle = operateTitle;
|
||||
}
|
||||
|
|
|
@ -123,6 +123,10 @@ public class FileUtils {
|
|||
case Messages.YES:
|
||||
break;
|
||||
case Messages.NO:
|
||||
// 对比代码时也格式化代码
|
||||
if (saveFile.isReformat()) {
|
||||
reformatFile(saveFile.getProject(), Collections.singletonList(PsiManager.getInstance(saveFile.getProject()).findFile(saveFile.getVirtualFile())));
|
||||
}
|
||||
CompareFileUtils.showCompareWindow(saveFile.getProject(), fileDocumentManager.getFile(psiDocumentManager.getDocument(oldFile)), saveFile.getVirtualFile());
|
||||
return;
|
||||
case Messages.CANCEL:
|
||||
|
|
Loading…
Reference in New Issue