mirror of
https://github.com/ilyakooo0/intellij-haskell.git
synced 2024-09-11 14:56:19 +03:00
Save file as is. Fix issue #459
This commit is contained in:
parent
fc9f61553e
commit
ceb6727753
@ -69,9 +69,9 @@ class HaskellAnnotator extends ExternalAnnotator[PsiFile, CompilationResult] {
|
||||
override def doAnnotate(psiFile: PsiFile): CompilationResult = {
|
||||
HaskellFileUtil.findVirtualFile(psiFile) match {
|
||||
case Some(virtualFile) =>
|
||||
val fileChanged = FileDocumentManager.getInstance().isFileModified(virtualFile)
|
||||
HaskellFileUtil.saveFileInDispatchThread(psiFile.getProject, virtualFile)
|
||||
HaskellComponentsManager.loadHaskellFile(psiFile, fileChanged).orNull
|
||||
val fileModified = FileDocumentManager.getInstance().isFileModified(virtualFile)
|
||||
HaskellFileUtil.saveFileAsIsInDispatchThread(psiFile.getProject, virtualFile)
|
||||
HaskellComponentsManager.loadHaskellFile(psiFile, fileModified).orNull
|
||||
case None => CompilationResult(Iterable(), Iterable(), failed = false)
|
||||
}
|
||||
}
|
||||
|
@ -117,8 +117,8 @@ object HaskellComponentsManager {
|
||||
StackReplsManager.getReplsManager(project).map(_.moduleCabalInfos.map { case (_, ci) => ci }).getOrElse(Iterable())
|
||||
}
|
||||
|
||||
def loadHaskellFile(psiFile: PsiFile, fileChanged: Boolean): Option[CompilationResult] = {
|
||||
LoadComponent.load(psiFile, fileChanged)
|
||||
def loadHaskellFile(psiFile: PsiFile, fileModified: Boolean): Option[CompilationResult] = {
|
||||
LoadComponent.load(psiFile, fileModified)
|
||||
}
|
||||
|
||||
def invalidateFileInfos(psiFile: PsiFile): Unit = {
|
||||
|
@ -37,7 +37,7 @@ private[component] object LoadComponent {
|
||||
}.contains(true)
|
||||
}
|
||||
|
||||
def load(psiFile: PsiFile, fileChanged: Boolean): Option[CompilationResult] = {
|
||||
def load(psiFile: PsiFile, fileModified: Boolean): Option[CompilationResult] = {
|
||||
val project = psiFile.getProject
|
||||
|
||||
StackReplsManager.getProjectRepl(psiFile).flatMap(projectRepl => {
|
||||
@ -51,7 +51,7 @@ private[component] object LoadComponent {
|
||||
|
||||
ProjectLibraryFileWatcher.checkLibraryBuild(project, projectRepl.stackComponentInfo)
|
||||
|
||||
projectRepl.load(psiFile, fileChanged, mustBeByteCode = false) match {
|
||||
projectRepl.load(psiFile, fileModified, mustBeByteCode = false) match {
|
||||
case Some((loadOutput, loadFailed)) =>
|
||||
ApplicationManager.getApplication.executeOnPooledThread(ScalaUtil.runnable {
|
||||
|
||||
|
@ -89,7 +89,7 @@ object StackProjectManager {
|
||||
}
|
||||
|
||||
def restart(project: Project): Unit = {
|
||||
HaskellFileUtil.saveAllFiles(project)
|
||||
HaskellFileUtil.saveFiles(project)
|
||||
|
||||
init(project, restart = true)
|
||||
}
|
||||
|
@ -146,9 +146,9 @@ case class ProjectStackRepl(project: Project, stackComponentInfo: StackComponent
|
||||
}
|
||||
}
|
||||
|
||||
def load(psiFile: PsiFile, fileChanged: Boolean, mustBeByteCode: Boolean): Option[(StackReplOutput, Boolean)] = synchronized {
|
||||
def load(psiFile: PsiFile, fileModified: Boolean, mustBeByteCode: Boolean): Option[(StackReplOutput, Boolean)] = synchronized {
|
||||
val forceBytecodeLoad = if (mustBeByteCode) objectCodeEnabled else false
|
||||
val reload = if (forceBytecodeLoad || !fileChanged) {
|
||||
val reload = if (forceBytecodeLoad || !fileModified) {
|
||||
false
|
||||
} else {
|
||||
val loaded = isFileLoaded(psiFile)
|
||||
@ -196,7 +196,7 @@ case class ProjectStackRepl(project: Project, stackComponentInfo: StackComponent
|
||||
}
|
||||
|
||||
def getModuleIdentifiers(moduleName: String, psiFile: Option[PsiFile]): Option[StackReplOutput] = synchronized {
|
||||
if (psiFile.isEmpty || isBrowseModuleLoaded(moduleName) || psiFile.exists(pf => load(pf, fileChanged = false, mustBeByteCode = false).exists(_._2 == false))) {
|
||||
if (psiFile.isEmpty || isBrowseModuleLoaded(moduleName) || psiFile.exists(pf => load(pf, fileModified = false, mustBeByteCode = false).exists(_._2 == false))) {
|
||||
execute(s":browse! $moduleName")
|
||||
} else {
|
||||
HaskellNotificationGroup.logInfoEvent(project, s"Couldn't get module identifiers for module $moduleName because file ${psiFile.map(_.getName).getOrElse("-")} isn't loaded")
|
||||
@ -224,7 +224,7 @@ case class ProjectStackRepl(project: Project, stackComponentInfo: StackComponent
|
||||
case Some(info) if info.psiFile == psiFile & !info.loadFailed & (if (mustBeByteCode) !objectCodeEnabled else true) => execute(command)
|
||||
case Some(info) if info.psiFile == psiFile & info.loadFailed => Some(StackReplOutput())
|
||||
case _ =>
|
||||
load(psiFile, fileChanged = false, mustBeByteCode)
|
||||
load(psiFile, fileModified = false, mustBeByteCode)
|
||||
loadedFile match {
|
||||
case None => None
|
||||
case Some(info) if info.psiFile == psiFile && !info.loadFailed => execute(command)
|
||||
|
@ -61,7 +61,7 @@ class HaskellRenameVariableProcessor extends RenamePsiElementProcessor {
|
||||
override def getPostRenameCallback(targetElement: PsiElement, newName: String, elementListener: RefactoringElementListener): Runnable = {
|
||||
ScalaUtil.runnable {
|
||||
val project = targetElement.getProject
|
||||
HaskellFileUtil.saveAllFiles(project)
|
||||
HaskellFileUtil.saveFiles(project)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ import intellij.haskell.external.component.{NoInfo, NoInfoAvailable}
|
||||
|
||||
object HaskellFileUtil {
|
||||
|
||||
def saveAllFiles(project: Project): Unit = {
|
||||
def saveFiles(project: Project): Unit = {
|
||||
val openFiles = FileEditorManager.getInstance(project).getOpenFiles.filter(HaskellFileUtil.isHaskellFile)
|
||||
val documentManager = PsiDocumentManager.getInstance(project)
|
||||
openFiles.flatMap(f => findDocument(f)).foreach(documentManager.doPostponedOperationsAndUnblockDocument)
|
||||
@ -58,11 +58,11 @@ object HaskellFileUtil {
|
||||
})
|
||||
}
|
||||
|
||||
def saveFileInDispatchThread(project: Project, virtualFile: VirtualFile): Unit = {
|
||||
def saveFileAsIsInDispatchThread(project: Project, virtualFile: VirtualFile): Unit = {
|
||||
findDocument(virtualFile).foreach(d => {
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(d)
|
||||
ApplicationManager.getApplication.invokeAndWait(() => {
|
||||
FileDocumentManager.getInstance.saveDocument(d)
|
||||
FileDocumentManager.getInstance.saveDocumentAsIs(d)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user