feat(language-service): Add getTypeDefinitionAtPosition (go to type d… #39145
Conversation
This is so exciting
| it('should return nothing for input providers', () => { | ||
| const definitions = getTypeDefinitionsAndAssertBoundSpan({ | ||
| templateOverride: `<test-comp [tcN¦ame]="name"></test-comp>`, | ||
| }); | ||
| expect(definitions).toEqual([]); |
Wouldn't tcName have a type, namely string?
This is actually just the behavior of the ts language service itself for primitives. However, if I set the type to String rather than string, I do get definitions from the lib.es2015.core.d.ts, lib.es5.d.ts, etc. I think this case is generally covered in the new test that Keen requested (go to type definition of toLowerCase)
Gotcha. I think it would be worth reworking this test to use a value that has a go-to-definition type, because I think the test title "should return nothing for input providers" is incorrect - in general we do want to return something for input providers, when there is something to return.
minor comments. LGTM overall
| } | ||
| } | ||
|
|
||
| function getDefinitionsForSymbols( | ||
| symbols: {shimLocation: ShimLocation}[], |
Instead of the custom type, why not just pass in the shim locations?
It makes calling the function easier. I would otherwise have to map all the symbols before passing them in. I also can't use the Symbol type because some don't have shimLocation at the top level. If you feel strongly about this, I can change it.
ecdbf2d
to
d43ea0f
PTAL. I had to make some adjustments to the getDirectiveMatches to allow matching compound selectors that included the tag name.
| } | ||
| } | ||
|
|
||
| function getDefinitionsForSymbols( | ||
| symbols: {shimLocation: ShimLocation}[], |
It makes calling the function easier. I would otherwise have to map all the symbols before passing them in. I also can't use the Symbol type because some don't have shimLocation at the top level. If you feel strongly about this, I can change it.
| it('should return nothing for input providers', () => { | ||
| const definitions = getTypeDefinitionsAndAssertBoundSpan({ | ||
| templateOverride: `<test-comp [tcN¦ame]="name"></test-comp>`, | ||
| }); | ||
| expect(definitions).toEqual([]); |
This is actually just the behavior of the ts language service itself for primitives. However, if I set the type to String rather than string, I do get definitions from the lib.es2015.core.d.ts, lib.es5.d.ts, etc. I think this case is generally covered in the new test that Keen requested (go to type definition of toLowerCase)
f0ecc84
to
61d11e5
| return symbols.reduce((result, {shimLocation}) => { | ||
| const defs = this.tsLS.getDefinitionAtPosition( | ||
| shimLocation.shimPath, shimLocation.positionInShimFile) ?? | ||
| []; |
nit: clang format is really weird here, maybe something like
| return symbols.reduce((result, {shimLocation}) => { | |
| const defs = this.tsLS.getDefinitionAtPosition( | |
| shimLocation.shimPath, shimLocation.positionInShimFile) ?? | |
| []; | |
| return symbols.reduce((result, {shimLocation}) => { | |
| const {shimPath, positionInShimFile} = shimLocation; | |
| const defs = this.tsLS.getDefinitionAtPosition(shimPath, positionInShimFile) ?? []; |
to make it a bit more linear?
Also, can we use map and flatten here rather than creating a new array on each reduce iteration?
Done.
| switch (symbol.kind) { | ||
| case SymbolKind.Template: { | ||
| const matches = getDirectiveMatches( | ||
| {name: symbol.templateNode.tagName, kind: DirectiveMatchKind.TAG_NAME}, |
can we pass the name and kind as separate params? Constructing an object feels verbose.
Refactored this into two totally separate functions. This was feeling a little bit like a code smell the way it was.
| }, [] as ts.DefinitionInfo[]); | ||
| } | ||
|
|
||
| private getSymbolAndNodeAtPosition(fileName: string, position: number): DefinitionMeta { |
The usages of this function return value unpack symbol and node and check that both are defined before moving on, so I think it would be better to make the return type DefinitionMeta|undefined. I think this would make it clearer that the metadata is either entirely defined with a symbol and node, or not at all.
Done. I have a WIP branch that distinguish between templateInfo is undefined vs if the node/symbol lookup failed so I just extracted the templateInfo getter out of this function.
nice
…efinition) This commit adds the implementation for providing "go to type definition" functionality in the Ivy Language Service.
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
…efinition)
This commit adds the implementation for providing "go to type definition"
functionality in the Ivy Language Service.
The text was updated successfully, but these errors were encountered: