Skip to content

Fixes a crash when renaming import path of a JSON file#3196

Open
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:fix/rename-json-import-path-crash
Open

Fixes a crash when renaming import path of a JSON file#3196
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:fix/rename-json-import-path-crash

Conversation

@Andarist
Copy link
Contributor

fixes a crash found here #3187 (comment) (it also crashes in Strada)

Comment on lines +1383 to +1385
if options.use == referenceUseRename && ast.IsSourceFile(decl) {
continue
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tested the same patch in Strada and renaming the from "./x/package.json" resulted in the file itself being renamed too. That's definitely a desirable outcome but I'm not exactly sure what's the codepath leading to that filename rename - given it works... I wasn't exactly inclined to dig deeper.

The alternative fix would be to handle this in the loop here:

for _, entry := range entries {
uri := l.getFileNameOfEntry(entry)
if l.UserPreferences().AllowRenameOfImportPath != core.TSTrue && entry.node != nil && ast.IsStringLiteralLike(entry.node) && ast.TryGetImportFromModuleSpecifier(entry.node) != nil {
continue
}
textEdit := &lsproto.TextEdit{
Range: l.getRangeOfEntry(entry),
NewText: l.getTextForRename(data.OriginalNode, entry, params.NewName, ch, quotePreference),
}
changes[uri] = append(changes[uri], textEdit)
}

The crash happens in getTextForRename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant