Skip to content
Snippets Groups Projects
Commit adad18dc authored by Valentin Perrelle's avatar Valentin Perrelle
Browse files

[ivette] Add more type annotations

parent 0cf43a29
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ export abstract class Client { ...@@ -39,7 +39,7 @@ export abstract class Client {
abstract disconnect(): void; abstract disconnect(): void;
/** Send Request */ /** Send Request */
abstract send(kind: string, id: string, request: string, data: any): void; abstract send(kind: string, id: string, request: string, data: json): void;
/** Signal ON */ /** Signal ON */
abstract sigOn(id: string): void; abstract sigOn(id: string): void;
......
...@@ -95,7 +95,7 @@ class SocketClient extends Client { ...@@ -95,7 +95,7 @@ class SocketClient extends Client {
} }
/** Send Request */ /** Send Request */
send(kind: string, id: string, request: string, data: any): void { send(kind: string, id: string, request: string, data: json): void {
this.queue.push({ cmd: kind, id, request, data }); this.queue.push({ cmd: kind, id, request, data });
this._flush(); this._flush();
} }
...@@ -181,6 +181,7 @@ class SocketClient extends Client { ...@@ -181,6 +181,7 @@ class SocketClient extends Client {
const n1 = this.buffer.length; const n1 = this.buffer.length;
if (data === undefined || n0 <= n1) break; if (data === undefined || n0 <= n1) break;
try { try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const cmd: any = JSON.parse(data); const cmd: any = JSON.parse(data);
if (cmd !== null && typeof (cmd) === 'object') { if (cmd !== null && typeof (cmd) === 'object') {
switch (cmd.res) { switch (cmd.res) {
......
...@@ -62,7 +62,7 @@ class ZmqClient extends Client { ...@@ -62,7 +62,7 @@ class ZmqClient extends Client {
} }
/** Send Request */ /** Send Request */
send(kind: string, id: string, request: string, data: any): void { send(kind: string, id: string, request: string, data: string): void {
if (this.zmqSocket) { if (this.zmqSocket) {
this.queue.push(kind, id, request, data); this.queue.push(kind, id, request, data);
this._flush(); this._flush();
......
...@@ -280,7 +280,7 @@ function MessageFilter(props: { filter: State<Filter> }) { ...@@ -280,7 +280,7 @@ function MessageFilter(props: { filter: State<Filter> }) {
); );
} }
function FilterRatio({ model }: { model: Arrays.ArrayModel<any, any> }) { function FilterRatio<K, R>({ model }: { model: Arrays.ArrayModel<K, R> }) {
const [filtered, total] = [model.getRowCount(), model.getTotalRowCount()]; const [filtered, total] = [model.getRowCount(), model.getTotalRowCount()];
const title = `${filtered} displayed messages / ${total} total messages`; const title = `${filtered} displayed messages / ${total} total messages`;
return ( return (
......
...@@ -56,8 +56,8 @@ interface Cxtcommand { ...@@ -56,8 +56,8 @@ interface Cxtcommand {
} }
interface CytoscapeExtended extends Cytoscape.Core { interface CytoscapeExtended extends Cytoscape.Core {
cxtmenu(options: any): void; cxtmenu(options: unknown): void;
panzoom(options: any): void; panzoom(options: unknown): void;
} }
function callstackToString(callstack: API.callstack): string { function callstackToString(callstack: API.callstack): string {
...@@ -217,9 +217,12 @@ class Dive { ...@@ -217,9 +217,12 @@ class Dive {
trigger: 'manual', trigger: 'manual',
appendTo: document.body, appendTo: document.body,
lazy: false, lazy: false,
// Cytoscape extensions are not typed yet
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onCreate: (instance: any) => { onCreate: (instance: any) => {
const { popperInstance } = instance; const { popperInstance } = instance;
if (popperInstance) { if (popperInstance) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
popperInstance.reference = (node as any).popperRef(); popperInstance.reference = (node as any).popperRef();
} }
}, },
...@@ -272,14 +275,15 @@ class Dive { ...@@ -272,14 +275,15 @@ class Dive {
} }
/* eslint-disable no-restricted-syntax */ /* eslint-disable no-restricted-syntax */
receiveGraph(data: any): Cytoscape.CollectionReturnValue { receiveGraph(data: API.graphData): Cytoscape.CollectionReturnValue {
let newNodes = this.cy.collection(); let newNodes = this.cy.collection();
for (const node of data.nodes) { for (const node of data.nodes) {
let stops = undefined
if (typeof node.range === 'number') if (typeof node.range === 'number')
node.stops = `0% ${node.range}% ${node.range}% 100%`; stops = `0% ${node.range}% ${node.range}% 100%`;
let ele = this.cy.$id(node.id); let ele = this.cy.$id(node.id.toString());
if (ele.nonempty()) { if (ele.nonempty()) {
ele.removeData(); ele.removeData();
ele.data(node); ele.data(node);
...@@ -294,7 +298,7 @@ class Dive { ...@@ -294,7 +298,7 @@ class Dive {
ele = this.cy.add({ ele = this.cy.add({
group: 'nodes', group: 'nodes',
data: { ...node, parent }, data: { ...(node as { [k: string]: unknown }), stops, parent },
classes: 'new', classes: 'new',
}); });
this.addTips(ele); this.addTips(ele);
...@@ -320,10 +324,14 @@ class Dive { ...@@ -320,10 +324,14 @@ class Dive {
} }
for (const dep of data.deps) { for (const dep of data.deps) {
const src = this.cy.$id(dep.src); const src = this.cy.$id(dep.src.toString());
const dst = this.cy.$id(dep.dst); const dst = this.cy.$id(dep.dst.toString());
this.cy.add({ this.cy.add({
data: { ...dep, source: dep.src, target: dep.dst }, data: {
...(dep as { [k: string]: unknown }),
source: dep.src,
target: dep.dst
},
group: 'edges', group: 'edges',
classes: src?.hasClass('new') || dst?.hasClass('new') ? 'new' : '', classes: src?.hasClass('new') || dst?.hasClass('new') ? 'new' : '',
}); });
...@@ -332,11 +340,11 @@ class Dive { ...@@ -332,11 +340,11 @@ class Dive {
return newNodes; return newNodes;
} }
receiveData(data: any): Cytoscape.NodeSingular { receiveData(data: API.diffData): Cytoscape.NodeSingular | undefined {
this.cy.startBatch(); this.cy.startBatch();
for (const id of data.sub) for (const id of data.sub)
this.remove(this.cy.$id(id)); this.remove(this.cy.$id(id.toString()));
const newNodes = this.receiveGraph(data.add); const newNodes = this.receiveGraph(data.add);
...@@ -344,7 +352,8 @@ class Dive { ...@@ -344,7 +352,8 @@ class Dive {
this.recomputeLayout(newNodes); this.recomputeLayout(newNodes);
return this.cy.$id(data.root); const root = data.root
return root ? this.cy.$id(root.toString()) : undefined;
} }
get layout(): string { get layout(): string {
...@@ -383,8 +392,8 @@ class Dive { ...@@ -383,8 +392,8 @@ class Dive {
} }
} }
async exec<In, Out>( async exec<In>(
request: Server.ExecRequest<In, Out>, request: Server.ExecRequest<In, API.diffData | null>,
param: In, param: In,
) { ) {
try { try {
...@@ -417,7 +426,7 @@ class Dive { ...@@ -417,7 +426,7 @@ class Dive {
} }
} }
static async setWindow(window: any): Promise<void> { static async setWindow(window: API.explorationWindow): Promise<void> {
if (Server.isRunning()) if (Server.isRunning())
await Server.send(API.window, window); await Server.send(API.window, window);
} }
...@@ -433,7 +442,7 @@ class Dive { ...@@ -433,7 +442,7 @@ class Dive {
case 'overview': case 'overview':
await Dive.setWindow({ await Dive.setWindow({
perception: { backward: 4, forward: 1 }, perception: { backward: 4, forward: 1 },
horizon: { backward: null, forward: null }, horizon: { backward: undefined, forward: undefined },
}); });
break; break;
default: /* This is useless and impossible if the program is correctly default: /* This is useless and impossible if the program is correctly
......
...@@ -336,7 +336,7 @@ export function clear() { ...@@ -336,7 +336,7 @@ export function clear() {
/** Server configuration. */ /** Server configuration. */
export interface Configuration { export interface Configuration {
/** Process environment variables (default: `undefined`). */ /** Process environment variables (default: `undefined`). */
env?: any; env?: { [VAR: string]: string };
/** Working directory (default: current). */ /** Working directory (default: current). */
cwd?: string; cwd?: string;
/** Server command (default: `frama-c`). */ /** Server command (default: `frama-c`). */
...@@ -694,12 +694,15 @@ export function send<In, Out>( ...@@ -694,12 +694,15 @@ export function send<In, Out>(
const response: Response<Out> = new Promise<Out>((resolve, reject) => { const response: Response<Out> = new Promise<Out>((resolve, reject) => {
const unwrap = (js: Json.json) => { const unwrap = (js: Json.json) => {
const data = request.output(js); const data = request.output(js);
resolve(data as unknown as Out); if (data)
resolve(data);
else
reject('Wrong response type')
}; };
pending.set(rid, { resolve: unwrap, reject }); pending.set(rid, { resolve: unwrap, reject });
}); });
response.kill = () => pending.get(rid)?.reject(); response.kill = () => pending.get(rid)?.reject();
client.send(request.kind, rid, request.name, param); client.send(request.kind, rid, request.name, param as unknown as Json.json);
if (!pollingTimer) { if (!pollingTimer) {
const polling = (config && config.polling) || pollingTimeout; const polling = (config && config.polling) || pollingTimeout;
pollingTimer = setInterval(() => { pollingTimer = setInterval(() => {
......
...@@ -327,11 +327,11 @@ class SyncState<A> { ...@@ -327,11 +327,11 @@ class SyncState<A> {
// --- Synchronized States Registry // --- Synchronized States Registry
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const syncStates = new Map<string, SyncState<any>>(); const syncStates = new Map<string, SyncState<unknown>>();
function getSyncState<A>(h: Handler<A>): SyncState<A> { function getSyncState<A>(h: Handler<A>): SyncState<A> {
const id = `${currentProject}@${h.name}`; const id = `${currentProject}@${h.name}`;
let s = syncStates.get(id); let s = syncStates.get(id) as SyncState<A> | undefined;
if (!s) { if (!s) {
s = new SyncState(h); s = new SyncState(h);
syncStates.set(id, s); syncStates.set(id, s);
...@@ -440,16 +440,16 @@ class SyncArray<K, A> { ...@@ -440,16 +440,16 @@ class SyncArray<K, A> {
// --- Synchronized Arrays Registry // --- Synchronized Arrays Registry
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const syncArrays = new Map<string, SyncArray<any, any>>(); const syncArrays = new Map<string, SyncArray<unknown, unknown>>();
function lookupSyncArray<K, A>( function lookupSyncArray<K, A>(
array: Array<K, A>, array: Array<K, A>,
): SyncArray<K, A> { ): SyncArray<K, A> {
const id = `${currentProject}@${array.name}`; const id = `${currentProject}@${array.name}`;
let st = syncArrays.get(id); let st = syncArrays.get(id) as SyncArray<K,A> | undefined;
if (!st) { if (!st) {
st = new SyncArray(array); st = new SyncArray(array);
syncArrays.set(id, st); syncArrays.set(id, st as SyncArray<unknown, unknown>);
} }
return st; return st;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment