-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First step: fix #147 (CI will fail) * Fix #146 * Add info of doc * linter fixes * Fix #149 - delete/rename leaves zombies problems * Fix #121 - ms to open dynamic diagram * Fix #122 - skip diagram in ts-cli * Fix #111 - wollok icon * Fix e2e test * Back to old image but better definition * Removing migrated functions * Add new version for wollok-ts * Hack to test hover
- Loading branch information
Showing
21 changed files
with
206 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,45 @@ | ||
import { Location, TextDocumentPositionParams } from 'vscode-languageserver' | ||
import { Environment, Method, Module, New, Node, Reference, Self, Send, Singleton, Super, is, match, when } from 'wollok-ts' | ||
import { Environment, Method, Module, Node, Reference, Self, Send, Super, is, match, sendDefinitions, when } from 'wollok-ts' | ||
import { getNodesByPosition, nodeToLocation } from '../utils/text-documents' | ||
import { logger } from '../utils/logger' | ||
|
||
export const definition = (environment: Environment) => ( | ||
textDocumentPosition: TextDocumentPositionParams | ||
): Location[] => { | ||
const cursorNodes = getNodesByPosition(environment, textDocumentPosition) | ||
const definitions = getNodeDefinition(environment)(cursorNodes.reverse()[0]) | ||
const definitions = getDefinition(environment)(cursorNodes.reverse()[0]) | ||
return definitions.map(nodeToLocation) | ||
} | ||
|
||
// WOLLOK-TS: hablar con Nahue/Ivo, para mí desde acá para abajo todo se podria migrar a wollok-ts | ||
export const getNodeDefinition = (environment: Environment) => (node: Node): Node[] => { | ||
export const getDefinition = (environment: Environment) => (node: Node): Node[] => { | ||
try { | ||
return match(node)( | ||
when(Reference)(node => definedOrEmpty(referenceDefinition(node))), | ||
when(Send)(sendDefinitions(environment)), | ||
when(Super)(node => definedOrEmpty(superMethodDefinition(node))), | ||
when(Self)(node => definedOrEmpty(node.ancestors.find(is(Module)))) | ||
) | ||
} catch { | ||
return getNodeDefinition(environment)(node) | ||
} catch (error) { | ||
logger.error(`✘ Error in getDefinition: ${error}`, error) | ||
return [node] | ||
} | ||
} | ||
|
||
function referenceDefinition(ref: Reference<Node>): Node | undefined { | ||
return ref.target | ||
} | ||
|
||
|
||
const sendDefinitions = (environment: Environment) => (send: Send): Method[] => { | ||
// TODO: terminar de migrar a wollok-ts estas 4 definiciones | ||
export const getNodeDefinition = (environment: Environment) => (node: Node): Node[] => { | ||
try { | ||
return match(send.receiver)( | ||
when(Reference)(node => { | ||
const target = node.target | ||
return target && is(Singleton)(target) ? | ||
definedOrEmpty(target.lookupMethod(send.message, send.args.length)) | ||
: allMethodDefinitions(environment, send) | ||
}), | ||
when(New)(node => definedOrEmpty(node.instantiated.target?.lookupMethod(send.message, send.args.length))), | ||
when(Self)(_ => moduleFinderWithBackup(environment, send)( | ||
(module) => definedOrEmpty(module.lookupMethod(send.message, send.args.length)) | ||
)), | ||
return match(node)( | ||
when(Reference)(node => definedOrEmpty(node.target)), | ||
when(Send)(sendDefinitions(environment)), | ||
when(Super)(node => definedOrEmpty(superMethodDefinition(node))), | ||
when(Self)(node => definedOrEmpty(getParentModule(node))) | ||
) | ||
} catch { | ||
return allMethodDefinitions(environment, send) | ||
return [node] | ||
} | ||
} | ||
|
||
function superMethodDefinition(superNode: Super): Method | undefined { | ||
const superMethodDefinition = (superNode: Super): Method | undefined => { | ||
const currentMethod = superNode.ancestors.find(is(Method))! | ||
const module = superNode.ancestors.find(is(Module)) | ||
const module = getParentModule(superNode) | ||
return module ? module.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: module.fullyQualifiedName }) : undefined | ||
} | ||
|
||
function allMethodDefinitions(environment: Environment, send: Send): Method[] { | ||
const arity = send.args.length | ||
const name = send.message | ||
return environment.descendants.filter(n => | ||
is(Method)(n) && | ||
n.name === name && | ||
n.parameters.length === arity | ||
) as Method[] | ||
} | ||
|
||
|
||
// UTILS | ||
const moduleFinderWithBackup = (environment: Environment, send: Send) => (methodFinder: (module: Module) => Method[]) => { | ||
const module = send.ancestors.find(is(Module)) | ||
return module ? methodFinder(module) : allMethodDefinitions(environment, send) | ||
} | ||
const getParentModule = (node: Node) => node.ancestors.find(is(Module)) | ||
|
||
function definedOrEmpty<T>(value: T | undefined): T[] { | ||
return value ? [value] : [] | ||
} | ||
const definedOrEmpty = <T>(value: T | undefined): T[] => value ? [value] : [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.