Skip to content

Commit 2f22e62

Browse files
Show filename as relative path to workspace in spans (#60)
1 parent 52f0fe4 commit 2f22e62

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

.changeset/honest-flies-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect-vscode": patch
3+
---
4+
5+
Show filename as relative path to workspace in spans

src/DebugSpanStackProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
registerCommand,
1414
revealFile,
1515
TreeDataProvider,
16-
treeDataProvider
16+
treeDataProvider,
17+
vscodeUriFromPath
1718
} from "./VsCode"
1819

1920
class SpanNode {
@@ -180,7 +181,8 @@ const treeItem = (node: TreeNode): vscode.TreeItem => {
180181
)
181182
item.contextValue = "span"
182183
if (node.span.path) {
183-
item.description = vscode.workspace.asRelativePath(node.span.path) + ":" + node.span.line + ":" +
184+
item.description = vscode.workspace.asRelativePath(vscodeUriFromPath(node.span.path)) + ":" + node.span.line +
185+
":" +
184186
node.span.column
185187
}
186188
if (node.span.stackIndex >= 1) {

src/VsCode.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,23 @@ export const debugRequest = <A = unknown>(
324324
): Effect.Effect<A, never, VsCodeDebugSession> =>
325325
Effect.flatMap(VsCodeDebugSession, (session) => thenable(() => session.customRequest(command, args)))
326326

327+
export const vscodeUriFromPath = (path: string) => {
328+
const pathLowered = path.toLowerCase()
329+
if (
330+
pathLowered.startsWith("file://") || pathLowered.startsWith("http://") || pathLowered.startsWith("https://")
331+
) return vscode.Uri.parse(path, false)
332+
return vscode.Uri.file(path)
333+
}
334+
327335
export const revealFile = (
328336
path: string,
329337
selection?: vscode.Range
330338
) =>
331-
Effect.flatMap(
332-
thenable(() => vscode.workspace.openTextDocument(vscode.Uri.parse(path, false))),
333-
(doc) => thenable(() => vscode.window.showTextDocument(doc, { selection }))
339+
thenable(() => vscode.workspace.openTextDocument(vscodeUriFromPath(path))).pipe(
340+
Effect.flatMap((doc) => thenable(() => vscode.window.showTextDocument(doc, { selection })))
334341
)
342+
343+
export const revealFileWithSelection = (
344+
path: string,
345+
selection: vscode.Range
346+
) => revealFile(path, selection)

0 commit comments

Comments
 (0)