Skip to content

Commit

Permalink
Use path instead of fsPath
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Oct 3, 2023
1 parent c6d6185 commit e6a5ba3
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/features/antora/antoraSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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('/'))
}
}

Expand Down Expand Up @@ -53,15 +55,15 @@ 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
}
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
Expand Down Expand Up @@ -120,7 +122,7 @@ export class AntoraSupportManager implements vscode.Disposable {
}

public static async isEnabled (workspaceState: Memento): Promise<Boolean> {
return (await AntoraSupportManager.getInstance(workspaceState)).isEnabled()
return AntoraSupportManager.getInstance(workspaceState).isEnabled()
}

public async getAttributes (textDocumentUri: Uri): Promise<{ [key: string]: string }> {
Expand Down Expand Up @@ -206,7 +208,7 @@ export async function getAntoraConfigs (): Promise<AntoraConfig[]> {
} 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
}
Expand All @@ -216,14 +218,13 @@ export async function getAntoraConfig (textDocumentUri: Uri): Promise<AntoraConf
if (antoraConfigUri === undefined) {
return undefined
}
const antoraConfigPath = antoraConfigUri.fsPath
let config = {}
try {
config = yaml.load(fs.readFileSync(antoraConfigPath, 'utf8')) || {}
config = yaml.load(fs.readFileSync(antoraConfigUri.fsPath, 'utf8')) || {}
} catch (err) {
console.log(`Unable to parse ${antoraConfigPath}, cause:` + err.toString())
console.log(`Unable to parse ${antoraConfigUri.fsPath}, cause:` + err.toString())
}
return new AntoraConfig(antoraConfigPath, config)
return new AntoraConfig(antoraConfigUri.path, config)
}

export async function getAttributes (textDocumentUri: Uri): Promise<{ [key: string]: string }> {
Expand All @@ -235,7 +236,7 @@ export async function getAttributes (textDocumentUri: Uri): Promise<{ [key: stri
}

export async function getAntoraDocumentContext (textDocumentUri: Uri, workspaceState: Memento): Promise<AntoraDocumentContext | undefined> {
const antoraSupportManager = await AntoraSupportManager.getInstance(workspaceState)
const antoraSupportManager = AntoraSupportManager.getInstance(workspaceState)
if (!antoraSupportManager.isEnabled()) {
return undefined
}
Expand All @@ -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)),
},
})
}))
Expand Down

0 comments on commit e6a5ba3

Please sign in to comment.