From e6a5ba33d6f18ee711301325990373945f788863 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Tue, 3 Oct 2023 10:25:17 +0200 Subject: [PATCH] Use path instead of fsPath --- src/features/antora/antoraSupport.ts | 44 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/features/antora/antoraSupport.ts b/src/features/antora/antoraSupport.ts index 90790447..2757c2ca 100644 --- a/src/features/antora/antoraSupport.ts +++ b/src/features/antora/antoraSupport.ts @@ -2,7 +2,7 @@ import vscode, { CancellationTokenSource, FileType, Memento, Uri } from 'vscode' import fs from 'fs' import yaml from 'js-yaml' import File from 'vinyl' -import * as path from 'path' +import { posix as posixpath } from 'path' import AntoraCompletionProvider from './antoraCompletionProvider' import { disposeAll } from '../../util/dispose' import * as nls from 'vscode-nls' @@ -17,7 +17,9 @@ export interface AntoraResourceContext { } export class AntoraConfig { - constructor (public fsPath: string, public config: { [key: string]: any }) { + public contentSourceRootPath: string + constructor (public path: string, public config: { [key: string]: any }) { + this.contentSourceRootPath = path.slice(0, path.lastIndexOf('/')) } } @@ -53,7 +55,7 @@ export class AntoraContext { if (antoraConfig === undefined) { return undefined } - const contentSourceRootPath = path.dirname(antoraConfig.fsPath) + const contentSourceRootPath = antoraConfig.contentSourceRootPath const config = antoraConfig.config if (config.name === undefined) { return undefined @@ -61,7 +63,7 @@ export class AntoraContext { const page = this.contentCatalog.getByPath({ component: config.name, version: config.version, - path: path.relative(contentSourceRootPath, textDocumentUri.path), + path: posixpath.relative(contentSourceRootPath, textDocumentUri.path), }) if (page === undefined) { return undefined @@ -120,7 +122,7 @@ export class AntoraSupportManager implements vscode.Disposable { } public static async isEnabled (workspaceState: Memento): Promise { - return (await AntoraSupportManager.getInstance(workspaceState)).isEnabled() + return AntoraSupportManager.getInstance(workspaceState).isEnabled() } public async getAttributes (textDocumentUri: Uri): Promise<{ [key: string]: string }> { @@ -206,7 +208,7 @@ export async function getAntoraConfigs (): Promise { } catch (err) { console.log(`Unable to parse ${antoraConfigUri}, cause:` + err.toString()) } - return new AntoraConfig(antoraConfigUri.fsPath, config) + return new AntoraConfig(antoraConfigUri.path, config) })) return antoraConfigs.filter((c) => c) // filter undefined } @@ -216,14 +218,13 @@ export async function getAntoraConfig (textDocumentUri: Uri): Promise { @@ -235,7 +236,7 @@ export async function getAttributes (textDocumentUri: Uri): Promise<{ [key: stri } export async function getAntoraDocumentContext (textDocumentUri: Uri, workspaceState: Memento): Promise { - const antoraSupportManager = await AntoraSupportManager.getInstance(workspaceState) + const antoraSupportManager = AntoraSupportManager.getInstance(workspaceState) if (!antoraSupportManager.isEnabled()) { return undefined } @@ -244,24 +245,23 @@ export async function getAntoraDocumentContext (textDocumentUri: Uri, workspaceS const contentAggregate: { name: string, version: string, files: any[] }[] = (await Promise.all(antoraConfigs .filter((antoraConfig) => antoraConfig.config !== undefined && 'name' in antoraConfig.config && 'version' in antoraConfig.config) .map(async (antoraConfig) => { - const contentSourceRootPath = path.dirname(antoraConfig.fsPath) - const workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(antoraConfig.fsPath)) - const workspaceRelative = path.relative(workspaceFolder.uri.fsPath, contentSourceRootPath) + const contentSourceRootPath = antoraConfig.contentSourceRootPath + const workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(antoraConfig.path)) + const workspaceRelative = posixpath.relative(workspaceFolder.uri.path, contentSourceRootPath) const files = await Promise.all((await vscode.workspace.findFiles(workspaceRelative + '/modules/**/*')).map(async (file) => { return new File({ base: contentSourceRootPath, - path: path.relative(contentSourceRootPath, file.path), - contents: Buffer.from((await vscode.workspace.fs.readFile(Uri.file(file.fsPath)))), - extname: path.extname(file.path), - stem: path.basename(file.path, path.extname(file.path)), + path: posixpath.relative(contentSourceRootPath, file.path), + contents: Buffer.from((await vscode.workspace.fs.readFile(file))), + extname: posixpath.extname(file.path), + stem: posixpath.basename(file.path, posixpath.extname(file.path)), src: { abspath: file.path, - basename: path.basename(file.path), + basename: posixpath.basename(file.path), editUrl: '', - extname: path.extname(file.path), - fileUrl: file.fsPath, + extname: posixpath.extname(file.path), path: file.path, - stem: path.basename(file.path, path.extname(file.path)), + stem: posixpath.basename(file.path, posixpath.extname(file.path)), }, }) }))