Skip to content

Commit 44cf9a1

Browse files
committed
add relation all params completion
1 parent 8c6c6c4 commit 44cf9a1

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ For a list of changes in the newest version, please refer to the [changelog](./C
1111
## 改进
1212
1. 增加了multi head的支持
1313
2. 增加了ByteCodeDL用到的一些语法比如`#if` `#paragma`
14+
3. 增加了relation全部参数的自动补全
15+
![re](./img/relation_all_param_completion.png)
16+
17+
## 遗留问题
18+
1. 本来想支持`cat`等内置的函数,但是和MacroExpr冲突了,不知道怎么解决
1419

1520
## Features
1621

88.6 KB
Loading

src/main/grammars/datalog.flex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ MACRO_CONTINUATION = \\[ \t\f]*{LINE_BREAK}
5656
{WHITE_SPACE} { return WHITE_SPACE; }
5757

5858
"#include" { return INCLUDE_DIRECTIVE; }
59+
"#paragma" { return PARAGMA_DIRECTIVE; }
5960
"#if" {return IF_DIRECTIVE; }
6061
"#ifdef" { return IFDEF_DIRECTIVE; }
6162
"#ifndef" { return IFNDEF_DIRECTIVE; }

src/main/kotlin/com/lfrobeen/datalog/lang/completion/DatalogCompletionScopeProcessor.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.lfrobeen.datalog.lang.psi.DatalogDeclarationComment
1010
import com.lfrobeen.datalog.lang.psi.DatalogDeclarationMixin
1111
import com.lfrobeen.datalog.lang.psi.DatalogTypes
1212
import com.lfrobeen.datalog.lang.psi.elementType
13+
import com.lfrobeen.datalog.lang.psi.impl.DatalogRelDeclImpl
1314

1415
class DatalogCompletionScopeProcessor(private val result: CompletionResultSet) : PsiScopeProcessor {
1516

@@ -22,6 +23,19 @@ class DatalogCompletionScopeProcessor(private val result: CompletionResultSet) :
2223
.withIcon(decl.presentation?.getIcon(false))
2324
.withTypeText(decl.elementType.toString())
2425
)
26+
27+
if (decl is DatalogRelDeclImpl){
28+
val variables = decl.typedIdentifierList.joinToString(separator = ", ") { it.variable.text }
29+
val keyword = decl.name + "(" + variables + ")"
30+
result.addElement(
31+
LookupElementBuilder.create(keyword)
32+
.withPsiElement(decl)
33+
.withBoldness(decl.elementType == DatalogTypes.REL_DECL)
34+
.withIcon(decl.presentation?.getIcon(false))
35+
.withTypeText(decl.elementType.toString())
36+
)
37+
}
38+
2539
}
2640

2741
if (decl is DatalogDeclarationComment && !decl.name.isNullOrEmpty()) {

src/main/kotlin/com/lfrobeen/datalog/lang/completion/DatalogKeywordCompletionContributor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class DatalogKeywordCompletionContributor : CompletionContributor() {
3131
"#ifdef",
3232
"#ifndef",
3333
"#endif",
34-
"#define"
34+
"#define",
35+
"#paragma",
3536
)
3637
)
3738
}

0 commit comments

Comments
 (0)