Skip to content

Commit

Permalink
feat(devin-lang): introduce variable identifier and completion support
Browse files Browse the repository at this point in the history
…#101

This commit introduces a new token type 'IDENTIFIER' and corresponding changes across the DevInLanguage extension, including the grammar, lexer, and completion contributor. The 'IDENTIFIER' token is now recognized in the lexer and used in the parser to represent variable identifiers. The completion provider has been updated to trigger on 'VARIABLE_ID' tokens, allowing for auto-completion of variable names. Additionally, the lexer now supports a 'VARIABLE_BLOCK' state to handle variable definitions. These changes enhance the language support for variable management within DevInLanguage.
  • Loading branch information
phodal committed Mar 11, 2024
1 parent 03c6d92 commit 6e30a9c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
9 changes: 8 additions & 1 deletion exts/devin-lang/src/grammar/DevInLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import com.intellij.psi.TokenType;

%s CONTEXT_BLOCK
%s AGENT_BLOCK
%s VARIABLE_BLOCK

IDENTIFIER=[a-zA-Z0-9]([_\-a-zA-Z0-9]*)
VARIABLE_ID=[a-zA-Z0-9]([_\-a-zA-Z0-9]*)
REF_BLOCK=([$/@] {IDENTIFIER} )
TEXT_SEGMENT=[^$/@]+
NEWLINE=\n|\r\n
Expand All @@ -44,7 +46,7 @@ NEWLINE=\n|\r\n
<YYINITIAL> {
"@" { yybegin(AGENT_BLOCK); return AGENT_START; }
"/" { yybegin(AGENT_BLOCK); return COMMAND_START; }
"$" { yybegin(AGENT_BLOCK); return VARIABLE_START; }
"$" { yybegin(VARIABLE_BLOCK); return VARIABLE_START; }

{TEXT_SEGMENT} { return TEXT_SEGMENT; }
{NEWLINE} { return NEWLINE; }
Expand All @@ -55,3 +57,8 @@ NEWLINE=\n|\r\n
{IDENTIFIER} { yybegin(YYINITIAL); return IDENTIFIER; }
[^] { return TokenType.BAD_CHARACTER; }
}

<VARIABLE_BLOCK> {
{VARIABLE_ID} { yybegin(YYINITIAL); return VARIABLE_ID; }
[^] { return TokenType.BAD_CHARACTER; }
}
11 changes: 4 additions & 7 deletions exts/devin-lang/src/grammar/DevInParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
AGENT_START = "AGENT_START"
COMMAND_START = "COMMAND_START"
VARIABLE_START = "VARIABLE_START"
IDENTIFIER = "IDENTIFIER"
]
}

DevInFile ::= (used | TEXT_SEGMENT | CODE_FENCE | NEWLINE)*

used ::= (
AGENT_START agentId?
| COMMAND_START commandId?
| VARIABLE_START variableId?
AGENT_START AGENT_ID?
| COMMAND_START COMMAND_ID?
| VARIABLE_START VARIABLE_ID?
)

agentId ::= IDENTIFIER
commandId ::= IDENTIFIER
variableId ::= IDENTIFIER
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DevInCompletionContributor : CompletionContributor() {
init {
extend(
CompletionType.BASIC,
psiElement(DevInTypes.VARIABLE_START),
psiElement(DevInTypes.VARIABLE_ID),
VariableProvider()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ class DevInTypedHandler : TypedHandlerDelegate() {

return when (charTyped) {
'@' -> {
PsiDocumentManager.getInstance(project).commitDocument(editor.document)
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null)
Result.STOP
}

'/' -> {
PsiDocumentManager.getInstance(project).commitDocument(editor.document)
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null)
Result.STOP
}

'$' -> {
PsiDocumentManager.getInstance(project).commitDocument(editor.document)
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null)
Result.STOP
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class VariableProvider: CompletionProvider<CompletionParameters>() {
) {
CustomVariable.all().forEach {
val withTypeText = LookupElementBuilder.create(it.variable).withTypeText(it.description, true)

result.addElement(withTypeText)
}
}
Expand Down

0 comments on commit 6e30a9c

Please sign in to comment.