Skip to content

Commit

Permalink
fix issue property highlight (#188)
Browse files Browse the repository at this point in the history
Co-authored-by: Alumno <[email protected]>
  • Loading branch information
Miranda-03 and Alumno authored Oct 8, 2024
1 parent b56c64d commit c971091
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/client/src/test/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ suite('Should go to definitions', () => {
new Location(definitionURI, new Range(new Position(0, 0), new Position(4, 1))),
])
})

test ('can navigate to a property definition', async () => {
const definitionURI = getDocumentURI('definition.wlk')
await testDefinition(definitionURI, new Position(18, 29), [
new Location(definitionURI, new Range(new Position(13, 1), new Position(13, 22))),
])
})
})

async function testDefinition(uri: Uri, at: Position, expected: Array<Location | LocationLink>): Promise<void> {
Expand Down
9 changes: 9 additions & 0 deletions packages/client/testFixture/definition.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ object manolo {
method hacerVolarAPepita() {
pepita.vola()
}
}

object pepita_2 {
var property vida = 2
}

object gandalf {

method poder() = pepita_2.vida() + 1
}
11 changes: 10 additions & 1 deletion packages/server/src/functionalities/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getNodeDefinition = (environment: Environment) => (node: Node): Nod
try {
return match(node)(
when(Reference)(node => definedOrEmpty(node.target)),
when(Send)(sendDefinitions(environment)),
when(Send)(node => mapSyntheticMethods(environment, node)),
when(Super)(node => definedOrEmpty(superMethodDefinition(node))),
when(Self)(node => definedOrEmpty(getParentModule(node)))
)
Expand All @@ -34,6 +34,15 @@ export const getNodeDefinition = (environment: Environment) => (node: Node): Nod
}
}

const mapSyntheticMethods = (environment: Environment, node: Send) => {
const definitions = sendDefinitions(environment)(node)
return definitions.map((method: Method) => method.isSynthetic ? getDefinitionFromSyntheticMethod(method) : method)
}

const getDefinitionFromSyntheticMethod = (method: Method) => {
return method.parent.allFields.find((field) => field.name === method.name && field.isProperty)
}

const superMethodDefinition = (superNode: Super): Method | undefined => {
const currentMethod = superNode.ancestors.find(is(Method))!
const module = getParentModule(superNode)
Expand Down

0 comments on commit c971091

Please sign in to comment.