How to convert a Uri to a FilePath in a VS Code Language Server?

╄→гoц情女王★ 提交于 2019-12-12 14:25:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!