Skip to content

Error in 'setTextPos' during 'getCodeFixes' #49310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
typescript-bot opened this issue May 30, 2022 · 4 comments · Fixed by #49992
Closed

Error in 'setTextPos' during 'getCodeFixes' #49310

typescript-bot opened this issue May 30, 2022 · 4 comments · Fixed by #49992
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Source: Telemetry The issue relates to the telemetry in editors

Comments

@typescript-bot
Copy link
Collaborator

This issue comes from crash dumps in telemetry. We've tried to de-duplicate issues on a best-effort basis, comparing the sequence of methods called and the command requested while ignoring line numbers.
TypeScript version prefix: 4.7.2
VSCode version: 1.68.0-insider
Command requested: getCodeFixes
Hitting sessions: 847
Five line hash: 8bf0402bbe40ec04bbb0073872731305
Stack:

    at setTextPos (tsserver.js:12102:22)
    at skipToEndOf (tsserver.js:145368:25)
    at processChildNodes (tsserver.js:146863:47)
    at <anonymous> (tsserver.js:146780:21)
    at visitNodes (tsserver.js:30468:24)
    at forEachChild (tsserver.js:30659:21)
    at processNode (tsserver.js:146777:20)
    at processChildNode (tsserver.js:146848:21)
    at <anonymous> (tsserver.js:146778:21)
    at visitNode (tsserver.js:30463:24)
    at forEachChild (tsserver.js:30622:21)
    at processNode (tsserver.js:146777:20)
    at formatSpanWorker (tsserver.js:146577:17)
    at <anonymous> (tsserver.js:146540:140)
    at getFormattingScanner (tsserver.js:145167:23)
    at formatNodeGivenIndentation (tsserver.js:146540:31)
    at getFormattedTextOfNode (tsserver.js:148971:45)
    at format (tsserver.js:148942:52)
    at computeNewText (tsserver.js:148945:23)
    at <anonymous> (tsserver.js:148909:39)
    at mapDefined (tsserver.js:605:30)
    at <anonymous> (tsserver.js:148907:42)
    at mapDefined (tsserver.js:605:30)
    at getTextChangesFromChanges (tsserver.js:148893:27)
    at ChangeTracker.getChanges (tsserver.js:148832:45)
    at ChangeTracker.with (tsserver.js:148252:32)
    at getCodeActions (tsserver.js:153962:68)
    at <anonymous> (tsserver.js:149499:77)
    at flatMap (tsserver.js:508:25)
    at getFixes (tsserver.js:149499:23)
    at <anonymous> (tsserver.js:164899:35)
    at flatMap (tsserver.js:508:25)
    at getCodeFixesAtPosition (tsserver.js:164897:23)
    at unknown (suppressed.js:182:34)
    at unknown (suppressed.js:79:25)
    at Session.getCodeFixes (tsserver.js:176796:64)
    at _a.<computed> (tsserver.js:175179:61)
    at <anonymous> (tsserver.js:177109:88)
    at Session.executeWithRequestId (tsserver.js:177100:28)
    at Session.executeCommand (tsserver.js:177109:33)
    at Session.onMessage (tsserver.js:177135:35)
    at <anonymous> (tsserver.js:179770:31)
@typescript-bot typescript-bot added Bug A bug in TypeScript Source: Telemetry The issue relates to the telemetry in editors labels May 30, 2022
@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.7.3
VSCode version: 1.68.0-insider
Command requested: getCodeFixes
Hitting sessions: 178
Five line hash: 8bf0402bbe40ec04bbb0073872731305
Stack:

    at setTextPos (tsserver.js:12103:22)
    at skipToEndOf (tsserver.js:145431:25)
    at processChildNodes (tsserver.js:146926:47)
    at <anonymous> (tsserver.js:146843:21)
    at visitNodes (tsserver.js:30474:24)
    at forEachChild (tsserver.js:30665:21)
    at processNode (tsserver.js:146840:20)
    at processChildNode (tsserver.js:146911:21)
    at <anonymous> (tsserver.js:146841:21)
    at visitNode (tsserver.js:30469:24)
    at forEachChild (tsserver.js:30628:21)
    at processNode (tsserver.js:146840:20)
    at formatSpanWorker (tsserver.js:146640:17)
    at <anonymous> (tsserver.js:146603:140)
    at getFormattingScanner (tsserver.js:145230:23)
    at formatNodeGivenIndentation (tsserver.js:146603:31)
    at getFormattedTextOfNode (tsserver.js:149034:45)
    at format (tsserver.js:149005:52)
    at computeNewText (tsserver.js:149008:23)
    at <anonymous> (tsserver.js:148972:39)
    at mapDefined (tsserver.js:605:30)
    at <anonymous> (tsserver.js:148970:42)
    at mapDefined (tsserver.js:605:30)
    at getTextChangesFromChanges (tsserver.js:148956:27)
    at ChangeTracker.getChanges (tsserver.js:148895:45)
    at ChangeTracker.with (tsserver.js:148315:32)
    at getCodeActions (tsserver.js:154025:68)
    at <anonymous> (tsserver.js:149562:77)
    at flatMap (tsserver.js:508:25)
    at getFixes (tsserver.js:149562:23)
    at <anonymous> (tsserver.js:164962:35)
    at flatMap (tsserver.js:508:25)
    at getCodeFixesAtPosition (tsserver.js:164960:23)
    at Session.getCodeFixes (tsserver.js:176859:64)
    at _a.<computed> (tsserver.js:175242:61)
    at <anonymous> (tsserver.js:177172:88)
    at Session.executeWithRequestId (tsserver.js:177163:28)
    at Session.executeCommand (tsserver.js:177172:33)
    at Session.onMessage (tsserver.js:177198:35)
    at <anonymous> (tsserver.js:179833:31)

