Skip to content

Commit 1974c6f

Browse files
committed
fix: use mapper for different interpreters
1 parent 9f8ad7a commit 1974c6f

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.xepozz.php_dump.command
2+
3+
import com.intellij.execution.ExecutionException
4+
import com.intellij.openapi.project.Project
5+
import com.jetbrains.php.config.PhpProjectConfigurationFacade
6+
import com.jetbrains.php.config.interpreters.PhpInterpreter
7+
import com.jetbrains.php.config.interpreters.PhpInterpretersManagerImpl
8+
import com.jetbrains.php.run.remote.PhpRemoteInterpreterManager
9+
10+
object PathMapper {
11+
fun map(project: Project, interpreter: PhpInterpreter, localPath: String): String {
12+
if (!interpreter.isRemote) return localPath
13+
14+
val data = interpreter.phpSdkAdditionalData
15+
val manager = PhpRemoteInterpreterManager.getInstance() ?: throw ExecutionException(
16+
PhpRemoteInterpreterManager.getRemoteInterpreterPluginIsDisabledErrorMessage()
17+
)
18+
val pathMapper = manager.createPathMapper(project, data)
19+
return pathMapper.process(localPath)
20+
}
21+
22+
fun map(project: Project, localPath: String): String =
23+
(PhpProjectConfigurationFacade.getInstance(project).interpreter
24+
?: PhpInterpretersManagerImpl.getInstance(project).interpreters.firstOrNull())
25+
?.let { map(project, it, localPath) }
26+
?: localPath
27+
}

src/main/kotlin/com/github/xepozz/php_dump/services/OpcacheSettingsTreeDumperService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xepozz.php_dump.services
22

3+
import com.github.xepozz.php_dump.command.PathMapper
34
import com.github.xepozz.php_dump.command.PhpCommandExecutor
45
import com.github.xepozz.php_dump.stubs.any_tree.AnyNodeList
56
import com.github.xepozz.php_dump.stubs.any_tree.AnyNodeParser
@@ -43,11 +44,12 @@ class OpcacheSettingsTreeDumperService(var project: Project) : DumperServiceInte
4344
'status' => opcache_get_status(true),
4445
]));
4546
""".trimIndent()
47+
val localFile = PathMapper.map(project, file)
4648

4749
return withContext(Dispatchers.IO) {
4850
val output = StringBuilder()
4951

50-
PhpCommandExecutor.execute(file, phpSnippet, project, object : ProcessAdapter() {
52+
PhpCommandExecutor.execute(localFile, phpSnippet, project, object : ProcessAdapter() {
5153
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
5254
when (outputType) {
5355
ProcessOutputTypes.STDERR -> output.append(event.text)

src/main/kotlin/com/github/xepozz/php_dump/services/OpcodesDumperService.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xepozz.php_dump.services
22

3+
import com.github.xepozz.php_dump.command.PathMapper
34
import com.github.xepozz.php_dump.command.PhpCommandExecutor
45
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
56
import com.intellij.execution.configurations.GeneralCommandLine
@@ -17,14 +18,15 @@ import kotlinx.coroutines.withContext
1718
@Service(Service.Level.PROJECT)
1819
class OpcodesDumperService(var project: Project) : DumperServiceInterface {
1920
val state = PhpDumpSettingsService.getInstance(project)
20-
val interpretersManager = PhpInterpretersManagerImpl.getInstance(project)
2121
val interpreter = PhpProjectConfigurationFacade.getInstance(project).interpreter
22-
?: interpretersManager.interpreters.firstOrNull()
22+
?: PhpInterpretersManagerImpl.getInstance(project).interpreters.firstOrNull()
2323

2424
override suspend fun dump(file: String): Any? {
2525
val interpreterPath = interpreter?.pathToPhpExecutable ?: return null
2626
val debugLevel = state.debugLevel.value
2727
val preloadFile = state.preloadFile
28+
29+
val localFile = PathMapper.map(project, file)
2830
val command = GeneralCommandLine(buildList {
2931
add(interpreterPath)
3032
add("-l")
@@ -39,11 +41,9 @@ class OpcodesDumperService(var project: Project) : DumperServiceInterface {
3941
}
4042

4143
add("1>/dev/null")
42-
add(file)
44+
add(localFile)
4345
}).commandLineString
4446

45-
46-
4747
// language=injectablephp
4848
val phpSnippet = $$"""
4949
opcache_compile_file($argv[1]);
@@ -53,7 +53,7 @@ class OpcodesDumperService(var project: Project) : DumperServiceInterface {
5353
return withContext(Dispatchers.IO) {
5454
val output = StringBuilder()
5555

56-
PhpCommandExecutor.execute(file, phpSnippet, project, object : ProcessAdapter() {
56+
PhpCommandExecutor.execute(localFile, phpSnippet, project, object : ProcessAdapter() {
5757
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
5858
when (outputType) {
5959
ProcessOutputTypes.STDERR -> output.append(event.text)

src/main/kotlin/com/github/xepozz/php_dump/services/TokensDumperService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xepozz.php_dump.services
22

3+
import com.github.xepozz.php_dump.command.PathMapper
34
import com.github.xepozz.php_dump.command.PhpCommandExecutor
45
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
56
import com.intellij.execution.process.ProcessAdapter
@@ -52,11 +53,12 @@ class TokensDumperService(var project: Project) : DumperServiceInterface {
5253
);
5354
""".trimIndent()
5455
}
56+
val localFile = PathMapper.map(project, file)
5557

5658
return withContext(Dispatchers.IO) {
5759
val output = StringBuilder()
5860

59-
PhpCommandExecutor.execute(file, phpSnippet, project, object : ProcessAdapter() {
61+
PhpCommandExecutor.execute(localFile, phpSnippet, project, object : ProcessAdapter() {
6062
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
6163
when (outputType) {
6264
ProcessOutputTypes.STDERR -> output.append(event.text)

src/main/kotlin/com/github/xepozz/php_dump/services/TokensTreeDumperService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xepozz.php_dump.services
22

3+
import com.github.xepozz.php_dump.command.PathMapper
34
import com.github.xepozz.php_dump.command.PhpCommandExecutor
45
import com.github.xepozz.php_dump.stubs.token_object.TokenParser
56
import com.intellij.execution.process.ProcessAdapter
@@ -30,11 +31,12 @@ class TokensTreeDumperService(var project: Project) : DumperServiceInterface {
3031
)
3132
);
3233
""".trimIndent()
34+
val localFile = PathMapper.map(project, file)
3335

3436
return withContext(Dispatchers.IO) {
3537
val output = StringBuilder()
3638

37-
PhpCommandExecutor.execute(file, phpSnippet, project, object : ProcessAdapter() {
39+
PhpCommandExecutor.execute(localFile, phpSnippet, project, object : ProcessAdapter() {
3840
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
3941
when (outputType) {
4042
ProcessOutputTypes.STDERR -> output.append(event.text)

0 commit comments

Comments
 (0)