Added support for extern declarations and enhanced .lyng.d merging
- Implemented `extern` support for functions, classes, objects, enums, and properties in the `MiniAST`. - Updated `MiniAST` to include `isExtern` field for applicable nodes. - Enabled merging of `.lyng.d` declaration files into main `.lyng` scripts. - Adjusted tests to validate `extern` behavior and documentation handling. - Minor fixes to parser logic for improved robustness.
This commit is contained in:
1 parent
44675b976d
commit
fdc044d1e0
8 files changed
+310
-95
No files matched your search
@@ -19,6 +19,7 @@ package net.sergeych.lyng.idea.util
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.sergeych.lyng.Compiler
|
||||
import net.sergeych.lyng.Source
|
||||
@@ -45,7 +46,11 @@ object LyngAstManager {
|
||||
val provider = IdeLenientImportProvider.create()
|
||||
val src = Source(file.name, text)
|
||||
runBlocking { Compiler.compileWithMini(src, provider, sink) }
|
||||
sink.build()
|
||||
val script = sink.build()
|
||||
if (script != null && !file.name.endsWith(".lyng.d")) {
|
||||
mergeDeclarationFiles(file, script)
|
||||
}
|
||||
script
|
||||
} catch (_: Throwable) {
|
||||
sink.build()
|
||||
}
|
||||
@@ -59,6 +64,26 @@ object LyngAstManager {
|
||||
return built
|
||||
}
|
||||
|
||||
private fun mergeDeclarationFiles(file: PsiFile, mainScript: MiniScript) {
|
||||
val psiManager = PsiManager.getInstance(file.project)
|
||||
var current = file.virtualFile?.parent
|
||||
val seen = mutableSetOf<String>()
|
||||
|
||||
while (current != null) {
|
||||
for (child in current.children) {
|
||||
if (child.name.endsWith(".lyng.d") && child != file.virtualFile && seen.add(child.path)) {
|
||||
val psiD = psiManager.findFile(child) ?: continue
|
||||
val scriptD = getMiniAst(psiD)
|
||||
if (scriptD != null) {
|
||||
mainScript.declarations.addAll(scriptD.declarations)
|
||||
mainScript.imports.addAll(scriptD.imports)
|
||||
}
|
||||
}
|
||||
}
|
||||
current = current.parent
|
||||
}
|
||||
}
|
||||
|
||||
fun getBinding(file: PsiFile): BindingSnapshot? {
|
||||
val doc = file.viewProvider.document ?: return null
|
||||
val stamp = doc.modificationStamp
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<!-- Language and file type -->
|
||||
<fileType implementationClass="net.sergeych.lyng.idea.LyngFileType" name="Lyng" extensions="lyng" fieldName="INSTANCE" language="Lyng"/>
|
||||
<fileType implementationClass="net.sergeych.lyng.idea.LyngFileType" name="Lyng" extensions="lyng;lyng.d" fieldName="INSTANCE" language="Lyng"/>
|
||||
|
||||
<!-- Minimal parser/PSI to fully wire editor services for the language -->
|
||||
<lang.parserDefinition language="Lyng" implementationClass="net.sergeych.lyng.idea.psi.LyngParserDefinition"/>
|
||||
|
||||
Reference in new issue
Block a user