Skip to content

Commit

Permalink
set "noImplicitAny" to true and fix the problems
Browse files Browse the repository at this point in the history
  • Loading branch information
oltolm authored and WebFreak001 committed Apr 5, 2024
1 parent 86b6678 commit 1b9f13e
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 56 deletions.
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/mocha": "^5.2.6",
"@types/node": "^11.11.3",
"@types/ssh2": "^1.15.0",
"@types/vscode": "^1.55.0",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
Expand Down
4 changes: 2 additions & 2 deletions src/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface IBackend {
attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any>;
connect(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any>;
start(runToStart: boolean): Thenable<boolean>;
stop();
detach();
stop(): void;
detach(): void;
interrupt(): Thenable<boolean>;
continue(): Thenable<boolean>;
next(): Thenable<boolean>;
Expand Down
11 changes: 6 additions & 5 deletions src/backend/gdb_expansion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { VariableObject } from "./backend";
import { MINode } from "./mi_parse";

const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;
Expand Down Expand Up @@ -29,7 +30,7 @@ export function isExpandable(value: string): number {
else return 0;
}

export function expandValue(variableCreate: Function, value: string, root: string = "", extra: any = undefined): any {
export function expandValue(variableCreate: (arg: VariableObject | string, options?: any) => any, value: string, root: string = "", extra: any = undefined): any {
const parseCString = () => {
value = value.trim();
if (value[0] != '"' && value[0] != '\'')
Expand All @@ -56,10 +57,10 @@ export function expandValue(variableCreate: Function, value: string, root: strin
};

const stack = [root];
let parseValue, parseCommaResult, parseCommaValue, parseResult, createValue;
let parseValue: () => any, parseCommaResult: (pushToStack: boolean) => any, parseCommaValue: () => any, parseResult: (pushToStack: boolean) => any, createValue: (name: string, val: any) => any;
let variable = "";

const getNamespace = (variable) => {
const getNamespace = (variable: string) => {
let namespace = "";
let prefix = "";
stack.push(variable);
Expand Down Expand Up @@ -209,7 +210,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
return createValue(name, val);
};

createValue = (name, val) => {
createValue = (name: string, val: any) => {
let ref = 0;
if (typeof val == "object") {
ref = variableCreate(val);
Expand All @@ -223,7 +224,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
val = "Object@" + val;
}
} else if (typeof val == "string" && val.startsWith("@0x")) {
ref = variableCreate(getNamespace("*&" + name.substr));
ref = variableCreate(getNamespace("*&" + name.substring(1)));
val = "Ref" + val;
} else if (typeof val == "string" && val.startsWith("<...>")) {
ref = variableCreate(getNamespace(name));
Expand Down
42 changes: 21 additions & 21 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as linuxTerm from '../linux/console';
import * as net from "net";
import * as fs from "fs";
import * as path from "path";
import { Client } from "ssh2";
import { Client, ClientChannel, ExecOptions } from "ssh2";

export function escape(str: string) {
return str.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
Expand All @@ -29,7 +29,7 @@ export class MI2 extends EventEmitter implements IBackend {
super();

if (procEnv) {
const env = {};
const env: { [key: string]: string } = {};
// Duplicate process.env so we don't override it
for (const key in process.env)
if (process.env.hasOwnProperty(key))
Expand Down Expand Up @@ -57,8 +57,8 @@ export class MI2 extends EventEmitter implements IBackend {
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
this.process.stdout.on("data", this.stdout.bind(this));
this.process.stderr.on("data", this.stderr.bind(this));
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
this.process.on("exit", () => this.emit("quit"));
this.process.on("error", err => this.emit("launcherror", err));
const promises = this.initCommands(target, cwd);
if (procArgs && procArgs.length)
promises.push(this.sendCommand("exec-arguments " + procArgs));
Expand Down Expand Up @@ -137,7 +137,7 @@ export class MI2 extends EventEmitter implements IBackend {

this.sshConn.on("ready", () => {
this.log("stdout", "Running " + this.application + " over ssh...");
const execArgs: any = {};
const execArgs: ExecOptions = {};
if (args.forwardX11) {
execArgs.x11 = {
single: false,
Expand All @@ -150,7 +150,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (err) {
this.log("stderr", "Could not run " + this.application + "(" + sshCMD + ") over ssh!");
if (err === undefined) {
err = "<reason unknown>";
err = new Error("<reason unknown>");
}
this.log("stderr", err.toString());
this.emit("quit");
Expand All @@ -161,10 +161,10 @@ export class MI2 extends EventEmitter implements IBackend {
this.stream = stream;
stream.on("data", this.stdout.bind(this));
stream.stderr.on("data", this.stderr.bind(this));
stream.on("exit", (() => {
stream.on("exit", () => {
this.emit("quit");
this.sshConn.end();
}).bind(this));
});
const promises = this.initCommands(target, cwd, attach);
promises.push(this.sendCommand("environment-cd \"" + escape(cwd) + "\""));
if (attach) {
Expand All @@ -181,7 +181,7 @@ export class MI2 extends EventEmitter implements IBackend {
}).on("error", (err) => {
this.log("stderr", "Error running " + this.application + " over ssh!");
if (err === undefined) {
err = "<reason unknown>";
err = new Error("<reason unknown>");
}
this.log("stderr", err.toString());
this.emit("quit");
Expand Down Expand Up @@ -235,8 +235,8 @@ export class MI2 extends EventEmitter implements IBackend {
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
this.process.stdout.on("data", this.stdout.bind(this));
this.process.stderr.on("data", this.stderr.bind(this));
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
this.process.on("exit", () => this.emit("quit"));
this.process.on("error", err => this.emit("launcherror", err));
const promises = this.initCommands(target, cwd, true);
if (target.startsWith("extended-remote")) {
promises.push(this.sendCommand("target-select " + target));
Expand Down Expand Up @@ -267,8 +267,8 @@ export class MI2 extends EventEmitter implements IBackend {
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
this.process.stdout.on("data", this.stdout.bind(this));
this.process.stderr.on("data", this.stderr.bind(this));
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
this.process.on("exit", () => this.emit("quit"));
this.process.on("error", err => this.emit("launcherror", err));
const promises = this.initCommands(target, cwd, true);
promises.push(this.sendCommand("target-select remote " + target));
promises.push(...autorun.map(value => { return this.sendUserInput(value); }));
Expand All @@ -279,7 +279,7 @@ export class MI2 extends EventEmitter implements IBackend {
});
}

stdout(data) {
stdout(data: any) {
if (trace)
this.log("stderr", "stdout: " + data);
if (typeof data == "string")
Expand All @@ -298,7 +298,7 @@ export class MI2 extends EventEmitter implements IBackend {
}
}

stderr(data) {
stderr(data: any) {
if (typeof data == "string")
this.errbuf += data;
else
Expand Down Expand Up @@ -563,7 +563,7 @@ export class MI2 extends EventEmitter implements IBackend {
loadBreakPoints(breakpoints: Breakpoint[]): Thenable<[boolean, Breakpoint][]> {
if (trace)
this.log("stderr", "loadBreakPoints");
const promisses = [];
const promisses: Thenable<[boolean, Breakpoint]>[] = [];
breakpoints.forEach(breakpoint => {
promisses.push(this.addBreakPoint(breakpoint));
});
Expand Down Expand Up @@ -651,7 +651,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (trace)
this.log("stderr", "clearBreakPoints");
return new Promise((resolve, reject) => {
const promises = [];
const promises: Thenable<void | MINode>[] = [];
const breakpoints = this.breakpoints;
this.breakpoints = new Map();
breakpoints.forEach((k, index) => {
Expand Down Expand Up @@ -709,7 +709,7 @@ export class MI2 extends EventEmitter implements IBackend {

const result = await this.sendCommand(["stack-list-frames"].concat(options).join(" "));
const stack = result.result("stack");
return stack.map(element => {
return stack.map((element: any) => {
const level = MINode.valueOf(element, "@frame.level");
const addr = MINode.valueOf(element, "@frame.addr");
const func = MINode.valueOf(element, "@frame.func");
Expand Down Expand Up @@ -856,7 +856,7 @@ export class MI2 extends EventEmitter implements IBackend {
//TODO: add `from` and `to` arguments
const res = await this.sendCommand(`var-list-children --all-values ${this.quote(name)}`);
const children = res.result("children") || [];
const omg: VariableObject[] = children.map(child => new VariableObject(child[1]));
const omg: VariableObject[] = children.map((child: any) => new VariableObject(child[1]));
return omg;
}

Expand Down Expand Up @@ -945,6 +945,6 @@ export class MI2 extends EventEmitter implements IBackend {
protected buffer: string;
protected errbuf: string;
protected process: ChildProcess.ChildProcess;
protected stream;
protected sshConn;
protected stream: ClientChannel;
protected sshConn: Client;
}
4 changes: 2 additions & 2 deletions src/backend/mi2/mi2lldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class MI2_LLDB extends MI2 {
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
this.process.stdout.on("data", this.stdout.bind(this));
this.process.stderr.on("data", this.stderr.bind(this));
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
this.process.on("exit", () => this.emit("quit"));
this.process.on("error", err => this.emit("launcherror", err));
const promises = this.initCommands(target, cwd, true);
promises.push(this.sendCommand("file-exec-and-symbols \"" + escape(executable) + "\""));
promises.push(this.sendCommand("target-attach " + target));
Expand Down
4 changes: 2 additions & 2 deletions src/backend/mi2/mi2mago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export class MI2_Mago extends MI2_LLDB {
this.sendCommand(command).then((result) => {
const stack = result.resultRecords.results;
const ret: Stack[] = [];
const remaining = [];
const addToStack = (element) => {
const remaining: any = [];
const addToStack = (element: any) => {
const level = MINode.valueOf(element, "frame.level");
const addr = MINode.valueOf(element, "frame.addr");
const func = MINode.valueOf(element, "frame.func");
Expand Down
21 changes: 12 additions & 9 deletions src/backend/mi_parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ export function parseMI(output: string): MINode {
*/

let token = undefined;
const outOfBandRecord = [];
const outOfBandRecord: { isStream: boolean, type: string, asyncClass: string, output: [string, any][], content: string }[] = [];
let resultRecords = undefined;

const asyncRecordType = {
"*": "exec",
"+": "status",
"=": "notify"
};
} as const;
const streamRecordType = {
"~": "console",
"@": "target",
"&": "log"
};
} as const;

const parseCString = () => {
if (output[0] != '"')
Expand Down Expand Up @@ -192,7 +192,7 @@ export function parseMI(output: string): MINode {
return str;
};

let parseValue, parseCommaResult, parseCommaValue, parseResult;
let parseValue: () => any, parseCommaResult: () => any, parseCommaValue: () => any, parseResult: () => any;

const parseTupleOrList = () => {
if (output[0] != '{' && output[0] != '[')
Expand Down Expand Up @@ -274,9 +274,10 @@ export function parseMI(output: string): MINode {
output = output.substring(classMatch[0].length);
const asyncRecord = {
isStream: false,
type: asyncRecordType[match[2]],
type: asyncRecordType[match[2] as keyof typeof asyncRecordType],
asyncClass: classMatch[0],
output: []
output: [] as any,
content: ""
};
let result;
while (result = parseCommaResult())
Expand All @@ -285,8 +286,10 @@ export function parseMI(output: string): MINode {
} else if (match[3]) {
const streamRecord = {
isStream: true,
type: streamRecordType[match[3]],
content: parseCString()
type: streamRecordType[match[3] as keyof typeof streamRecordType],
content: parseCString(),
output: [] as [string, any][],
asyncClass: ""
};
outOfBandRecord.push(streamRecord);
}
Expand All @@ -310,5 +313,5 @@ export function parseMI(output: string): MINode {
output = output.replace(newlineRegex, "");
}

return new MINode(token, <any> outOfBandRecord || [], resultRecords);
return new MINode(token, outOfBandRecord || [], resultRecords);
}
Loading

0 comments on commit 1b9f13e

Please sign in to comment.