microsoft / TypeScript

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

[Bug] Occurrence Highlight does not work in case of file path case mismatch #43261

Open RamyRafik opened 3 years ago

RamyRafik commented 3 years ago

Issue:

On a TypeScript project, if the TSConfig has relative files paths, Occurrence Highlight in Editor works for that file If it has absolute paths with upper-case Drive letter, it doesn't.

Debugging

I checked TS Server logs for 2 cases:

  1. File name in tsConfig is "./test.ts" (Occurrence Highlight works)
  2. File name in tsConfig is "Z:/Code/Playground/test-ts-absolutePaths/test.ts" (Occurrence Highlight doesn't work)

In case 1, the documentHighlights command Request and Response are

{
    "seq": 13,
    "type": "request",
    "command": "documentHighlights",
    "arguments": {
        "file": "z:/Code/Playground/test-ts-absolutePaths/test.ts",
        "line": 2,
        "offset": 15,
        "filesToSearch": [
            "z:/Code/Playground/test-ts-absolutePaths/test.ts"
        ]
    }
}

{
    "seq": 0,
    "type": "response",
    "command": "documentHighlights",
    "request_seq": 13,
    "success": true,
    "body": [
        {
            "file": "z:/Code/Playground/test-ts-absolutePaths/test.ts",
            "highlightSpans": [
                {
                    "start": {
                        "line": 2,
                        "offset": 13
                    },
                    "end": {
                        "line": 2,
                        "offset": 17
                    },
                    "contextStart": {
                        "line": 2,
                        "offset": 5
                    },
                    "contextEnd": {
                        "line": 2,
                        "offset": 26
                    },
                    "kind": "reference"
                },
                {
                    "start": {
                        "line": 5,
                        "offset": 14
                    },
                    "end": {
                        "line": 5,
                        "offset": 18
                    },
                    "kind": "writtenReference"
                },
                {
                    "start": {
                        "line": 9,
                        "offset": 26
                    },
                    "end": {
                        "line": 9,
                        "offset": 30
                    },
                    "kind": "reference"
                }
            ]
        }
    ]
}

In case 2

{
    "seq": 18,
    "type": "request",
    "command": "documentHighlights",
    "arguments": {
        "file": "z:/Code/Playground/test-ts-absolutePaths/test.ts",
        "line": 2,
        "offset": 15,
        "filesToSearch": [
            "z:/Code/Playground/test-ts-absolutePaths/test.ts"
        ]
    }
}

{
    "seq": 0,
    "type": "response",
    "command": "documentHighlights",
    "request_seq": 18,
    "success": true,
    "body": [
        {
            "file": "Z:/Code/Playground/test-ts-absolutePaths/test.ts",
            "highlightSpans": [
                {
                    "start": {
                        "line": 2,
                        "offset": 13
                    },
                    "end": {
                        "line": 2,
                        "offset": 17
                    },
                    "contextStart": {
                        "line": 2,
                        "offset": 5
                    },
                    "contextEnd": {
                        "line": 2,
                        "offset": 26
                    },
                    "kind": "reference"
                },
                {
                    "start": {
                        "line": 5,
                        "offset": 14
                    },
                    "end": {
                        "line": 5,
                        "offset": 18
                    },
                    "kind": "writtenReference"
                },
                {
                    "start": {
                        "line": 9,
                        "offset": 26
                    },
                    "end": {
                        "line": 9,
                        "offset": 30
                    },
                    "kind": "reference"
                }
            ]
        }
    ]
}

The only difference is the Drive letter case (Z vs z) TS Server seems to work as intended. I can see 2 possible solutions:

Project folder is zipped and attached test-ts-absolutePaths.zip

vscodebot[bot] commented 3 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like: