Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/lib/vscode/extensions/markdown-language-features/src/util/url.ts
Joe Previte eae5d8c807
chore(vscode): update to 1.53.2
These conflicts will be resolved in the following commits. We do it this way so
that PR review is possible.
2021-02-25 11:27:27 -07:00

26 lines
1006 B
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
declare const URL: typeof import('url').URL;
/**
* Tries to convert an url into a vscode uri and returns undefined if this is not possible.
* `url` can be absolute or relative.
*/
export function urlToUri(url: string, base: vscode.Uri): vscode.Uri | undefined {
try {
// `vscode.Uri.joinPath` cannot be used, since it understands
// `src` as path, not as relative url. This is problematic for query args.
const parsedUrl = new URL(url, base.toString());
const uri = vscode.Uri.parse(parsedUrl.toString());
return uri;
} catch (e) {
// Don't crash if `URL` cannot parse `src`.
return undefined;
}
}