Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue property highlight #188

Merged
merged 1 commit into from
Oct 8, 2024
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
object pepita_2 {
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)
}
Comment on lines +42 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto es algo piola para tener en TS


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