Skip to content

Formatter doesn't recognize file type change #47448

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

Open
DanielRosenwasser opened this issue Jan 14, 2022 · 4 comments
Open

Formatter doesn't recognize file type change #47448

DanielRosenwasser opened this issue Jan 14, 2022 · 4 comments
Labels
Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Milestone

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jan 14, 2022

Possibly related to #47446.

In VS Code, use an anonymous buffer whose language starts as "TypeScript" and switches to "TypeScript React". The formatter doesn't adapt correctly.

let x = <div>
    <div>
    </div>
</div>;

Format.

Expected

No change

Actual

let x = <div>
    <div>
    </div>
    < /div>;
@RyanCavanaugh
Copy link
Member

I couldn't repro this or the other one

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jan 19, 2022
@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Jan 19, 2022

Figured it out. If you're in VS Code and have an anonymous buffer whose language starts as "TypeScript" and switches to "TypeScript React", the formatter doesn't adapt correctly. I can't tell if that's a TypeScript or VS Code bug.

@RyanCavanaugh
Copy link
Member

The server log should indicate whether TS Server got the message that the file should be treated as TSX

@RyanCavanaugh RyanCavanaugh removed the Needs More Info The issue still hasn't been fully clarified label Jan 19, 2022
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter labels Jan 19, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 19, 2022
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Jan 19, 2022
@DanielRosenwasser
Copy link
Member Author

The log does indicate that we got the right updateOpen request.

[Trace  - 02:19:34.109] <semantic> Sending request: updateOpen (4643). Response expected: yes. Current queue length: 2
Arguments: {
    "changedFiles": [],
    "closedFiles": [],
    "openFiles": [
        {
            "file": "^/untitled/Untitled-4",
            "fileContent": "let x = <div>\r\n</div>",
            "projectRootPath": "c:\\Users\\ME\\scratch\\example",
            "scriptKindName": "TSX"
        }
    ]
}

TypeScript also knows to interpret that code as JSX, but the formatter apparently doesn't.

@DanielRosenwasser DanielRosenwasser changed the title Strange file formatting for JSX Formatter doesn't recognize file type change Jan 21, 2022
@DanielRosenwasser DanielRosenwasser added the Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". label May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Formatter The issue relates to the built-in formatter Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants