Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for IFT (IDE Features Trainer) #871

Open
SingingBush opened this issue Jun 26, 2023 · 0 comments
Open

add support for IFT (IDE Features Trainer) #871

SingingBush opened this issue Jun 26, 2023 · 0 comments

Comments

@SingingBush
Copy link
Member

In recent versions of IDEA there is a plugin with the id of training which we can use as an optional dependency (it'll need to be added to the plugins array in build.gradle as well)

<depends optional="true" config-file="training.xml">training</depends>

This will give some extension points that can be setup with something like:

    <extensions defaultExtensionNs="training">
        <!-- with the 'IDE Features Trainer' (id: 'training') plugin installed (included in Intellij IDEA) -->
        <ift.language.extension language="D" defaultProductName="IDEA" learnWindowAnchor="right"
                                implementationClass="io.github.intellij.dlanguage.training.DlangSupport"/>
        <ift.learning.course language="D" implementationClass="io.github.intellij.dlanguage.training.DlangLearningCourse"/>
    </extensions>
class DlangSupport : AbstractLangSupport() {

    override val primaryLanguage: String
        get() = DLanguage.id

    override fun applyToProjectAfterConfigure(): (Project) -> Unit = { newProject ->
        invokeLater { ProjectUtils.markDirectoryAsSourcesRoot(newProject, "src") }
    }

    override fun checkSdk(sdk: Sdk?, project: Project) {}

    override fun isSdkConfigured(project: Project): Boolean {
        return ProjectRootManager.getInstance(project).projectSdk?.sdkType is DlangSdkType
    }
}

this is very rough work in progress (look at the equivalent Java training)

/**
 * Add a training course for "D" language
 */
class DlangLearningCourse : LearningCourseBase(DLanguage.id) {

    override fun modules(): Collection<IftModule> = stableModules()

    private fun stableModules() = listOf(
        LearningModule(id = "D.Essential",
            name = LessonsBundle.message("essential.module.name"),
            description = LessonsBundle.message("essential.module.description", LessonUtil.productName),
            primaryLanguage = langSupport,
            moduleType = LessonType.SCRATCH) {
            listOf(
                DlangBasicCompletionLesson(),
                // todo: add more lessons
            )
        }
    )

    class DlangBasicCompletionLesson : KLesson("Basic completion", LessonsBundle.message("basic.completion.lesson.name")) {
        private val sample = parseLessonSample("""
            import std.stdio, std.array, std.algorithm;
            void main() {
                stdin.byLineCopy.
            }
            """.trimIndent())

        override val lessonContent: LessonContext.() -> Unit = {
            prepareSample(sample)
            task {
                text("Try an auto complete")
                //action("EditorChooseLookupItem")
            }
            caret(2, 21) 
            // todo: finish this code
        }
    }
}

It's worth checking the following readme as well: https://github.com/JetBrains/intellij-community/blob/9fdd68f908db0b6bb6e08dc33fafb26e2e4712af/plugins/ide-features-trainer/src/HowToCreateLessons.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant