Skip to content

Commit ccd15c4

Browse files
committed
updates from review
1 parent b6bbe5c commit ccd15c4

File tree

7 files changed

+78
-59
lines changed

7 files changed

+78
-59
lines changed

extensions/positron-python/python_files/posit/positron/data_explorer_comm.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ class ConvertedCode(BaseModel):
258258
"""
259259

260260
converted_code: List[StrictStr] = Field(
261-
description="Lines of code translating filters and sort keys",
261+
description="Lines of code that implement filters and sort keys",
262262
)
263263

264264

265265
class CodeSyntaxName(BaseModel):
266266
"""
267-
Suggestion of syntax to use for code translation
267+
Syntax to use for code conversion
268268
"""
269269

270-
code_syntax_name: StrictStr = Field(
271-
description="The syntax for converted code",
270+
code_syntax_name: CodeSyntaxName = Field(
271+
description="The name of the code syntax, eg, pandas, polars, dplyr, etc.",
272272
)
273273

274274

@@ -992,8 +992,8 @@ class SupportedFeatures(BaseModel):
992992
description="Support for 'export_data_selection' RPC and its features",
993993
)
994994

995-
code_syntaxes: CodeSyntaxFeatures = Field(
996-
description="Support for converting data selections to code",
995+
convert_to_code: ConvertToCodeFeatures = Field(
996+
description="Support for 'convert_to_code' RPC and its features",
997997
)
998998

999999

@@ -1081,16 +1081,16 @@ class SetSortColumnsFeatures(BaseModel):
10811081
)
10821082

10831083

1084-
class CodeSyntaxFeatures(BaseModel):
1084+
class ConvertToCodeFeatures(BaseModel):
10851085
"""
1086-
A list of supported code syntax names for exporting data selections
1086+
Feature flags for convert to code RPC
10871087
"""
10881088

10891089
support_status: SupportStatus = Field(
10901090
description="The support status for this RPC method",
10911091
)
10921092

1093-
code_syntaxes: Optional[List[StrictStr]] = Field(
1093+
code_syntaxes: Optional[List[CodeSyntaxName]] = Field(
10941094
default=None,
10951095
description="The syntaxes for converted code",
10961096
)
@@ -1485,8 +1485,8 @@ class ConvertToCodeParams(BaseModel):
14851485
description="Zero or more sort keys to apply",
14861486
)
14871487

1488-
code_syntax_name: StrictStr = Field(
1489-
description="The code syntax to use for translation",
1488+
code_syntax_name: CodeSyntaxName = Field(
1489+
description="The code syntax to use for conversion",
14901490
)
14911491

14921492

@@ -1815,7 +1815,7 @@ class ReturnColumnProfilesParams(BaseModel):
18151815

18161816
SetSortColumnsFeatures.update_forward_refs()
18171817

1818-
CodeSyntaxFeatures.update_forward_refs()
1818+
ConvertToCodeFeatures.update_forward_refs()
18191819

18201820
TableSelection.update_forward_refs()
18211821

positron/comms/data_explorer-backend-openrpc.json

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
}
216216
}
217217
},
218-
{
218+
{
219219
"name": "convert_to_code",
220220
"summary": "Converts the current data view into a code snippet.",
221221
"description": "Converts filters and sort keys as code in different syntaxes like pandas, polars, data.table, dplyr",
@@ -255,14 +255,14 @@
255255
},
256256
{
257257
"name": "code_syntax_name",
258-
"description": "The code syntax to use for translation",
258+
"description": "The code syntax to use for conversion",
259259
"required": true,
260260
"schema": {
261-
"type": "string",
262-
"description": "The syntax for converted code"
261+
"$ref": "#/components/schemas/code_syntax_name",
262+
"description": "The name of the code syntax, eg, pandas, polars, dplyr, etc."
263263
}
264264
}
265-
],
265+
],
266266
"result": {
267267
"schema": {
268268
"name": "converted_code",
@@ -274,7 +274,7 @@
274274
"properties": {
275275
"converted_code": {
276276
"type": "array",
277-
"description": "Lines of code translating filters and sort keys",
277+
"description": "Lines of code that implement filters and sort keys",
278278
"items": {
279279
"type": "string"
280280
}
@@ -283,7 +283,7 @@
283283
}
284284
}
285285
},
286-
{
286+
{
287287
"name": "suggest_code_syntax",
288288
"summary": "Suggest code syntax for code conversion",
289289
"description": "Suggest code syntax for code conversion based on the current backend state",
@@ -292,14 +292,14 @@
292292
"schema": {
293293
"name": "code_syntax_name",
294294
"type": "object",
295-
"description": "Suggestion of syntax to use for code translation",
295+
"description": "Syntax to use for code conversion",
296296
"required": [
297297
"code_syntax_name"
298298
],
299299
"properties": {
300300
"code_syntax_name": {
301-
"type": "string",
302-
"description": "The syntax for converted code"
301+
"$ref": "#/components/schemas/code_syntax_name",
302+
"description": "The name of the code syntax, eg, pandas, polars, dplyr, etc."
303303
}
304304
}
305305
}
@@ -1393,8 +1393,7 @@
13931393
"get_column_profiles",
13941394
"set_sort_columns",
13951395
"export_data_selection",
1396-
"export_as_code",
1397-
"code_syntaxes"
1396+
"convert_to_code"
13981397
],
13991398
"properties": {
14001399
"search_schema": {
@@ -1421,9 +1420,9 @@
14211420
"description": "Support for 'export_data_selection' RPC and its features",
14221421
"$ref": "#/components/schemas/export_data_selection_features"
14231422
},
1424-
"code_syntaxes": {
1425-
"description": "Support for converting data selections to code",
1426-
"$ref": "#/components/schemas/code_syntax_features"
1423+
"convert_to_code": {
1424+
"description": "Support for 'convert_to_code' RPC and its features",
1425+
"$ref": "#/components/schemas/convert_to_code_features"
14271426
}
14281427
}
14291428
},
@@ -1550,9 +1549,9 @@
15501549
}
15511550
}
15521551
},
1553-
"code_syntax_features": {
1552+
"convert_to_code_features": {
15541553
"type": "object",
1555-
"description": "A list of supported code syntax names for exporting data selections",
1554+
"description": "Feature flags for convert to code RPC",
15561555
"required": [
15571556
"support_status"
15581557
],
@@ -1565,12 +1564,16 @@
15651564
"type": "array",
15661565
"description": "The syntaxes for converted code",
15671566
"items": {
1568-
"type": "string",
1569-
"description": "The syntaxes for converted code"
1567+
"$ref": "#/components/schemas/code_syntax_name",
1568+
"description": "The name of the code syntax, eg, pandas, polars, dplyr, etc."
15701569
}
15711570
}
15721571
}
15731572
},
1573+
"code_syntax_name": {
1574+
"type": "string",
1575+
"description": "The name of the code syntax, eg, pandas, polars, dplyr, etc."
1576+
},
15741577
"table_selection": {
15751578
"type": "object",
15761579
"description": "A selection on the data grid, for copying to the clipboard or other actions",

src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface IDataExplorerBackendClient extends Disposable {
6767
getRowLabels(selection: ArraySelection, formatOptions: FormatOptions): Promise<TableRowLabels>;
6868
exportDataSelection(selection: TableSelection, format: ExportFormat): Promise<ExportedData>;
6969
suggestCodeSyntax(): Promise<CodeSyntaxName | undefined>;
70-
convertToCode(columnFilters: Array<ColumnFilter>, rowFilters: Array<RowFilter>, sortKeys: Array<ColumnSortKey>, exportOptions: string): Promise<ConvertedCode>;
70+
convertToCode(columnFilters: Array<ColumnFilter>, rowFilters: Array<RowFilter>, sortKeys: Array<ColumnSortKey>, codeSyntax: CodeSyntaxName): Promise<ConvertedCode>;
7171
setColumnFilters(filters: Array<ColumnFilter>): Promise<void>;
7272
setRowFilters(filters: Array<RowFilter>): Promise<FilterResult>;
7373
setSortColumns(sortKeys: Array<ColumnSortKey>): Promise<void>;
@@ -105,7 +105,7 @@ export const DATA_EXPLORER_DISCONNECTED_STATE: BackendState = {
105105
support_status: SupportStatus.Unsupported,
106106
supported_formats: []
107107
},
108-
code_syntaxes: {
108+
convert_to_code: {
109109
support_status: SupportStatus.Unsupported
110110
}
111111
}
@@ -517,7 +517,7 @@ export class DataExplorerClientInstance extends Disposable {
517517
* @param desiredSyntax The desired syntax for the code conversion.
518518
* @returns A promise that resolves to the converted code.
519519
*/
520-
async convertToCode(desiredSyntax: string): Promise<ConvertedCode> {
520+
async convertToCode(desiredSyntax: CodeSyntaxName): Promise<ConvertedCode> {
521521
const state = await this.getBackendState();
522522
await this.isSyntaxSupported(desiredSyntax, state);
523523

@@ -536,7 +536,7 @@ export class DataExplorerClientInstance extends Disposable {
536536
* @returns A promise that resolves to the available code syntaxes.
537537
*/
538538
async suggestCodeSyntax(): Promise<CodeSyntaxName | undefined> {
539-
await this.isSyntaxSupported();
539+
await this.isConvertToCodeSupported();
540540
return await this.runBackendTask(
541541
() => this._backendClient.suggestCodeSyntax(),
542542
() => undefined
@@ -548,15 +548,29 @@ export class DataExplorerClientInstance extends Disposable {
548548

549549
//#region Private Methods
550550

551-
private async isSyntaxSupported(syntax?: string, backendState?: BackendState): Promise<void> {
551+
/**
552+
* Checks if the convert to code feature is supported by the backend.
553+
* @param backendState The backend state to check.
554+
* @throws An error if the feature is not supported.
555+
*/
556+
private async isConvertToCodeSupported(backendState?: BackendState): Promise<void> {
552557
const state = backendState || await this.getBackendState();
553-
const supportedSyntaxes = state.supported_features.code_syntaxes.code_syntaxes;
554558

555-
if (state.supported_features.code_syntaxes.support_status === SupportStatus.Unsupported) {
559+
if (state.supported_features.convert_to_code.support_status === SupportStatus.Unsupported) {
556560
throw new Error('Code syntax conversion is not supported by the backend.');
557561
}
562+
}
563+
564+
/**
565+
* Checks if the given code syntax is supported by the backend.
566+
* @param syntax The code syntax to check.
567+
* @param backendState The backend state to check.
568+
* @throws An error if the syntax is not supported.
569+
*/
570+
private async isSyntaxSupported(syntax: CodeSyntaxName, backendState: BackendState): Promise<void> {
571+
await this.isConvertToCodeSupported(backendState);
558572

559-
if (syntax && !supportedSyntaxes?.includes(syntax)) {
573+
if (syntax && !backendState.supported_features.convert_to_code.code_syntaxes?.some(s => s.code_syntax_name === syntax)) {
560574
throw new Error(`Code syntax "${syntax}" is not supported by the backend.`);
561575
}
562576
}

src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ export interface ExportedData {
5959
*/
6060
export interface ConvertedCode {
6161
/**
62-
* Lines of code translating filters and sort keys
62+
* Lines of code that implement filters and sort keys
6363
*/
6464
converted_code: Array<string>;
6565

6666
}
6767

6868
/**
69-
* Suggestion of syntax to use for code translation
69+
* Syntax to use for code conversion
7070
*/
7171
export interface CodeSyntaxName {
7272
/**
73-
* The syntax for converted code
73+
* The name of the code syntax, eg, pandas, polars, dplyr, etc.
7474
*/
75-
code_syntax_name: string;
75+
code_syntax_name: CodeSyntaxName;
7676

7777
}
7878

@@ -879,9 +879,9 @@ export interface SupportedFeatures {
879879
export_data_selection: ExportDataSelectionFeatures;
880880

881881
/**
882-
* Support for converting data selections to code
882+
* Support for 'convert_to_code' RPC and its features
883883
*/
884-
code_syntaxes: CodeSyntaxFeatures;
884+
convert_to_code: ConvertToCodeFeatures;
885885

886886
}
887887

@@ -982,9 +982,9 @@ export interface SetSortColumnsFeatures {
982982
}
983983

984984
/**
985-
* A list of supported code syntax names for exporting data selections
985+
* Feature flags for convert to code RPC
986986
*/
987-
export interface CodeSyntaxFeatures {
987+
export interface ConvertToCodeFeatures {
988988
/**
989989
* The support status for this RPC method
990990
*/
@@ -993,7 +993,7 @@ export interface CodeSyntaxFeatures {
993993
/**
994994
* The syntaxes for converted code
995995
*/
996-
code_syntaxes?: Array<string>;
996+
code_syntaxes?: Array<CodeSyntaxName>;
997997

998998
}
999999

@@ -1349,9 +1349,9 @@ export interface ConvertToCodeParams {
13491349
sort_keys: Array<ColumnSortKey>;
13501350

13511351
/**
1352-
* The code syntax to use for translation
1352+
* The code syntax to use for conversion
13531353
*/
1354-
code_syntax_name: string;
1354+
code_syntax_name: CodeSyntaxName;
13551355
}
13561356

13571357
/**
@@ -1589,11 +1589,11 @@ export class PositronDataExplorerComm extends PositronBaseComm {
15891589
* @param columnFilters Zero or more column filters to apply
15901590
* @param rowFilters Zero or more row filters to apply
15911591
* @param sortKeys Zero or more sort keys to apply
1592-
* @param codeSyntaxName The code syntax to use for translation
1592+
* @param codeSyntaxName The code syntax to use for conversion
15931593
*
15941594
* @returns Code snippet for the data view
15951595
*/
1596-
convertToCode(columnFilters: Array<ColumnFilter>, rowFilters: Array<RowFilter>, sortKeys: Array<ColumnSortKey>, codeSyntaxName: string): Promise<ConvertedCode> {
1596+
convertToCode(columnFilters: Array<ColumnFilter>, rowFilters: Array<RowFilter>, sortKeys: Array<ColumnSortKey>, codeSyntaxName: CodeSyntaxName): Promise<ConvertedCode> {
15971597
return super.performRpc('convert_to_code', ['column_filters', 'row_filters', 'sort_keys', 'code_syntax_name'], [columnFilters, rowFilters, sortKeys, codeSyntaxName]);
15981598
}
15991599

@@ -1604,7 +1604,7 @@ export class PositronDataExplorerComm extends PositronBaseComm {
16041604
* state
16051605
*
16061606
*
1607-
* @returns Suggestion of syntax to use for code translation
1607+
* @returns Syntax to use for code conversion
16081608
*/
16091609
suggestCodeSyntax(): Promise<CodeSyntaxName> {
16101610
return super.performRpc('suggest_code_syntax', [], []);

src/vs/workbench/services/positronDataExplorer/browser/interfaces/positronDataExplorerInstance.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TableDataDataGridInstance } from '../tableDataDataGridInstance.js';
99
import { DataExplorerClientInstance } from '../../../languageRuntime/common/languageRuntimeDataExplorerClient.js';
1010
import { TableSummaryDataGridInstance } from '../tableSummaryDataGridInstance.js';
1111
import { PositronDataExplorerLayout } from './positronDataExplorerService.js';
12+
import { CodeSyntaxName } from '../../../languageRuntime/common/positronDataExplorerComm.js';
1213

1314
/**
1415
* IPositronDataExplorerInstance interface.
@@ -121,7 +122,7 @@ export interface IPositronDataExplorerInstance extends IDisposable {
121122
copyTableDataToClipboard(): Promise<void>;
122123

123124
/**
124-
* Translates the current data view's filters and sorts to code in the desired syntax.
125+
* Converts the current data view's filters and sorts to code in the desired syntax.
125126
*/
126-
convertToCode(desiredSyntax: string): Promise<string | undefined>;
127+
convertToCode(desiredSyntax: CodeSyntaxName): Promise<string | undefined>;
127128
}

src/vs/workbench/services/positronDataExplorer/browser/positronDataExplorerInstance.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { PositronDataExplorerLayout } from './interfaces/positronDataExplorerSer
2424
import { IPositronDataExplorerInstance } from './interfaces/positronDataExplorerInstance.js';
2525
import { ClipboardCell, ClipboardCellRange, ClipboardColumnIndexes, ClipboardColumnRange, ClipboardRowIndexes, ClipboardRowRange } from '../../../browser/positronDataGrid/classes/dataGridInstance.js';
2626
import { DataExplorerSummaryCollapseEnabled, DefaultDataExplorerSummaryLayout } from './positronDataExplorerSummary.js';
27+
import { CodeSyntaxName } from '../../languageRuntime/common/positronDataExplorerComm.js';
2728

2829
/**
2930
* Constants.
@@ -431,10 +432,10 @@ export class PositronDataExplorerInstance extends Disposable implements IPositro
431432
}
432433

433434
/**
434-
* Translates the data explorer view to code in the desired syntax.
435-
* @returns A Promise<string> that resolves when generated code is returned.
435+
* Converts the data explorer view to code in the desired syntax.
436+
* @returns A Promise<string> that resolves when converted code is returned.
436437
*/
437-
async convertToCode(desiredSyntax: string): Promise<string | undefined> {
438+
async convertToCode(desiredSyntax: CodeSyntaxName): Promise<string | undefined> {
438439
const generatedCode = await this._dataExplorerClientInstance.convertToCode(desiredSyntax);
439440
return generatedCode.converted_code.join('\n');
440441
}

0 commit comments

Comments
 (0)