Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions src/hover-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import type { NodeId } from '@eagleoutice/flowr/r-bridge/lang-4.x/ast/model/processing/node-id';
import { getFlowrSession } from './extension';
import { makeSlicingCriteriaForPositions } from './flowr/utils';
import { Bottom, Top } from '@eagleoutice/flowr/abstract-interpretation/domains/lattice';
import { Bottom, BottomSymbol, Top, TopSymbol } from '@eagleoutice/flowr/abstract-interpretation/domains/lattice';
import { isTop, stringifyValue } from '@eagleoutice/flowr/dataflow/eval/values/r-value';
import { getConfig, Settings } from './settings';
import { ConfigurableRefresher, RefreshType } from './configurable-refresher';
Expand Down Expand Up @@ -116,14 +116,12 @@ class FlowrHoverProvider implements vscode.HoverProvider {
if(shape) {
values.push({
value: shape,
textRep: `Dataframe Shape:
| | |
|----|----|
| Rows: | ${intLift2Str(shape.rows.value)} |
| Cols: | ${intLift2Str(shape.cols.value)} |

Known Columns: ${setString(shape.colnames.value)}
textRep: `
Dataframe Shape:

*Columns*: ${formatSetRange(shape.colnames.value)}\\
*Cols*: ${shape.cols.toString()}\\
*Rows*: ${shape.rows.toString()}
`.trim(),
criteria: criteria
});
Expand All @@ -135,28 +133,27 @@ Known Columns: ${setString(shape.colnames.value)}
}
}

function setString(set: { readonly min: ReadonlySet<string>, readonly range: ReadonlySet<string> | typeof Top } | typeof Top | typeof Bottom): string {
function formatSetRange(set: { readonly min: ReadonlySet<string>, readonly range: ReadonlySet<string> | typeof Top } | typeof Top | typeof Bottom): string {
if(set === Bottom) {
return '⊥';
return BottomSymbol;
} else if(set === Top || (set.min.size === 0 && set.range === Top)) {
return TopSymbol;
}
if(set === Top) {
return '⊤';
let txt: string | undefined;

if(set.min.size === 0) {
txt = '*\\<None\\>*';
} else {
txt = `${set.min.values().toArray().map(entry => '`' + entry + '`').join(', ')}`;
}
let txt = `${[...set.min].map(f => `\`${f}\``).join(', ')}
`;
if(set.range === Top) {
txt += '(Potential: )';
txt += ' (Potential: ' + TopSymbol + ')';
} else if(set.range.size > 0) {
txt += '(Potential: ' + [...set.range].map(f => `\`${f}\``).join(', ') + ')';
txt += ' (Potential: ' + set.range.values().toArray().map(entry => '`' + entry + '`').join(', ') + ')';
}
return txt;
}
function intLift2Str(val: readonly [number, number] | typeof Bottom): string {
if(val === Bottom) {
return '⊥';
}
return `[${val[0]}, ${val[1]}]`;
}

function valueToHint(cached: ValueInfo[]): vscode.Hover | undefined {
if(cached.length === 0) {
return undefined;
Expand Down
12 changes: 6 additions & 6 deletions src/test/hover-values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ suite('hover values', () => {
});

test('shows inferred value for dataframe', async() => {
const df = `Dataframe Shape:
| | |
|----|----|
| Rows: | [3, 3] |
| Cols: | [2, 2] |
const df = `
Dataframe Shape:

Known Columns: \`id\`, \`label\``;
*Columns*: \`id\`, \`label\`\\
*Cols*: [2, 2]\\
*Rows*: [3, 3]
`.trim();
await tc(new vscode.Position(2, 1), df);
});
});
Expand Down
Loading