Skip to content

Commit

Permalink
refactor: ♻️ improve script file resolution logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 13, 2024
1 parent fa3f846 commit dd8d647
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/vscode/src/fragmentcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,26 @@ export function activateFragmentCommands(state: ExtensionState) {
const { context, host } = state
const { subscriptions } = context

const scriptFile = (p: PromptScript) =>
state.host.path.isAbsolute(p.filename)
? p.filename
: state.host.path.resolve(state.host.projectFolder(), p.filename)

const findScript = (filename: vscode.Uri) => {
const fp = state.host.path.resolve(filename.fsPath)
const scripts = state.project.scripts.filter((p) => !!p.filename)
const script = scripts
.filter((p) => !!p.filename)
.find((p) => {
const pf = state.host.path.isAbsolute(p.filename)
? p.filename
: state.host.path.resolve(
state.host.projectFolder(),
p.filename
)
return pf === fp
const sfp = scriptFile(p)
return sfp === fp
})

if (!script) {
state.output.appendLine(`requested script: ${fp}`)
scripts.forEach((s) => state.output.appendLine(`- ${s.filename}`))
scripts.forEach((s) =>
state.output.appendLine(`- ${s.filename}\n ${scriptFile(s)}`)
)

const reportIssue = "Report Issue"
vscode.window
Expand Down

0 comments on commit dd8d647

Please sign in to comment.