Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/kotlin/org/pkl/lsp/ast/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class PklDeclaredTypeImpl(
if (filterChildren) elems.filter { it is PklTypeName || it is Terminal } else elems
}

// Within a PklAnnotation, [ctx] spans the object body, too. Without narrowing the span to the
// type name, nodes within the object body would resolve to this type.
override val span: Span by lazy { if (filterChildren) name.span else super.span }

override val name: PklTypeName by lazy {
toTypeName(super.children[qualifiedIdentifierIdx] as PklQualifiedIdentifier)
}
Expand Down
39 changes: 39 additions & 0 deletions src/test/kotlin/org/pkl/lsp/GoToDefinitionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,45 @@ class GoToDefinitionTest : LspTestBase() {
assertThat(resolved.parentOfTypes(PklClass::class)!!.name).isEqualTo("MyClass")
}

@Test
fun `resolve annotation type`() {
createPklFile(
"""
class MyAnnotation extends Annotation {
name: String
}

@MyAnnot<caret>ation { name = "Bob" }
value: String
"""
.trimIndent()
)
val resolved = goToDefinition().single()
assertThat(resolved).isInstanceOf(PklClass::class.java)
resolved as PklClass
assertThat(resolved.name).isEqualTo("MyAnnotation")
}

@Test
fun `resolve annotation property`() {
createPklFile(
"""
class MyAnnotation extends Annotation {
name: String
}

@MyAnnotation { na<caret>me = "Bob" }
value: String
"""
.trimIndent()
)
val resolved = goToDefinition().single()
assertThat(resolved).isInstanceOf(PklClassProperty::class.java)
resolved as PklClassProperty
assertThat(resolved.name).isEqualTo("name")
assertThat(resolved.parentOfTypes(PklClass::class)!!.name).isEqualTo("MyAnnotation")
}

@Test
fun `resolve function name`() {
createPklFile(
Expand Down
20 changes: 20 additions & 0 deletions src/test/kotlin/org/pkl/lsp/HoverTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ class HoverTest : LspTestBase() {
assertThat(hoverText).contains("This is the docs for foo!")
}

@Test
fun `annotation property`() {
createPklFile(
"""
class MyAnnotation extends Annotation {
/// The name.
name: String
}

@MyAnnotation { na<caret>me = "Bob" }
value: String
"""
.trimIndent()
)
val hoverText = getHoverText()
assertThat(hoverText).contains("name: String")
assertThat(hoverText).contains("The name.")
assertThat(hoverText).doesNotContain("class MyAnnotation")
}

@Test
fun `member links get rendered`() {
createPklFile(
Expand Down
Loading