Skip to content

Commit fecaea3

Browse files
committed
Add support for debugpy and fix loading of Shapely geometries
1 parent 6c1547a commit fecaea3

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

resources/python.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"kind": "container",
102102
"array": {
103103
"start": "$this",
104-
"size": "$this.__len__()"
104+
"size": "int($this.__len__())"
105105
},
106106
"_comment": "Shapely module"
107107
},
@@ -110,7 +110,7 @@
110110
"kind": "container",
111111
"array": {
112112
"start": "$this",
113-
"size": "$this.__len__()"
113+
"size": "int($this.__len__())"
114114
},
115115
"_comment": "Shapely module"
116116
},
@@ -144,7 +144,7 @@
144144
"kind": "container",
145145
"array": {
146146
"start": "$this",
147-
"size": "$this.__len__()"
147+
"size": "int($this.__len__())"
148148
},
149149
"_comment": "Shapely module"
150150
},
@@ -153,7 +153,7 @@
153153
"kind": "container",
154154
"array": {
155155
"start": "$this",
156-
"size": "$this.__len__()"
156+
"size": "int($this.__len__())"
157157
},
158158
"_comment": "Shapely module"
159159
},

src/debugger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class SessionInfo {
1919
return undefined;
2020
if (['cppvsdbg', 'cppdbg', 'lldb', 'cortex-debug'].includes(sessionType))
2121
return Language.Cpp;
22-
else if (['python', 'Python Kernel Debug Adapter'].includes(sessionType))
22+
else if (['python', 'debugpy', 'Python Kernel Debug Adapter'].includes(sessionType))
2323
return Language.Python;
2424
else if (['node', 'chrome', 'msedge', 'pwa-node', 'pwa-chrome', 'pwa-msedge'].includes(sessionType))
2525
return Language.JavaScript;
@@ -230,7 +230,7 @@ export class Debugger {
230230
}
231231

232232
private _isPythonError(type: string): boolean {
233-
return (type === 'NameError' || type === 'AttributeError') && this.sessionInfo?.language === Language.Python;
233+
return (type === 'NameError' || type === 'AttributeError' || type === 'TypeError') && this.sessionInfo?.language === Language.Python;
234234
}
235235

236236
private _isRubyError(type: string): boolean {

src/loader.ts

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,35 @@ export class Geometries extends ContainerLoader {
446446
}
447447
}
448448

449+
export class DynamicGeometries extends ContainerLoader {
450+
constructor(private _container: Container) {
451+
super();
452+
}
453+
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
454+
let drawables: draw.Drawable[] = [];
455+
for await (let elStr of this._container.elements(dbg, variable)) {
456+
const elType = await dbg.getRawType(elStr);
457+
if (elType === undefined)
458+
return undefined;
459+
const v = new Variable(elStr, elType);
460+
let elLoad = this._loaders.get(elType);
461+
if (elLoad === undefined) {
462+
elLoad = await getLoader(dbg, v);
463+
if (elLoad === undefined)
464+
return undefined;
465+
this._loaders.set(elType, elLoad);
466+
}
467+
const d = await elLoad.load(dbg, v);
468+
if (d === undefined)
469+
return undefined;
470+
drawables.push(d);
471+
}
472+
return new draw.Drawables(drawables);
473+
}
474+
475+
private _loaders: Map<string, Geometry> = new Map<string, Geometry>();
476+
}
477+
449478
// Geometric primitives
450479

451480
export class Geometry extends Loader {
@@ -741,33 +770,28 @@ export class Polygon extends Geometry {
741770
private _intLoad: Geometries | undefined = undefined;
742771
}
743772

744-
export class GeometryCollection extends ContainerLoader {
745-
constructor(private _container: Container) {
773+
export class MultiGeometry extends Geometry {
774+
constructor(private _containerExpr: EvaluatedExpression,
775+
private _geometriesLoad: Geometries) {
746776
super();
747777
}
748778
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
749-
let drawables: draw.Drawable[] = [];
750-
for await (let elStr of this._container.elements(dbg, variable)) {
751-
const elType = await dbg.getRawType(elStr);
752-
if (elType === undefined)
753-
return undefined;
754-
const v = new Variable(elStr, elType);
755-
let elLoad = this._loaders.get(elType);
756-
if (elLoad === undefined) {
757-
elLoad = await getLoader(dbg, v);
758-
if (elLoad === undefined)
759-
return undefined;
760-
this._loaders.set(elType, elLoad);
761-
}
762-
const d = await elLoad.load(dbg, v);
763-
if (d === undefined)
764-
return undefined;
765-
drawables.push(d);
766-
}
767-
return new draw.Drawables(drawables);
779+
const contStr = this._containerExpr.expression.toString(variable);
780+
const contVar = new Variable(contStr, this._containerExpr.type);
781+
return this._geometriesLoad.load(dbg, contVar);
768782
}
783+
}
769784

770-
private _loaders: Map<string, Geometry> = new Map<string, Geometry>();
785+
export class GeometryCollection extends Geometry {
786+
constructor(private _containerExpr: EvaluatedExpression,
787+
private _dynamicGeometriesLoad: DynamicGeometries) {
788+
super();
789+
}
790+
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
791+
const contStr = this._containerExpr.expression.toString(variable);
792+
const contVar = new Variable(contStr, this._containerExpr.type);
793+
return this._dynamicGeometriesLoad.load(dbg, contVar);
794+
}
771795
}
772796

773797
class LanguageTypes {
@@ -1122,7 +1146,9 @@ export async function getLoader(dbg: debug.Debugger,
11221146
const contExpr = await evaluateExpression(dbg, variable, entry.linestrings.container.name, entry.linestrings.container.type);
11231147
if (contExpr) {
11241148
const contVar = contExpr.variable;
1125-
return await getLoader(dbg, contVar, onlyContainers, onlyLinestrings);
1149+
const geometriesLoad = await getLoader(dbg, contVar, onlyContainers, onlyLinestrings) as Geometries;
1150+
if (geometriesLoad != undefined)
1151+
return new MultiGeometry(contExpr, geometriesLoad);
11261152
}
11271153
}
11281154
else {
@@ -1138,7 +1164,9 @@ export async function getLoader(dbg: debug.Debugger,
11381164
const contExpr = await evaluateExpression(dbg, variable, entry.polygons.container.name, entry.polygons.container.type);
11391165
if (contExpr) {
11401166
const contVar = contExpr.variable;
1141-
return await getLoader(dbg, contVar, onlyContainers, onlyPolygons);
1167+
const geometriesLoad = await getLoader(dbg, contVar, onlyContainers, onlyPolygons) as Geometries;
1168+
if (geometriesLoad != undefined)
1169+
return new MultiGeometry(contExpr, geometriesLoad);
11421170
}
11431171
}
11441172
else {
@@ -1155,14 +1183,14 @@ export async function getLoader(dbg: debug.Debugger,
11551183
if (contExpr) {
11561184
const contVar = contExpr.variable;
11571185
const contLoad = await getContainer(dbg, contExpr.variable);
1158-
if (contLoad)
1159-
return new GeometryCollection(contLoad);
1186+
if (contLoad !== undefined)
1187+
return new GeometryCollection(contExpr, new DynamicGeometries(contLoad));
11601188
}
11611189
}
11621190
else {
11631191
const contLoad: Container | undefined = await _getContainer(dbg, variable, entry.geometries.container);
11641192
if (contLoad !== undefined)
1165-
return new GeometryCollection(contLoad);
1193+
return new DynamicGeometries(contLoad);
11661194
}
11671195
}
11681196
}

0 commit comments

Comments
 (0)