Skip to content

Commit

Permalink
feat(autoin-lang): add basic infrastructure for AutoDev input languag…
Browse files Browse the repository at this point in the history
…e support #101

AutoDev input language support is a new feature added to the project. The following files have been modified or created to support this new language:
  • Loading branch information
phodal committed Mar 11, 2024
1 parent 7bfe9f0 commit 02c5a04
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 0 deletions.
41 changes: 41 additions & 0 deletions build.gradle.kts
Expand Up @@ -41,6 +41,8 @@ plugins {
alias(libs.plugins.serialization)
alias(libs.plugins.gradleIntelliJPlugin)

id("org.jetbrains.grammarkit") version "2022.3.2.2"

kotlin("jvm") version "1.8.22"
id("net.saliman.properties") version "1.5.2"
}
Expand Down Expand Up @@ -580,6 +582,45 @@ project(":exts:ext-harmonyos") {
}
}

project(":exts:autoin-lang") {
apply {
plugin("org.jetbrains.grammarkit")
}

intellij {
version.set(ideaVersion)
plugins.set(ideaPlugins)
}
dependencies {
implementation(project(":"))
implementation(project(":java"))
}

tasks {
generateLexer {
sourceFile.set(file("src/grammar/DevInLexer.flex"))
// targetDir.set("src/gen/com/feakin/intellij/lexer")
targetOutputDir.set(file("src/gen/cc/unitmesh/language/lexer"))
// targetClass.set("_FeakinLexer")
purgeOldFiles.set(true)
}

generateParser {
sourceFile.set(file("src/grammar/DevInParser.bnf"))
// targetRoot.set("src/gen")
targetRootOutputDir.set(file("src/gen"))
pathToParser.set("cc/unitmesh/language/parser/DevInParser.java")
pathToPsiRoot.set("cc/unitmesh/language/psi")
purgeOldFiles.set(true)
}

withType<KotlinCompile> {
dependsOn(generateLexer, generateParser)
}
}
}


fun File.isPluginJar(): Boolean {
if (!isFile) return false
if (extension != "jar") return false
Expand Down
1 change: 1 addition & 0 deletions exts/autoin-lang/.gitignore
@@ -0,0 +1 @@
src/gen
33 changes: 33 additions & 0 deletions exts/autoin-lang/src/grammar/DevInLexer.flex
@@ -0,0 +1,33 @@
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.intellij.sdk.language;

import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import cc.unitmesh.language.psi.DevInTypes;
import com.intellij.psi.TokenType;

%%

%class DevInLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}

CRLF=\R
WHITE_SPACE=[\ \n\t\f]
FIRST_VALUE_CHARACTER=[^ \n\f\\] | "\\"{CRLF} | "\\".
VALUE_CHARACTER=[^\n\f\\] | "\\"{CRLF} | "\\".
END_OF_LINE_COMMENT=("#"|"!")[^\r\n]*
SEPARATOR=[:=]
KEY_CHARACTER=[^:=\ \n\t\f\\] | "\\ "

%state WAITING_VALUE

%%

({CRLF}|{WHITE_SPACE})+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }

[^] { return TokenType.BAD_CHARACTER; }
20 changes: 20 additions & 0 deletions exts/autoin-lang/src/grammar/DevInParser.bnf
@@ -0,0 +1,20 @@
// should similar to markdown syntax
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
{
parserClass="cc.unitmesh.language.parser.DevInParser"

extends="com.intellij.extapi.psi.ASTWrapperPsiElement"

psiClassPrefix="DevIn"
psiImplClassSuffix="Impl"
psiPackage="cc.unitmesh.language.psi"
psiImplPackage="cc.unitmesh.language.psi.impl"

elementTypeHolderClass="cc.unitmesh.language.psi.DevInTypes"
elementTypeClass="cc.unitmesh.language.psi.DevInElementType"
tokenTypeClass="cc.unitmesh.language.psi.DevInTokenType"
}

DevInFile ::= item_*

private item_ ::= (CRLF)
@@ -0,0 +1,18 @@
package cc.unitmesh.language

import cc.unitmesh.devti.AutoDevIcons
import com.intellij.openapi.fileTypes.LanguageFileType
import com.intellij.openapi.vfs.VirtualFile
import javax.swing.Icon

