Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
feat(variables): Add check for padwalker
Browse files Browse the repository at this point in the history
It can be difficult for newcommers to know that perl debugger relies on "Padwalker".
This release will display a message in the variable inspector in case PadWalker is missing.

Our CI now runs on the package manager "yarn"
  • Loading branch information
Morten Henriksen committed Feb 12, 2018
1 parent 243285f commit 9c47476
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class perlDebuggerConnection {
public perlDebugger: DebugSession;
public streamCatcher: StreamCatcher;
public perlVersion: string;
public padwalkerVersion: string;
public commandRunning: string = '';

private filename?: string;
Expand Down Expand Up @@ -362,6 +363,13 @@ export class perlDebuggerConnection {
// error on windows
}

try {
this.padwalkerVersion = await this.getPadwalkerVersion();
} catch(ignore) {
// xxx: Ignore errors - it should not break anything, this is used to
// inform the user of a missing dependency install of PadWalker
}

return this.parseResponse(data);
}

Expand Down Expand Up @@ -534,6 +542,19 @@ export class perlDebuggerConnection {
}

async variableList(scopes): Promise<ParsedVariableScope> {
// If padwalker not found then tell the user via the variable inspection
// instead of being empty.
if (!this.padwalkerVersion) {
return {
local_0: [{
name: 'PadWalker',
value: 'Not installed',
type: 'string',
variablesReference: '0',
}],
};
}

const keys = Object.keys(scopes);
let result: ParsedVariableScope = {};

Expand Down Expand Up @@ -589,6 +610,14 @@ export class perlDebuggerConnection {
return res.data[0];
}

async getPadwalkerVersion(): Promise<string> {
const res = await this.request('print $DB::OUT eval { require PadWalker; PadWalker->VERSION() }');
const version = res.data[0];
if (/^[0-9]+\.?([0-9]?)+$/.test(version)) {
return version;
}
}

async resolveFilename(filename): Promise<string> {
const res = await this.request(`p $INC{"${filename}"};`);
const [ result = '' ] = res.data;
Expand Down
2 changes: 1 addition & 1 deletion src/localSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class LocalSession implements DebugSession {
...options.env,
},
};
// print $DB::OUT eval { require PadWalker; PadWalker->VERSION(0.08) }

const session = spawn(perlCommand, commandArgs, spawnOptions);
this.stdin = session.stdin;
this.stdout = session.stdout;
Expand Down
9 changes: 9 additions & 0 deletions src/tests/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ describe('Perl debugger connection', () => {
});
});

describe('getPadwalkerVersion', () => {
it('should return version of installed padwalker', async () => {
await conn.launchRequest(FILE_TEST_PL, DATA_ROOT, [], launchOptions);
expect(conn.padwalkerVersion).toBeDefined();
expect(conn.padwalkerVersion.length).toBeGreaterThan(1);
expect(Number(conn.padwalkerVersion)).toBeGreaterThan(1);
});
});

describe('getVariableList', () => {
it('Should get more scope variables types', async function() {
await conn.launchRequest(FILE_TEST_PL, DATA_ROOT, [], launchOptions);
Expand Down

0 comments on commit 9c47476

Please sign in to comment.