From 5aa78d093608953aa34205bb40bfbf0ece8c0a74 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky <vital2580@icloud.com> Date: Fri, 24 May 2024 08:35:13 +0300 Subject: [PATCH] feat: Improve relative file path handling in filesAutoImport --- typescript/src/completions/filesAutoImport.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/typescript/src/completions/filesAutoImport.ts b/typescript/src/completions/filesAutoImport.ts index 13b9d06..207e16a 100644 --- a/typescript/src/completions/filesAutoImport.ts +++ b/typescript/src/completions/filesAutoImport.ts @@ -60,7 +60,8 @@ export default () => { const files = collected.filter(f => f.endsWith(ext)) for (const file of files) { const fullPath = nodeModules.path.join(root, file) - const relativeToFile = nodeModules.path.relative(nodeModules.path.dirname(sourceFile.fileName), fullPath).replaceAll('\\', '/') + let relativeToFile = nodeModules.path.relative(nodeModules.path.dirname(sourceFile.fileName), fullPath).replaceAll('\\', '/') + if (!relativeToFile.startsWith('.')) relativeToFile = `./${relativeToFile}` const lastModified = nodeModules.fs.statSync(fullPath).mtime const lastModifiedFormatted = timeDifference(Date.now(), lastModified.getTime()) const importPath = (item.importPath ?? '$path').replaceAll('$path', relativeToFile)