问题
In a VS Code extension you can convert a uri to a filePath like this:
import {Uri} from 'vscode';
let uri = 'file:///c%3A/WINDOWS/file.txt';
let path:string = Uri.parse(uri).fsPath;
However, in a language server this does not work, beacuse importing vscode fails.
The reason for this is the fact that vscode is "not a real node_module"
vscode issue #6586
after successfully running,
node ./node_modules/vscode/bin/install
when the language server is started it still does not find the module:
Error: Cannot find module 'vscode'
What is the best way to transform a Uri to a filePath in a platform independent way?
回答1:
It seems that Microsoft has moved this package, so you need to do this:
First add as a dependency:
npm install --save vscode-uri
And then in your program:
import Uri from 'vscode-uri'
来源:https://stackoverflow.com/questions/37658425/how-to-convert-a-uri-to-a-filepath-in-a-vs-code-language-server