如何在 VS Code 语言服务器中将 Uri 转换为 FilePath? [英] How to convert a Uri to a FilePath in a VS Code Language Server?
问题描述
在 VS Code 扩展中,您可以像这样将 uri 转换为 filePath:
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;
但是,在语言服务器中这不起作用,因为导入 vscode 失败.这样做的原因是 vscode 不是真正的 node_module"
vscode 问题 #6586运行成功后,
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'
以独立于平台的方式将 Uri 转换为 filePath 的最佳方法是什么?
What is the best way to transform a Uri to a filePath in a platform independent way?
推荐答案
微软好像把这个包,所以你需要这样做:
It seems that Microsoft has moved this package, so you need to do this:
首先作为依赖添加:
npm install --save vscode-uri
然后在你的程序中:
import Uri from 'vscode-uri'
这篇关于如何在 VS Code 语言服务器中将 Uri 转换为 FilePath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!