Skip to content

Skip past module.exports = { Foo } in go-to-defintion on 'Foo' - #40835

Merged
Andrew Branch (andrewbranch) merged 5 commits into
microsoft:masterfrom
andrewbranch:bug/39895
Oct 5, 2020
Merged

Skip past module.exports = { Foo } in go-to-defintion on 'Foo'#40835
Andrew Branch (andrewbranch) merged 5 commits into
microsoft:masterfrom
andrewbranch:bug/39895

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

Fixes#39895

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about a fail case, but I think it was pre-existing.

while (symbol) {
if (symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
const aliased = checker.getAliasedSymbol(symbol);
if (!aliased.declarations) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when does this happen?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the converse of the previous code, but I think it could happen in certain error cases where the checker falls back to unknownSymbol. Not sure if that’s actually possible in getAliasedSymbol, but I feel like our assumption that symbols always have declarations is a frequent source of crashes, particularly in error-ridden code.

Comment threadsrc/services/goToDefinition.ts Outdated
const spanContent = fileContent.slice(defs.textSpan.start, ts.textSpanEnd(defs.textSpan));
const spanContentWithMarker = spanContent.slice(0, marker.position - defs.textSpan.start) + `/*${startMarkerName}*/` + spanContent.slice(marker.position - defs.textSpan.start);
const suggestedFileContent = (fileContent.slice(0, defs.textSpan.start) + `\x1b[1;4m[|${spanContentWithMarker}|]\x1b[31m` + fileContent.slice(ts.textSpanEnd(defs.textSpan)))
const suggestedFileContent = (fileContent.slice(0, defs.textSpan.start) + `\x1b[1;4m[|${spanContentWithMarker}|]\x1b[0;31m` + fileContent.slice(ts.textSpanEnd(defs.textSpan)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look to see colour markup in error messages

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Milestone BugPRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Go to definition shows Node require statement as definition

3 participants

@andrewbranch@sandersn@typescript-bot