File tree 2 files changed +12
-10
lines changed
2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ import fs from 'fs';
3
3
import path from 'path' ;
4
4
5
5
import {
6
- containsImageExt ,
7
6
getWorkspaceCache ,
8
7
findUriByRef ,
9
8
ensureDirectoryExists ,
10
9
parseRef ,
10
+ getWorkspaceFolder ,
11
11
} from '../utils' ;
12
12
13
13
const openDocumentByReference = async ( { reference } : { reference : string } ) => {
@@ -17,14 +17,12 @@ const openDocumentByReference = async ({ reference }: { reference: string }) =>
17
17
18
18
if ( uri ) {
19
19
await vscode . commands . executeCommand ( 'vscode.open' , uri ) ;
20
- } else if ( ! containsImageExt ( reference ) ) {
21
- // TODO: Open document regardless of extension
22
- const workspaceFolder =
23
- vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders [ 0 ] ;
20
+ } else {
21
+ const workspaceFolder = getWorkspaceFolder ( ) ! ;
24
22
if ( workspaceFolder ) {
25
23
const paths = ref . split ( '/' ) ;
26
24
const pathsWithExt = [ ...paths . slice ( 0 , - 1 ) , `${ paths . slice ( - 1 ) } .md` ] ;
27
- const filePath = path . join ( workspaceFolder . uri . fsPath , ...pathsWithExt ) ;
25
+ const filePath = path . join ( workspaceFolder , ...pathsWithExt ) ;
28
26
29
27
// don't override file content if it already exists
30
28
if ( ! fs . existsSync ( filePath ) ) {
Original file line number Diff line number Diff line change @@ -358,24 +358,28 @@ export const findAllUrisWithUnknownExts = async (uris: vscode.Uri[]) => {
358
358
359
359
export const extractExt = ( value : string ) => path . parse ( value ) . ext . replace ( / ^ \. / , '' ) ;
360
360
361
- export const findUriByRef = ( uris : vscode . Uri [ ] , ref : string ) : vscode . Uri | undefined =>
362
- uris . find ( ( uri ) => {
361
+ export const findUriByRef = ( uris : vscode . Uri [ ] , ref : string ) : vscode . Uri | undefined => {
362
+ return uris . find ( ( uri ) => {
363
+ const relativeFsPath =
364
+ path . sep + path . relative ( getWorkspaceFolder ( ) ! . toLowerCase ( ) , uri . fsPath . toLowerCase ( ) ) ;
365
+
363
366
if ( containsImageExt ( ref ) || containsOtherKnownExts ( ref ) || containsUnknownExt ( ref ) ) {
364
367
if ( isLongRef ( ref ) ) {
365
- return normalizeSlashes ( uri . fsPath . toLowerCase ( ) ) . endsWith ( ref . toLowerCase ( ) ) ;
368
+ return normalizeSlashes ( relativeFsPath ) . endsWith ( ref . toLowerCase ( ) ) ;
366
369
}
367
370
368
371
return path . basename ( uri . fsPath ) . toLowerCase ( ) === ref . toLowerCase ( ) ;
369
372
}
370
373
371
374
if ( isLongRef ( ref ) ) {
372
- return normalizeSlashes ( uri . fsPath . toLowerCase ( ) ) . endsWith ( `${ ref . toLowerCase ( ) } .md` ) ;
375
+ return normalizeSlashes ( relativeFsPath ) . endsWith ( `${ ref . toLowerCase ( ) } .md` ) ;
373
376
}
374
377
375
378
const name = path . parse ( uri . fsPath ) . name . toLowerCase ( ) ;
376
379
377
380
return containsMarkdownExt ( path . basename ( uri . fsPath ) ) && name === ref . toLowerCase ( ) ;
378
381
} ) ;
382
+ } ;
379
383
380
384
export const ensureDirectoryExists = ( filePath : string ) => {
381
385
const dirname = path . dirname ( filePath ) ;
You can’t perform that action at this time.
0 commit comments