Skip to content

Commit 5e8fac4

Browse files
committed
feat(devins-lang): add support for browsing web content with new command /browse
The `/browse` command has been added to the DevIns language, allowing users to fetch the content of a given URL. This feature refactors the existing command parsing logic and introduces a new `BrowseInsCommand` class to handle the execution of the `/browse` command. The command is now recognized by the DevIns parser and can be used within the language.
1 parent cc9f956 commit 5e8fac4

File tree

8 files changed

+33
-6
lines changed

8 files changed

+33
-6
lines changed

exts/devins-lang/src/grammar/DevInLexer.flex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SYSTEM_ID=[a-zA-Z][_\-a-zA-Z0-9]*
4646
NUMBER=[0-9]+
4747

4848
TEXT_SEGMENT=[^$/@#\n]+
49-
COMMAND_PROP=[^:\ \t\r\n]*
49+
COMMAND_PROP=[^\ \t\r\n]*
5050
CODE_CONTENT=[^\n]+
5151
COMMENTS=\[ ([^\]]+)? \] [^\t\r\n]*
5252
NEWLINE= \n | \r | \r\n
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cc.unitmesh.devti.language.compiler
2+
3+
import cc.unitmesh.devti.language.agenttool.browse.BrowseTool
4+
import cc.unitmesh.devti.language.compiler.exec.InsCommand
5+
import com.intellij.openapi.project.Project
6+
7+
class BrowseInsCommand(val myProject: Project, val prop: String) : InsCommand {
8+
override suspend fun execute(): String? {
9+
val documentContent = BrowseTool.parse(prop)
10+
return documentContent.body
11+
}
12+
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ class DevInsCompiler(
204204
result.isLocalCommand = true
205205
ShellInsCommand(myProject, prop)
206206
}
207+
208+
BuiltinCommand.BROWSE -> {
209+
result.isLocalCommand = true
210+
BrowseInsCommand(myProject, prop)
211+
}
212+
213+
else -> {
214+
PrintInsCommand("/" + commandNode.commandName + ":" + prop)
215+
}
207216
}
208217

209218
val execResult = runBlocking { command.execute() }

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum class BuiltinCommand(
1414
) {
1515
FILE("file", "Read the content of a file", AllIcons.Actions.Copy, true, true),
1616
REV("rev", "Read git change by file", AllIcons.Vcs.History, true, true),
17+
1718
/**
1819
* Every language will have a symbol completion, which is the most basic completion, for example,
1920
* - Java: [com.intellij.codeInsight.completion.JavaKeywordCompletion]
@@ -39,6 +40,7 @@ enum class BuiltinCommand(
3940
true,
4041
true
4142
),
43+
BROWSE("browse", "Get the content of a given URL.", AllIcons.Xml.Browsers.Firefox, false, true),
4244
;
4345

4446
companion object {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/browse:https://ide.unitmesh.cc

exts/devins-lang/src/test/kotlin/cc/unitmesh/devti/language/DevInParsingTest.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ class DevInParsingTest : ParsingTestCase("parser", "devin", DevInParserDefinitio
4040
doTest(true)
4141
}
4242

43-
fun testSystemCalling() {
44-
doTest(true)
45-
}
46-
47-
fun testSingleComment() {
43+
fun testBrowseWeb() {
4844
doTest(true)
4945
}
5046
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/browse:https://ide.unitmesh.cc
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DevInFile
2+
DevInUsedImpl(USED)
3+
PsiElement(DevInTokenType.COMMAND_START)('/')
4+
PsiElement(DevInTokenType.COMMAND_ID)('browse')
5+
PsiElement(DevInTokenType.COLON)(':')
6+
PsiElement(DevInTokenType.COMMAND_PROP)('https://ide.unitmesh.cc')

0 commit comments

Comments
 (0)