Skip to content

Commit fd0cb1e

Browse files
FantoomForNeVeR
authored andcommitted
add debug action
1 parent 9aa5c1a commit fd0cb1e

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.intellij.plugin.powershell.ide.actions
2+
3+
import com.intellij.execution.DefaultExecutionResult
4+
import com.intellij.execution.configurations.GeneralCommandLine
5+
import com.intellij.execution.configurations.PtyCommandLine
6+
import com.intellij.execution.process.KillableProcessHandler
7+
import com.intellij.execution.runners.showRunContent
8+
import com.intellij.execution.util.ExecUtil
9+
import com.intellij.openapi.actionSystem.AnAction
10+
import com.intellij.openapi.actionSystem.AnActionEvent
11+
import com.intellij.openapi.diagnostic.logger
12+
import com.intellij.openapi.diagnostic.runAndLogException
13+
import com.intellij.openapi.fileEditor.FileEditorManager
14+
import com.intellij.openapi.options.advanced.AdvancedSettings
15+
import com.intellij.openapi.progress.ModalTaskOwner.project
16+
import com.intellij.openapi.project.Project
17+
import com.intellij.openapi.rd.util.withUiContext
18+
import com.intellij.plugin.powershell.ide.run.PowerShellScriptCommandLineState
19+
import com.intellij.plugin.powershell.lang.lsp.LSPInitMain
20+
import com.intellij.psi.PsiDocumentManager
21+
import com.intellij.terminal.TerminalExecutionConsole
22+
import java.nio.charset.Charset
23+
24+
25+
class PowerShellStartDebugAction : AnAction(){
26+
val logger = logger<PowerShellStartDebugAction>()
27+
28+
override fun actionPerformed(e: AnActionEvent) {
29+
logger.info("PowerShellStartDebugAction LOG STARTED")
30+
val currentProject: Project = e.project ?: return
31+
var currentDoc = FileEditorManager.getInstance(currentProject).selectedTextEditor?.getDocument()
32+
val psiFile = PsiDocumentManager.getInstance(currentProject).getPsiFile(currentDoc ?: return)
33+
val vFile = psiFile!!.originalFile.virtualFile
34+
val path = vFile.path
35+
val pwshExe = LSPInitMain.getInstance().getPowerShellExecutable()
36+
val commandLine = GeneralCommandLine(pwshExe, "-File", "c:\\debugger.ps1", path, "7")
37+
commandLine.setCharset(Charset.forName("UTF-8"))
38+
commandLine.setWorkDirectory(currentProject.basePath)
39+
val result = ExecUtil.execAndGetOutput(commandLine)
40+
logger.info(result.toString())
41+
}
42+
43+
private fun getTerminalCharSet(): Charset {
44+
val name = AdvancedSettings.getString("terminal.character.encoding")
45+
return logger.runAndLogException { charset(name) } ?: Charsets.UTF_8
46+
}
47+
}
48+

src/main/resources/META-INF/plugin.xml

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
<extensions defaultExtensionNs="com.intellij">
2222

23+
<toolWindow id="DebugLogWindow"
24+
anchor="bottom"
25+
factoryClass="com.intellij.execution."></toolWindow>
26+
2327
<fileType name="PowerShell" language="PowerShell" extensions="ps1;psm1;psd1"
2428
implementationClass="com.intellij.plugin.powershell.PowerShellFileType" />
2529

@@ -117,5 +121,10 @@
117121
<action id="NewPowerShellFile" class="com.intellij.plugin.powershell.ide.actions.NewPowerShellFileAction">
118122
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFromTemplate"/>
119123
</action>
124+
<action id="com.intellij.plugin.powershell.ide.actions.PowerShellStartDebugAction"
125+
class="com.intellij.plugin.powershell.ide.actions.PowerShellStartDebugAction"
126+
text="Start Powershell debug">
127+
<add-to-group group-id="DebugMainMenu" anchor="first"/>
128+
</action>
120129
</actions>
121130
</idea-plugin>

0 commit comments

Comments
 (0)