Skip to content

Commit 5f1287f

Browse files
committed
Expose StatementRangeSyntaxError via hooksAPI()
This is why I was needing `'positron'` as an "external" before. We've never had to expose a class that we need to construct before, and it requires using it as a "value" rather than just as a "type" so it needs to show up in `PositronApi` and be called via `hooksApi()`
1 parent 7a22bc3 commit 5f1287f

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

apps/vscode/src/@types/hooks.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare module 'positron' {
1010
runtime: PositronRuntime;
1111
languages: PositronLanguages;
1212
window: PositronWindow;
13+
StatementRangeSyntaxError: typeof StatementRangeSyntaxError;
1314
}
1415

1516
export interface PositronRuntime {

apps/vscode/src/host/hooks.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,26 @@ class EmbeddedStatementRangeProvider implements HostStatementRangeProvider {
215215
);
216216
return { range: unadjustedRange(vdoc.language, result.range), code: result.code };
217217
} catch (err) {
218+
let hooks = hooksApi();
219+
220+
if (!hooks) {
221+
throw err;
222+
}
223+
218224
// TODO: Remove this once `apps/vscode/package.json` bumps to `"positron": "^2026.03.0"` or higher.
219225
// For now we avoid aggressive bumping due to https://github.com/posit-dev/positron/issues/11321.
220-
if (semver.gte(hooks.version, "2026.03.0")) {
221-
if (err instanceof hooks.StatementRangeSyntaxError) {
222-
// Rethrow syntax error with unadjusted line number, so Positron's notification will
223-
// jump to the correct line
224-
throw new hooks.StatementRangeSyntaxError(err.line ? unadjustedLine(vdoc.language, err.line) : undefined);
225-
}
226+
if (semver.lt(hooks.version, "2026.03.0")) {
227+
throw err;
228+
}
229+
230+
if (err instanceof hooks.StatementRangeSyntaxError) {
231+
// Rethrow syntax error with unadjusted line number, so Positron's notification will
232+
// jump to the correct line
233+
throw new hooks.StatementRangeSyntaxError(err.line ? unadjustedLine(vdoc.language, err.line) : undefined);
234+
} else {
235+
// Rethrow unrecognized error
236+
throw err;
226237
}
227-
throw err;
228238
}
229239
});
230240
};

0 commit comments

Comments
 (0)