@typescript-bot
Copy link
Collaborator Author

This issue reproduced in the following context:
TypeScript version prefix: 4.7.4
VSCode version: 1.64.2
Command requested: getCodeFixes
Hitting sessions: 744
Five line hash: 8bf0402bbe40ec04bbb0073872731305
Stack:

    at setTextPos (tsserver.js:12103:22)
    at skipToEndOf (tsserver.js:145432:25)
    at processChildNodes (tsserver.js:146927:47)
    at <anonymous> (tsserver.js:146844:21)
    at visitNodes (tsserver.js:30474:24)
    at forEachChild (tsserver.js:30665:21)
    at processNode (tsserver.js:146841:20)
    at processChildNode (tsserver.js:146912:21)
    at processChildNodes (tsserver.js:146966:48)
    at <anonymous> (tsserver.js:146844:21)
    at visitNodes (tsserver.js:30474:24)
    at forEachChild (tsserver.js:30653:24)
    at processNode (tsserver.js:146841:20)
    at processChildNode (tsserver.js:146912:21)
    at <anonymous> (tsserver.js:146842:21)
    at visitNode (tsserver.js:30469:24)
    at forEachChild (tsserver.js:30565:21)
    at processNode (tsserver.js:146841:20)
    at processChildNode (tsserver.js:146912:21)
    at processChildNodes (tsserver.js:146966:48)
    at <anonymous> (tsserver.js:146844:21)
    at visitNodes (tsserver.js:30474:24)
    at forEachChild (tsserver.js:30627:21)
    at processNode (tsserver.js:146841:20)
    at formatSpanWorker (tsserver.js:146641:17)
    at <anonymous> (tsserver.js:146604:140)
    at getFormattingScanner (tsserver.js:145231:23)
    at formatNodeGivenIndentation (tsserver.js:146604:31)
    at getFormattedTextOfNode (tsserver.js:149035:45)
    at format (tsserver.js:149006:52)
    at computeNewText (tsserver.js:149009:23)
    at <anonymous> (tsserver.js:148973:39)
    at mapDefined (tsserver.js:605:30)
    at <anonymous> (tsserver.js:148971:42)
    at mapDefined (tsserver.js:605:30)
    at getTextChangesFromChanges (tsserver.js:148957:27)
    at ChangeTracker.getChanges (tsserver.js:148896:45)
    at ChangeTracker.with (tsserver.js:148316:32)
    at getCodeActions (tsserver.js:154048:68)
    at <anonymous> (tsserver.js:149563:77)
    at flatMap (tsserver.js:508:25)
    at getFixes (tsserver.js:149563:23)
    at <anonymous> (tsserver.js:164985:35)
    at flatMap (tsserver.js:508:25)
    at getCodeFixesAtPosition (tsserver.js:164983:23)
    at unknown (suppressed.js:182:34)
    at unknown (suppressed.js:79:25)
    at Session.getCodeFixes (tsserver.js:176882:64)
    at _a.<computed> (tsserver.js:175265:61)
    at <anonymous> (tsserver.js:177195:88)
    at Session.executeWithRequestId (tsserver.js:177186:28)
    at Session.executeCommand (tsserver.js:177195:33)
    at Session.onMessage (tsserver.js:177221:35)
    at <anonymous> (tsserver.js:179856:31)
    at unknown (suppressed.js:315:20)
    at unknown (suppressed.js:903:12)
    at unknown (suppressed.js:81:21)

@jakebailey
Copy link
Member

jakebailey commented Jul 21, 2022

Redused-ish repro:

/// <reference path="fourslash.ts" />

// @filename: index.esm.d.ts
//// export declare class Chart {
////     constructor(config: ChartConfiguration);
//// }
//// 
//// export interface ChartConfiguration {
////     options?: Partial<TickOptions>;
//// }
//// 
//// export interface TickOptions {
////     callback: (this: Scale, tickValue: number | string) => string | string[] | number | number[] | null | undefined;
//// }
//// 
//// export interface CoreScaleOptions {
////     opt: boolean;
//// }
////   
//// export interface Scale<O extends CoreScaleOptions = CoreScaleOptions> {
////     opts: O;
////     getLabelForValue(value: number): string;
//// }
  
// @filename: options.ts
//// import { Chart } from './index.esm';
//// 
//// const chart = new Chart({
////     options: {
////         callback(tickValue) {
////             /*a*/const value = this.getLabelForValue(tickValue as number);/*b*/
////             return '$' + value;
////         }
////     }
//// });

goTo.file("options.ts");
verify.noErrors();
goTo.select("a", "b");
edit.applyRefactor({
    refactorName: "Extract Symbol",
    actionName: "function_scope_0",
    actionDescription: "Extract to inner function in method 'callback'",
    newContent:
`TODO`
});

Feels like another node reuse problem, kinda like I fixed in #48490.

@jakebailey
Copy link
Member

jakebailey commented Jul 21, 2022

No, different problem. The formatter doesn't seem to like synthesized nodes/arrays, which can happen since code fixes and refactors generate code (which means we may create import nodes, for example), which is then formatted before being returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Source: Telemetry The issue relates to the telemetry in editors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants