mirror of
https://github.com/ilyakooo0/intellij-haskell.git
synced 2024-09-11 14:56:19 +03:00
feat(test): Provide SUT_NAME property to Haskell test Module
Closes #396.
This commit is contained in:
parent
a6d5851c32
commit
c1a57f0566
@ -1,2 +1,3 @@
|
||||
module ${NAME} where
|
||||
|
||||
import qualified ${SUT_NAME} as SUT
|
@ -1,5 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This is a Haskell test module file template.
|
||||
This is a Haskell test module file template. You can refer to the module under test with ${SUT_NAME}.
|
||||
</body>
|
||||
</html>
|
||||
|
@ -17,6 +17,7 @@
|
||||
package intellij.haskell.action
|
||||
|
||||
import java.text.ParseException
|
||||
import java.util.Properties
|
||||
|
||||
import com.intellij.ide.actions.CreateFileFromTemplateDialog.Builder
|
||||
import com.intellij.ide.actions.{CreateFileAction, CreateFileFromTemplateAction}
|
||||
@ -66,6 +67,10 @@ class CreateHaskellFileAction extends CreateFileFromTemplateAction(CreateHaskell
|
||||
}
|
||||
|
||||
override def createFileFromTemplate(fileName: String, template: FileTemplate, fileDir: PsiDirectory): PsiFile = {
|
||||
createFileFromTemplate(fileName, template, fileDir, new Properties())
|
||||
}
|
||||
|
||||
def createFileFromTemplate(fileName: String, template: FileTemplate, fileDir: PsiDirectory, additionalProps: Properties): PsiFile = {
|
||||
val path = HaskellFileUtil.getAbsolutePath(fileDir.getVirtualFile)
|
||||
val pathItems = ProjectRootManager.getInstance(fileDir.getProject)
|
||||
.getContentSourceRoots
|
||||
@ -88,9 +93,9 @@ class CreateHaskellFileAction extends CreateFileFromTemplateAction(CreateHaskell
|
||||
targetDir = Option(targetDir.findSubdirectory(dirName)).getOrElse(targetDir.createSubdirectory(dirName))
|
||||
})
|
||||
|
||||
createFileFromTemplate(pathItems.map(_ ++ prefixes), moduleName, template, targetDir)
|
||||
createFileFromTemplate(pathItems.map(_ ++ prefixes), moduleName, template, targetDir, additionalProps)
|
||||
} else {
|
||||
createFileFromTemplate(pathItems, fileName, template, fileDir)
|
||||
createFileFromTemplate(pathItems, fileName, template, fileDir, additionalProps)
|
||||
}
|
||||
|
||||
createFileResult match {
|
||||
@ -101,7 +106,7 @@ class CreateHaskellFileAction extends CreateFileFromTemplateAction(CreateHaskell
|
||||
}
|
||||
}
|
||||
|
||||
private def createFileFromTemplate(pathItems: Option[List[String]], fileName: String, template: FileTemplate, fileDir: PsiDirectory): Option[(PsiFile, String)] = {
|
||||
private def createFileFromTemplate(pathItems: Option[List[String]], fileName: String, template: FileTemplate, fileDir: PsiDirectory, additionalProps: Properties): Option[(PsiFile, String)] = {
|
||||
pathItems match {
|
||||
case None => None
|
||||
case Some(items) =>
|
||||
@ -120,6 +125,7 @@ class CreateHaskellFileAction extends CreateFileFromTemplateAction(CreateHaskell
|
||||
// Patch props with custom property.
|
||||
val props = FileTemplateManager.getInstance(project).getDefaultProperties()
|
||||
props.setProperty("NAME", nameWithmodulePrefix)
|
||||
props.putAll(additionalProps)
|
||||
|
||||
val element = FileTemplateUtil.createFromTemplate(template, name, props, dir)
|
||||
val psiFile = element.getContainingFile.getOriginalFile
|
||||
|
@ -1,5 +1,7 @@
|
||||
package intellij.haskell.testIntegration
|
||||
|
||||
import java.util.Properties
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager
|
||||
@ -35,10 +37,12 @@ class CreateHaskellTestAction extends PsiElementBaseIntentionAction {
|
||||
val testTemplate = FileTemplateManager.getInstance(project).getInternalTemplate("Haskell Test Module")
|
||||
|
||||
val createTestFileAction = new CreateHaskellFileAction()
|
||||
val additionalProps = new Properties()
|
||||
additionalProps.setProperty("SUT_NAME", moduleName)
|
||||
|
||||
// If the user left the dialog by any other mean than "OK" then abort everything
|
||||
if (!createTestDialog.showAndGet) return
|
||||
val testFileCreation: Runnable = () => createTestFileAction.createFileFromTemplate(createTestDialog.getModuleName, testTemplate, testRootDirectory)
|
||||
val testFileCreation: Runnable = () => createTestFileAction.createFileFromTemplate(createTestDialog.getModuleName, testTemplate, testRootDirectory, additionalProps)
|
||||
try {
|
||||
WriteCommandAction.runWriteCommandAction(project, testFileCreation)
|
||||
} catch {
|
||||
|
Loading…
Reference in New Issue
Block a user