Skip to content

Commit 404db1d

Browse files
authored
Fix Go Lambda handler resolving into Go standard library (#2748)
1 parent d7089c0 commit 404db1d

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix Go Lambda handler resolving into Go standard library (#2730)"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/Lambda.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ object Lambda {
3838
// Don't search through ".aws-sam" folders
3939
val samBuildFileScopes = GlobalSearchScope.filesScope(project, findSamBuildContents(project))
4040
val excludeSamBuildFileScopes = GlobalSearchScope.notScope(samBuildFileScopes)
41-
val scope = GlobalSearchScope.allScope(project).intersectWith(excludeSamBuildFileScopes)
41+
// only search within project content roots
42+
val scope = GlobalSearchScope.projectScope(project).intersectWith(excludeSamBuildFileScopes)
4243

4344
val elements = resolver.findPsiElements(project, handler, scope)
4445

jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/LambdaBuilder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ abstract class LambdaBuilder {
9999
const val TASK_PATH = "/var/task"
100100

101101
fun getModule(psiFile: PsiFile): Module = ModuleUtil.findModuleForFile(psiFile)
102-
?: throw IllegalStateException("Failed to locate module for $psiFile")
102+
?: throw IllegalStateException("Failed to locate module for ${psiFile.virtualFile}")
103103
}
104104
}

jetbrains-ultimate/it/software/aws/toolkits/jetbrains/services/lambda/go/GoLocalRunConfigurationIntegrationTest.kt

+30-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ package software.aws.toolkits.jetbrains.services.lambda.go
55

66
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
77
import com.fasterxml.jackson.module.kotlin.readValue
8+
import com.goide.sdk.GoSdk
9+
import com.goide.sdk.GoSdkService
10+
import com.goide.sdk.GoSdkUtil
811
import com.goide.vgo.VgoTestUtil
912
import com.intellij.execution.executors.DefaultDebugExecutor
1013
import com.intellij.openapi.application.ApplicationInfo
1114
import com.intellij.openapi.module.WebModuleTypeBase
15+
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
1216
import com.intellij.testFramework.PsiTestUtil
1317
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
1418
import com.intellij.testFramework.runInEdtAndWait
@@ -181,8 +185,6 @@ class GoLocalRunConfigurationIntegrationTest(private val runtime: LambdaRuntime)
181185

182186
@Test
183187
fun samIsExecutedWithDebugger() {
184-
// only run this test on > 2020.1. FIX_WHEN_MIN_IS_202
185-
assumeFalse(ApplicationInfo.getInstance().let { info -> (info.majorVersion == "2020" && info.minorVersionMainPart == "1") })
186188
projectRule.fixture.addLambdaFile(fileContents)
187189

188190
val runConfiguration = createHandlerBasedRunConfiguration(
@@ -207,6 +209,32 @@ class GoLocalRunConfigurationIntegrationTest(private val runtime: LambdaRuntime)
207209
assertThat(debuggerIsHit.get()).isTrue
208210
}
209211

212+
@Test
213+
fun `works when handler is 'main'`() {
214+
assumeFalse(true) // TODO: fix when new build images are ready
215+
// fails if [Lambda.findPsiElementsForHandler] finds the handler in the Go standard library
216+
val sdkDir = GoSdkUtil.suggestSdkDirectory()!!.children.sortedByDescending { it.name }.first().canonicalPath!!
217+
VfsRootAccess.allowRootAccess(projectRule.project, sdkDir)
218+
runInEdtAndWait {
219+
GoSdkService.getInstance(projectRule.project).setSdk(GoSdk.fromHomePath(sdkDir))
220+
}
221+
projectRule.fixture.addLambdaFile(fileContents)
222+
223+
val runConfiguration = createHandlerBasedRunConfiguration(
224+
project = projectRule.project,
225+
runtime = runtime.toSdkRuntime(),
226+
handler = "main",
227+
input = "\"${input}\"",
228+
credentialsProviderId = mockId
229+
)
230+
231+
assertThat(runConfiguration).isNotNull
232+
233+
val executeLambda = executeRunConfigurationAndWait(runConfiguration, DefaultDebugExecutor.EXECUTOR_ID)
234+
235+
assertThat(executeLambda.exitCode).isEqualTo(0)
236+
}
237+
210238
@Test
211239
fun samIsExecutedImage(): Unit = samImageRunDebugTest(
212240
projectRule = projectRule,

0 commit comments

Comments
 (0)