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

Language Server: Problem with incorrect paths in Windows #1316

Closed
3 tasks done
Narretz opened this issue May 31, 2019 · 4 comments · Fixed by #1662
Closed
3 tasks done

Language Server: Problem with incorrect paths in Windows #1316

Narretz opened this issue May 31, 2019 · 4 comments · Fixed by #1662

Comments

@Narretz
Copy link
Contributor

Narretz commented May 31, 2019

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: Windows
  • Language Server: 0.0.56

Problem

I'm using the vls together with Language Server Protocol in Sublime Text 3.
However, the problem doesn't look like it depends on these programs.

What happens is that VLS in some cases passes the wrong path to typescript, which makes it fail when trying to find a source file. For example:

const fileFsPath = getFileFsPath(doc.uri);
const rawScriptDiagnostics = [
...service.getSyntacticDiagnostics(fileFsPath),
...service.getSemanticDiagnostics(fileFsPath)
];

This produces an uri like c:\Users\path\src\components\App.vue but Typescript internally has this file stored as C:/Users/path/src/components/App.vue

Reproducible Case

@octref
Copy link
Member

octref commented Jun 19, 2019

in some cases passes
Do you have a specific case that I can repro?

Can you repro by modifying https://github.com/octref/veturpack?

@Narretz
Copy link
Contributor Author

Narretz commented Aug 9, 2019

I still don't have a simple reproducible case, but I looked into this further I may have found the problem.

vls usually uses getFsFilePath to get the path to a file before it sends it to the relevant service, e.g. here:

const fileFsPath = getFileFsPath(doc.uri);

getFsFilePath runs vscode-uri.parse().fsPath, which on Windows gives the following result with a file uri sent from Sublime LSP:
file:///C:/Users/Martin/dev/newnow/pdf_vue/src/components/HelloWorld.vue
->
c:\Users\path\src\components\App.vue

As written above, this breaks typescript in my setup (Windows + Sublime Text + Sublime LSP) because previously, the tsserver has stored the sourceFiles like so: c:/Users/path/src/components/App.vue

Now there's another function called getFilePath:

export function getFilePath(documentUri: string): string {
const IS_WINDOWS = platform() === 'win32';
if (IS_WINDOWS) {
// Windows have a leading slash like /C:/Users/pine
return Uri.parse(documentUri).path.slice(1);
} else {
return Uri.parse(documentUri).path;
}

which returns exactly what we (I) need:
c:/Users/path/src/components/App.vue

Any reason why getFsFilePath instead of getFilePath is used?

I noticed that in another function, getFilePath is used to see if a file exists in the service:

export function languageServiceIncludesFile(ls: ts.LanguageService, documentUri: string): boolean {

@mattn
Copy link
Contributor

mattn commented Jan 21, 2020

I got same. Current implementation does not handle Windows paths correctly. I'm using vim-lsp but vetur does not works eventhough another language server works fine on Windows.

@mattn
Copy link
Contributor

mattn commented Jan 21, 2020

I confirmed this issue fixes with #1662

@Narretz Could you please try this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants