Skip to content

Commit

Permalink
Implement go-to-definition for constructors and implicit class types (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rvanasa authored Aug 16, 2023
1 parent d24a92b commit fc18a17
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/server/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function searchInScope(
return;
}

function searchVariableBinding(
function searchDeclaration(
reference: Reference,
search: Search,
dec: Node,
Expand All @@ -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,
)
);
}
Expand All @@ -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,
)
);
}

Expand All @@ -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',
Expand All @@ -413,7 +433,7 @@ function searchObject(
},
) ||
matchNode(arg, 'DecField', (dec: Node) =>
searchVariableBinding(reference, search, dec),
searchDeclaration(reference, search, dec),
) ||
matchNode(
arg,
Expand All @@ -424,7 +444,7 @@ function searchObject(
field,
'DecField',
(dec: Node) =>
searchVariableBinding(
searchDeclaration(
reference,
search,
dec,
Expand Down

0 comments on commit fc18a17

Please sign in to comment.