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

Pasar la búsqueda de properties en definitions a wollok-ts #193

Open
fdodino opened this issue Oct 10, 2024 · 0 comments
Open

Pasar la búsqueda de properties en definitions a wollok-ts #193

fdodino opened this issue Oct 10, 2024 · 0 comments
Labels
good first issue Good for newcomers refactor Make a refactor in the project

Comments

@fdodino
Copy link
Contributor

fdodino commented Oct 10, 2024

El fin de semana en la hackathon me preguntaron si la búsqueda de las definitions las podían implementar en LSP-IDE o wollok-ts y fui víctima de mi propia decisión, aunque a mi favor todavía faltaba mergear el refactor que migró el archivo definitions.ts a wollok-ts.

Ahora quedó

export const getDefinition = (environment: Environment) => (node: Node): Node[] => {
  try {
    // **** TODO: migrate to wollok-ts
    if (node.is(Send)) {
      const getDefinitionFromSyntheticMethod = (method: Method) => {
        return method.parent.allFields.find((field) => field.name === method.name && field.isProperty)
      }

      const definitions = sendDefinitions(environment)(node)
      return definitions.map((method: Method) => method.isSynthetic ? getDefinitionFromSyntheticMethod(method) : method)
    }
    // *** FIN TODO: migrate to wollok-ts

    return getNodeDefinition(environment)(node)
  } catch (error) {
    logger.error(`✘ Error in getDefinition: ${error}`, error)
    return [node]
  }
}

dentro del archivo packages/server/src/functionalities/definition.ts. Lo que hay que hacer es mover todo ese if a wollok-ts: src/helpers.ts

export const sendDefinitions = (environment: Environment) => (send: Send): Method[] => {
  try {
    return match(send.receiver)(
      when(Reference)(node => {
        const target = node.target
        return target && is(Singleton)(target) ?
          valueAsListOrEmpty(target.lookupMethod(send.message, send.args.length))
          : allMethodDefinitions(environment, send)
      }),
      when(New)(node => valueAsListOrEmpty(node.instantiated.target?.lookupMethod(send.message, send.args.length))),
      when(Self)(_ => moduleFinderWithBackup(environment, send)(
        (module) => valueAsListOrEmpty(module.lookupMethod(send.message, send.args.length))
      )),
    )
  } catch (error) {
    return allMethodDefinitions(environment, send)
  }
}
@fdodino fdodino added good first issue Good for newcomers refactor Make a refactor in the project labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers refactor Make a refactor in the project
Projects
None yet
Development

No branches or pull requests

1 participant