Skip to content
Snippets Groups Projects
Commit 5b8a2ae1 authored by Michele Alberti's avatar Michele Alberti
Browse files

[ivette] Update ASTview to marker API changes.

parent bf91559d
No related branches found
No related tags found
No related merge requests found
...@@ -43,10 +43,6 @@ export const compute: Server.ExecRequest<null,null>= compute_internal; ...@@ -43,10 +43,6 @@ export const compute: Server.ExecRequest<null,null>= compute_internal;
/** Marker kind */ /** Marker kind */
export enum markerKind { export enum markerKind {
/** Variable */
variable = 'variable',
/** Function */
function = 'function',
/** Expression */ /** Expression */
expression = 'expression', expression = 'expression',
/** Lvalue */ /** Lvalue */
...@@ -83,12 +79,44 @@ const markerKindTags_internal: Server.GetRequest<null,tag[]> = { ...@@ -83,12 +79,44 @@ const markerKindTags_internal: Server.GetRequest<null,tag[]> = {
/** Registered tags for the above type. */ /** Registered tags for the above type. */
export const markerKindTags: Server.GetRequest<null,tag[]>= markerKindTags_internal; export const markerKindTags: Server.GetRequest<null,tag[]>= markerKindTags_internal;
/** Marker variable */
export enum markerVar {
/** None */
none = 'none',
/** Variable */
variable = 'variable',
/** Function */
function = 'function',
}
/** Loose decoder for `markerVar` */
export const jMarkerVar: Json.Loose<markerVar> = Json.jEnum(markerVar);
/** Safe decoder for `markerVar` */
export const jMarkerVarSafe: Json.Safe<markerVar> =
Json.jFail(Json.jEnum(markerVar),'kernel.ast.markerVar expected');
/** Natural order for `markerVar` */
export const byMarkerVar: Compare.Order<markerVar> =
Compare.byEnum(markerVar);
const markerVarTags_internal: Server.GetRequest<null,tag[]> = {
kind: Server.RqKind.GET,
name: 'kernel.ast.markerVarTags',
input: Json.jNull,
output: Json.jList(jTag),
};
/** Registered tags for the above type. */
export const markerVarTags: Server.GetRequest<null,tag[]>= markerVarTags_internal;
/** Data for array rows [`markerInfo`](#markerinfo) */ /** Data for array rows [`markerInfo`](#markerinfo) */
export interface markerInfoData { export interface markerInfoData {
/** Entry identifier. */ /** Entry identifier. */
key: Json.key<'#markerInfo'>; key: Json.key<'#markerInfo'>;
/** Marker kind */ /** Marker kind */
kind: markerKind; kind: markerKind;
/** Marker variable */
var: markerVar;
/** Marker short name */ /** Marker short name */
name: string; name: string;
/** Marker declaration or description */ /** Marker declaration or description */
...@@ -101,6 +129,7 @@ export const jMarkerInfoData: Json.Loose<markerInfoData> = ...@@ -101,6 +129,7 @@ export const jMarkerInfoData: Json.Loose<markerInfoData> =
key: Json.jFail(Json.jKey<'#markerInfo'>('#markerInfo'), key: Json.jFail(Json.jKey<'#markerInfo'>('#markerInfo'),
'#markerInfo expected'), '#markerInfo expected'),
kind: jMarkerKindSafe, kind: jMarkerKindSafe,
var: jMarkerVarSafe,
name: Json.jFail(Json.jString,'String expected'), name: Json.jFail(Json.jString,'String expected'),
descr: Json.jFail(Json.jString,'String expected'), descr: Json.jFail(Json.jString,'String expected'),
}); });
...@@ -112,10 +141,11 @@ export const jMarkerInfoDataSafe: Json.Safe<markerInfoData> = ...@@ -112,10 +141,11 @@ export const jMarkerInfoDataSafe: Json.Safe<markerInfoData> =
/** Natural order for `markerInfoData` */ /** Natural order for `markerInfoData` */
export const byMarkerInfoData: Compare.Order<markerInfoData> = export const byMarkerInfoData: Compare.Order<markerInfoData> =
Compare.byFields Compare.byFields
<{ key: Json.key<'#markerInfo'>, kind: markerKind, name: string, <{ key: Json.key<'#markerInfo'>, kind: markerKind, var: markerVar,
descr: string }>({ name: string, descr: string }>({
key: Compare.string, key: Compare.string,
kind: byMarkerKind, kind: byMarkerKind,
var: byMarkerVar,
name: Compare.alpha, name: Compare.alpha,
descr: Compare.string, descr: Compare.string,
}); });
......
...@@ -133,18 +133,8 @@ const ASTview = () => { ...@@ -133,18 +133,8 @@ const ASTview = () => {
async function onContextMenu(id: key<'#markerInfo'>) { async function onContextMenu(id: key<'#markerInfo'>) {
const items = []; const items = [];
const selectedMarkerInfo = markersInfo.find((e) => e.key === id); const selectedMarkerInfo = markersInfo.find((e) => e.key === id);
switch (selectedMarkerInfo?.kind) { if (selectedMarkerInfo?.var === 'function') {
case 'function': { if (selectedMarkerInfo.kind === 'declaration') {
items.push({
label: `Go to definition of ${selectedMarkerInfo.name}`,
onClick: () => {
const location = { function: selectedMarkerInfo.name };
updateSelection({ location });
},
});
break;
}
case 'declaration': {
if (selectedMarkerInfo?.name) { if (selectedMarkerInfo?.name) {
const locations = await functionCallers(selectedMarkerInfo.name); const locations = await functionCallers(selectedMarkerInfo.name);
const locationsByFunction = _.groupBy(locations, (e) => e.function); const locationsByFunction = _.groupBy(locations, (e) => e.function);
...@@ -162,10 +152,15 @@ const ASTview = () => { ...@@ -162,10 +152,15 @@ const ASTview = () => {
}); });
}); });
} }
break; } else {
items.push({
label: `Go to definition of ${selectedMarkerInfo.name}`,
onClick: () => {
const location = { function: selectedMarkerInfo.name };
updateSelection({ location });
},
});
} }
default:
break;
} }
if (items.length > 0) if (items.length > 0)
Dome.popupMenu(items); Dome.popupMenu(items);
......
...@@ -52,8 +52,6 @@ module MarkerKind = struct ...@@ -52,8 +52,6 @@ module MarkerKind = struct
~descr:(Md.plain (String.capitalize_ascii name)) ~descr:(Md.plain (String.capitalize_ascii name))
kinds kinds
let var = kind "variable"
let fct = kind "function"
let expr = kind "expression" let expr = kind "expression"
let lval = kind "lvalue" let lval = kind "lvalue"
let decl = kind "declaration" let decl = kind "declaration"
......
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