Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2529ce

Browse files
committed
feat(compiler): add URL support for structure command#397
Support fetching HTML from URLs in StructureInCommand. When a URL is provided, it fetches the HTML content and creates a scratch file for processing. Also updates output format to include URL paths.
1 parentc28151c commita2529ce

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

‎exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/StructureInCommand.kt‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@ import cc.unitmesh.devti.command.InsCommand
55
importcc.unitmesh.devti.command.dataprovider.BuiltinCommand
66
importcc.unitmesh.devti.language.utils.lookupFile
77
importcc.unitmesh.devti.util.relativePath
8+
importcom.intellij.ide.scratch.ScratchRootType
9+
importcom.intellij.lang.html.HTMLLanguage
810
importcom.intellij.openapi.application.ApplicationManager
911
importcom.intellij.openapi.application.runReadAction
1012
importcom.intellij.openapi.diagnostic.logger
1113
importcom.intellij.openapi.project.Project
12-
importcom.intellij.openapi.project.guessProjectDir
1314
importcom.intellij.openapi.vfs.VirtualFile
1415
importcom.intellij.psi.PsiFile
1516
importcom.intellij.psi.PsiManager
1617
importkotlinx.coroutines.Dispatchers
1718
importkotlinx.coroutines.withContext
19+
importorg.jsoup.Jsoup
20+
importjava.net.MalformedURLException
21+
importjava.net.URL
1822

1923

2024
classStructureInCommand(valmyProject:Project,valprop:String) : InsCommand {
2125
overrideval commandName:BuiltinCommand=BuiltinCommand.STRUCTURE
2226

2327
privateval logger= logger<StructureInCommand>()
2428
overridesuspendfunexecute():String? {
25-
val virtualFile= file(myProject, prop)
29+
val virtualFile=if (isUrl(prop)) {
30+
fetchHtmlFromUrl(myProject, prop)
31+
}else {
32+
file(myProject, prop)
33+
}
34+
2635
if (virtualFile==null) {
2736
logger.warn("File not found:$prop")
2837
returnnull
@@ -37,13 +46,41 @@ class StructureInCommand(val myProject: Project, val prop: String) : InsCommand
3746
}?:returnnull
3847

3948
val structure=StructureCommandUtil.getFileStructure(myProject, virtualFile, psiFile)
40-
val filepath= virtualFile.relativePath(myProject)
41-
return"//$filepath\n```\n$structure\n```"
49+
val filepath=if (isUrl(prop)) {
50+
prop
51+
}else {
52+
virtualFile.relativePath(myProject)
53+
}
54+
55+
return"# structure:$filepath\n```\n$structure\n```"
4256
}
4357

4458
funfile(project:Project,path:String):VirtualFile? {
4559
val filename= path.split("#")[0]
4660
val virtualFile= project.lookupFile(filename)
4761
return virtualFile
4862
}
49-
}
63+
64+
privatefunisUrl(str:String):Boolean {
65+
returntry {
66+
val url=URL(str)
67+
url.protocol=="http"|| url.protocol=="https"
68+
}catch (e:MalformedURLException) {
69+
false
70+
}
71+
}
72+
73+
privatesuspendfunfetchHtmlFromUrl(project:Project,url:String):VirtualFile? {
74+
returntry {
75+
val htmlContent= withContext(Dispatchers.IO) {
76+
Jsoup.connect(url).get().outerHtml()
77+
}
78+
79+
ScratchRootType.getInstance()
80+
.createScratchFile(project,"autodev-structure.html",HTMLLanguage.INSTANCE, htmlContent)
81+
}catch (e:Exception) {
82+
logger.warn("Failed to fetch HTML from URL:$url", e)
83+
null
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp