Is there a means to convert an object of type string to vscode.Uri? In my case I have a string as a result of vscode.workspace.rootPath that I'd like to join to a am the string that is a partial path of that rootPath. In a custom type I'm using, I'm extending vscode.TreeItem that has a Uri property of type vscode.Uri path.
For reasons unknown to me vscode.uri("c:\\some\\path") is not being liked by the compiler.
Is this a type that can even be converted to or from?
You can use the static Uri.file(path) function to create a vscode.Uri from a string file path:
let uri = vscode.Uri.file("c:\\some\\path");
To obtain the path in string form again, use fsPath:
let path = uri.fsPath; // c:\some\path
Something to be aware of is that the drive letter in Windows paths is normalized. So when doing a round-trip like this, it will be c: even if you originally started with C:. It will also replace / and \ depending on the current platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With