Skip to content
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

Getting "File name X differs from already included file name Y only in casing" on Windows #2433

Closed
4 tasks done
rchl opened this issue Nov 3, 2020 · 5 comments · Fixed by #2444
Closed
4 tasks done
Labels
bug lsp:general LSP integration for use in LSP clients

Comments

@rchl
Copy link
Collaborator

rchl commented Nov 3, 2020

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Win
  • Vetur version: 0.28.0
  • VS Code version: none, using Sublime Text LSP 1.0.18

Problem

After opening a Vue file, getting a diagnostic error like:

File name 'c:/Projekt/temp/lsp-vue-repro/src/App.vue' differs from already included file name 'C:/Projekt/temp/lsp-vue-repro/src/App.vue' only in casing.

The issue happens only on Windows and with editors other than VSCode (at least with Sublime Text). The problem is that vetur does some path normalization but not consistent enough to avoid this problem.

Here are differences between the folders passed through initialize request in ST and Vscode:

ST:

  "rootPath": "C:\\workspace\\project",
  "rootUri": "file:///C:/workspace/project",
  "workspaceFolders": [
    {
      "name": "project",
      "uri": "file:///C:/workspace/project"
    }
  ]

VSCode:

    "rootPath": "c:\\workspace\\project",
    "rootUri": "file:///c%3A/workspace/project",
    "workspaceFolders": [
        {
            "uri": "file:///c%3A/workspace/project",
            "name": "project"
        }
    ]

As you can see VSCode normalizes drive letter to lower-case which is why there is no issue there. While it would be possible for ST to do the same, it's not really required per LSP spec, and also the issue is really in vetur as I'll demonstrate in next comment.

A related issue in ST: sublimelsp/LSP-vue#83

Reproducible Case

This issue doesn't reproduce on VSCode as it's doing normalization of passed in paths but it happens in Sublime Text with LSP plugin and possibly on other clients.

@rchl
Copy link
Collaborator Author

rchl commented Nov 3, 2020

Vetur generally uses its getFileFsPath utility function to get a normalized file system path from the document URI. It does that before validating the document from different notification handlers like didOpen or didChange.

The one (and the main) problem I found is that it doesn't do any normalization in the VLS.init() function. It passes whatever it has gotten from the client to the dependencyService.init call which initializes typescript service with non-nomalized filesystem path. That is problematic because that will create a list of project files in parsedConfig.fileNames with upper-case drive letter and that list will be later compared with the URIs passed through didOpen and other notifications.

@yoyo930021 yoyo930021 added bug lsp:general LSP integration for use in LSP clients labels Nov 4, 2020
rchl added a commit to rchl/vetur that referenced this issue Nov 6, 2020
On Sublime Text (and potentially other clients) the paths passed to
LSP servers on Windows have upper-case drive letter. So either:
 - C:\folder\foo
 or
 - file:///C:/folder/foo

This is problematic with Vetur as it normalizes URI paths received from
the client in notifications and requests like "textDocument/completion",
"textDocument/didChange" etc. It uses getFileFsPath() utility path to
get filesystem path from the URI.

But it doesn't do normalization for the filesystem path received through
"InitializeParams.rootPath" and then uses that path to initialize the
Typescript server. That list (parsedConfig.fileNames in serviceHost.ts)
is later used to lookup files passed through other calls and causes
issues due to there being duplicate path differing only with drive letter.

This issue doesn't reproduce in VSCode as it itself normalizes paths
passed to the server and automatically lower-cases the drive letter.

Fix by normalizing the path passed through InitializeParams.rootPath.

Fixes vuejs#2433
@tooooong
Copy link

tooooong commented Feb 1, 2021

7C%8LQD%%QHF0NISJ9YLEGF

Platform: Win10
Vetur version: 0.32.0

Is this fixed?

@yinfoyuan
Copy link

yinfoyuan commented Feb 24, 2021

Can this prompt be ignored in version 0.32.0

@rchl
Copy link
Collaborator Author

rchl commented Feb 24, 2021

Please post a server log somewhere (on gist for example).
https://github.com/vuejs/vetur/wiki/Collecting-LSP-log

(I would suggest restarting VSCode and clear the log manually before reproducing but instead provide a full log since starting VSCode)

@wangxdmm
Copy link

wangxdmm commented Nov 5, 2021

@rchl
win10
vetur v0.35.0

[Trace - 下午5:20:47] Sending request 'textDocument/codeAction - (17)'.
Params: {
    "textDocument": {
        "uri": "file:///d%3A/web-app/vue3/element-plus/packages/components/button/src/button.vue"
    },
    "range": {
        "start": {
            "line": 39,
            "character": 41
        },
        "end": {
            "line": 39,
            "character": 51
        }
    },
    "context": {
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 39,
                        "character": 41
                    },
                    "end": {
                        "line": 39,
                        "character": 51
                    }
                },
                "message": "File name 'd:/web-app/vue3/element-plus/packages/components/button/src/button.ts' differs from already included file name 'D:/web-app/vue3/element-plus/packages/components/button/src/button.ts' only in casing.\n  The file is in the program because:\n    Imported via './button' from file 'D:/web-app/vue3/element-plus/packages/components/button/src/button.vue'\n    Imported via './button' from file 'D:/web-app/vue3/element-plus/packages/components/button/src/button-group.ts'\n    Imported via './src/button' from file 'D:/web-app/vue3/element-plus/packages/components/button/index.ts'\n    Imported via './button' from file 'd:/web-app/vue3/element-plus/packages/components/button/src/button.vue'",
                "code": 1149,
                "severity": 1,
                "source": "Vetur"
            }
        ],
        "only": [
            "quickfix"
        ]
    }
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug lsp:general LSP integration for use in LSP clients
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants