Use vscode-uri instead of node's path

This makes sure we handle other types of uris instead of assuming they are all file uris
This commit is contained in:
Matt Bierner
2022-03-08 15:30:44 -08:00
parent 6ecba6531f
commit 79d381f1df
7 changed files with 22 additions and 23 deletions

View File

@@ -5,10 +5,10 @@
import * as path from 'path';
import * as vscode from 'vscode';
import * as uri from 'vscode-uri';
import { MarkdownEngine } from '../markdownEngine';
import { TableOfContents } from '../tableOfContentsProvider';
import { isMarkdownFile } from './file';
import { extname } from './path';
export interface OpenDocumentLinkArgs {
readonly parts: vscode.Uri;
@@ -53,7 +53,7 @@ export async function openDocumentLink(engine: MarkdownEngine, targetResource: v
if (typeof targetResourceStat === 'undefined') {
// We don't think the file exists. If it doesn't already have an extension, try tacking on a `.md` and using that instead
if (extname(targetResource.path) === '') {
if (uri.Utils.extname(targetResource) === '') {
const dotMdResource = targetResource.with({ path: targetResource.path + '.md' });
try {
const stat = await vscode.workspace.fs.stat(dotMdResource);
@@ -140,7 +140,7 @@ export async function resolveUriToMarkdownFile(resource: vscode.Uri): Promise<vs
}
// If no extension, try with `.md` extension
if (extname(resource.path) === '') {
if (uri.Utils.extname(resource) === '') {
return tryResolveUriToMarkdownFile(resource.with({ path: resource.path + '.md' }));
}