microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.06k stars 12.49k forks source link

File gets corrupted due to mismatched file casing #57578

Open mjbvz opened 8 months ago

mjbvz commented 8 months ago

🔎 Search Terms

🕗 Version & Regression Information

5.5.0-dev.20240226

⏯ Playground Link

No response

💻 Code

In the vscode repo, create a file:

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

/**
 * A hierarchical value.
 */
export class HierarchicalScope {
    public static readonly sep = '.';

    constructor(
        public readonly value: string
    ) { }

    public equals(other: HierarchicalScope): boolean {
        return this.value === other.value;
    }

    public contains(other: HierarchicalScope): boolean {
        return this.equals(other) || this.value === '' || other.value.startsWith(this.value + HierarchicalScope.sep);
    }

    public intersects(other: HierarchicalScope): boolean {
        return this.contains(other) || other.contains(this);
    }

    public append(...parts: string[]): HierarchicalScope {
        // TODO: escape parts
        return new HierarchicalScope([this.value, ...parts].join(HierarchicalScope.sep));
    }
}
  1. Delete the whole comment for A hierarchical value.
  2. undo
  3. Try formatting the file

🙁 Actual behavior

The file becomes corrupted. Running format produces:

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

xport class HierarchicalScope {
    ublic static readonly sep = '.';

    constructor(
        public readonly value: string
     { }

    public equals(other: HierarchicalScope): boolean {
        return this.value === other.value;

    public contains(other: HierarchicalScope): boolean {
        return this.equals(other) || this.value === '' || other.value.startsWith(this.value + HierarchicalScope.sep);

    public intersects(other: HierarchicalScope): boolean {
        return this.contains(other) || other.contains(this);

public append(...parts: string[]): HierarchicalScope {
        // TODO: escape parts
        return new HierarchicalScope([this.value, ...parts].join(HierarchicalScope.sep));
    }
}

🙂 Expected behavior

File shouldn't be corrupted

Additional information about the issue

Server logs

tsserver.log

mjbvz commented 8 months ago

Actually looks unrelated to the actual edits. Instead it seems to be a file casing issue where both hierarchicalScope.ts and HierarchicalScope.ts are being used

sheetalkamat commented 8 months ago

File was opened with:

"file": "/Users/matb/projects/vscode/src/vs/base/common/hierarchicalScope.ts", (line 113 in the log)

But further down the requests come with different casing and it just uses that.. This results in conflict in what we would return in results depending on how they are retrieved.

Seems like vscode issue instead.

Info 4241 [10:54:47.471] request:
    {
      "seq": 14,
      "type": "request",
      "command": "configure",
      "arguments": {
        "file": "/Users/matb/projects/vscode/src/vs/base/common/HierarchicalScope.ts",

seems like vscode is sending wrong casing at this location...