From fc18a17e5201bb98b1113b764fa6614af929724f Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Tue, 15 Aug 2023 18:51:21 -0600 Subject: [PATCH] Implement go-to-definition for constructors and implicit class types (#236) * Support all assignment patterns in outline / go-to-symbol * Refactor 'findNameInPattern()' in terms of 'findInPattern()' * Implement go-to-definition for qualified types * Implement go-to-definition for class constructors * Implement go-to-definition for types corresponding to classes --- src/server/navigation.ts | 44 +++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/server/navigation.ts b/src/server/navigation.ts index 754a3c2..84b048b 100644 --- a/src/server/navigation.ts +++ b/src/server/navigation.ts @@ -342,7 +342,7 @@ function searchInScope( return; } -function searchVariableBinding( +function searchDeclaration( reference: Reference, search: Search, dec: Node, @@ -366,6 +366,15 @@ function searchVariableBinding( body, } : undefined, + ) || + matchNode(dec, 'ClassD', (_sharedPat: any, name: string) => + name === search.name + ? { + uri: reference.uri, + cursor: dec, // TODO: cursor on variable name + body: dec, + } + : undefined, ) ); } @@ -375,14 +384,25 @@ function searchTypeBinding( search: Search, dec: Node, ): Definition | undefined { - return matchNode(dec, 'TypD', (name: string, typ: Node) => - name === search.name - ? { - uri: reference.uri, - cursor: typ, // TODO: source location from `name` - body: typ, - } - : undefined, + return ( + matchNode(dec, 'TypD', (name: string, typ: Node) => + name === search.name + ? { + uri: reference.uri, + cursor: typ, // TODO: source location from `name` + body: typ, + } + : undefined, + ) || + matchNode(dec, 'ClassD', (_sharedPat: any, name: string) => + name === search.name + ? { + uri: reference.uri, + cursor: dec, // TODO: cursor on variable name + body: dec, + } + : undefined, + ) ); } @@ -401,7 +421,7 @@ function searchObject( let definition: Definition | undefined; if (search.type === 'variable') { definition = - searchVariableBinding(reference, search, arg) || + searchDeclaration(reference, search, arg) || matchNode( arg, 'ExpField', @@ -413,7 +433,7 @@ function searchObject( }, ) || matchNode(arg, 'DecField', (dec: Node) => - searchVariableBinding(reference, search, dec), + searchDeclaration(reference, search, dec), ) || matchNode( arg, @@ -424,7 +444,7 @@ function searchObject( field, 'DecField', (dec: Node) => - searchVariableBinding( + searchDeclaration( reference, search, dec,