From c9710913b04466de38c9c6bb7b4b821884eac493 Mon Sep 17 00:00:00 2001 From: Miranda <72475370+Miranda-03@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:02:51 -0300 Subject: [PATCH] fix issue property highlight (#188) Co-authored-by: Alumno --- packages/client/src/test/definition.test.ts | 7 +++++++ packages/client/testFixture/definition.wlk | 9 +++++++++ packages/server/src/functionalities/definition.ts | 11 ++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/client/src/test/definition.test.ts b/packages/client/src/test/definition.test.ts index 24bf2957..deeccc57 100644 --- a/packages/client/src/test/definition.test.ts +++ b/packages/client/src/test/definition.test.ts @@ -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): Promise { diff --git a/packages/client/testFixture/definition.wlk b/packages/client/testFixture/definition.wlk index 7dcf9d7c..72619487 100644 --- a/packages/client/testFixture/definition.wlk +++ b/packages/client/testFixture/definition.wlk @@ -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 } \ No newline at end of file diff --git a/packages/server/src/functionalities/definition.ts b/packages/server/src/functionalities/definition.ts index 7e0ed3bd..6f571b48 100644 --- a/packages/server/src/functionalities/definition.ts +++ b/packages/server/src/functionalities/definition.ts @@ -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))) ) @@ -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)