object DevInFileType : LanguageFileType(DevInLanguage) {
override fun getName(): String = "DevIn File"

override fun getIcon(): Icon = AutoDevIcons.AI_COPILOT

override fun getDefaultExtension(): String = "devin"

override fun getCharset(file: VirtualFile, content: ByteArray): String = "UTF-8"

override fun getDescription(): String = "DevIn file"
}
@@ -0,0 +1,10 @@
package cc.unitmesh.language

import com.intellij.lang.Language

object DevInLanguage : Language("DevIn", "text/devin", "text/x-devin", "application/x-devin") {
val INSTANCE: Language = DevInLanguage

override fun isCaseSensitive() = true
override fun getDisplayName() = "DevIn"
}
@@ -0,0 +1,51 @@
package cc.unitmesh.language

import com.intellij.lang.ASTNode
import com.intellij.lang.ParserDefinition
import com.intellij.lang.PsiParser
import com.intellij.lexer.Lexer
import com.intellij.openapi.project.Project
import com.intellij.psi.FileViewProvider
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.tree.IFileElementType
import com.intellij.psi.tree.TokenSet
import org.jetbrains.annotations.NotNull


internal class DevInParserDefinition : ParserDefinition {
@NotNull
override fun createLexer(project: Project?): Lexer {
TODO()
}

@NotNull
override fun getCommentTokens(): TokenSet = TokenSet.EMPTY

@NotNull
override fun getStringLiteralElements(): TokenSet = TokenSet.EMPTY

@NotNull
override fun createParser(project: Project?): PsiParser {
TODO()
}

@NotNull
override fun getFileNodeType(): IFileElementType {
return FILE
}

@NotNull
override fun createFile(@NotNull viewProvider: FileViewProvider): PsiFile {
TODO()
}

@NotNull
override fun createElement(node: ASTNode?): PsiElement {
TODO()
}

companion object {
val FILE: IFileElementType = IFileElementType(DevInLanguage.INSTANCE)
}
}
@@ -0,0 +1,12 @@
package cc.unitmesh.language

import com.intellij.openapi.fileTypes.SyntaxHighlighter
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile

class DevInSyntaxHighlighterFactory : SyntaxHighlighterFactory() {
override fun getSyntaxHighlighter(project: Project?, virtualFile: VirtualFile?): SyntaxHighlighter {
TODO("Not yet implemented")
}
}
@@ -0,0 +1,13 @@
package cc.unitmesh.language.psi

import com.intellij.psi.tree.IElementType
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.NotNull

class DevInTokenType(
@NotNull @NonNls debugName: String
): IElementType(debugName, cc.unitmesh.language.DevInLanguage.INSTANCE) {
override fun toString(): String {
return "DevInTokenType." + super.toString()
}
}
11 changes: 11 additions & 0 deletions exts/autoin-lang/src/main/resources/cc.unitmesh.language.xml
@@ -0,0 +1,11 @@
<idea-plugin package="cc.unitmesh.language">
<extensions defaultExtensionNs="com.intellij">
<!-- refs: https://github.com/JetBrains/intellij-sdk-code-samples/blob/main/simple_language_plugin/src/main/resources/META-INF/plugin.xml-->
<fileType name="AutoinFile" implementationClass="cc.unitmesh.language.DevInFileType" fieldName="INSTANCE"
language="AutoIn" extensions="autoin"/>

<lang.parserDefinition language="AutoIn" implementationClass="cc.unitmesh.language.DevInParserDefinition"/>
<lang.syntaxHighlighterFactory language="AutoIn"
implementationClass="cc.unitmesh.language.DevInSyntaxHighlighterFactory"/>
</extensions>
</idea-plugin>
3 changes: 3 additions & 0 deletions settings.gradle.kts
Expand Up @@ -23,4 +23,7 @@ include(
// since JetBrains also call `android.jar`, so we rename it to `ext-android`
"exts:ext-android",
"exts:ext-harmonyos",

// the Input Language support for AutoDev
"exts:autoin-lang"
)

0 comments on commit 02c5a04

Please sign in to comment.