Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a relative path in the socket path #279

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { DebugProtocol } from "@vscode/debugprotocol";
import { registerInspectorView } from "./inspector";
import { AttachConfiguration, LaunchConfiguration } from "./config";
import { VersionChecker } from "./utils";
import { VersionChecker, fullPath } from "./utils";

const asyncExec = promisify(child_process.exec);

Expand Down Expand Up @@ -483,7 +483,7 @@ class RdbgAdapterDescriptorFactory implements DebugAdapterDescriptorFactory, Ver
}

if (sockPath) {
return new DebugAdapterNamedPipeServer(sockPath);
return new DebugAdapterNamedPipeServer(fullPath(sockPath, session));
}
else if (port) {
return new vscode.DebugAdapterServer(port, host);
Expand Down
25 changes: 4 additions & 21 deletions src/rdbgTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
RdbgInspectorCommand,
BaseLog,
} from "./protocol";
import { customRequest } from "./utils";
import * as path from "path";
import * as fs from "fs";
import { customRequest, fullPath } from "./utils";

export type RdbgTreeItemOptions = Pick<
vscode.TreeItem,
Expand Down Expand Up @@ -112,7 +110,7 @@ export class RecordLogItem extends BaseLogItem {
state?: vscode.TreeItemCollapsibleState,
)
{
log.location.path = fullPath(log.location.path);
log.location.path = fullPath(log.location.path, vscode.debug.activeDebugSession);
const description = prettyPath(log.location.path) + ":" + log.location.line;
const opts: RdbgTreeItemOptions = { collapsibleState: state };
opts.collapsibleState = state;
Expand Down Expand Up @@ -150,7 +148,7 @@ const locationIcon = new vscode.ThemeIcon("location");

export class LineTraceLogItem extends TraceLogItem {
constructor(log: TraceLog, idx: number, state?: vscode.TreeItemCollapsibleState) {
log.location.path = fullPath(log.location.path);
log.location.path = fullPath(log.location.path, vscode.debug.activeDebugSession);
const label = prettyPath(log.location.path) + ":" + log.location.line.toString();
const tooltip = log.location.path;
const opts: RdbgTreeItemOptions = { iconPath: locationIcon, collapsibleState: state , tooltip};
Expand All @@ -164,7 +162,7 @@ export class CallTraceLogItem extends TraceLogItem {
public readonly returnValue: TraceLog["returnValue"];
public readonly parameters: TraceLog["parameters"];
constructor(log: TraceLog, idx: number, state?: vscode.TreeItemCollapsibleState) {
log.location.path = fullPath(log.location.path);
log.location.path = fullPath(log.location.path, vscode.debug.activeDebugSession);
let iconPath: vscode.ThemeIcon;
if (log.returnValue) {
iconPath = arrowCircleLeft;
Expand Down Expand Up @@ -277,18 +275,3 @@ export class ToggleTreeItem extends RdbgTreeItem {
this._enabledCommand = undefined;
}
}

function fullPath(p: string) {
if (path.isAbsolute(p)) {
return p;
}
const workspace = vscode.debug.activeDebugSession?.workspaceFolder;
if (workspace === undefined) {
return p;
}
const fullPath = path.join(workspace.uri.fsPath, p);
if (fs.existsSync(fullPath)) {
return fullPath;
}
return p;
}
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as vscode from "vscode";
import { LaunchConfiguration } from "./config";
import * as path from "path";
import * as fs from "fs";

export async function customRequest(session: vscode.DebugSession, command: string, args?: any) {
try {
Expand All @@ -14,3 +16,18 @@ export interface VersionChecker {
getVersion(config: LaunchConfiguration): Promise<string | null>;
vernum(version: string): number;
}

export function fullPath(p: string, session: vscode.DebugSession | undefined) {
if (path.isAbsolute(p)) {
return p;
}
const workspace = session?.workspaceFolder;
if (workspace === undefined) {
return p;
}
const fullPath = path.join(workspace.uri.fsPath, p);
if (fs.existsSync(fullPath)) {
return fullPath;
}
return p;
}