Skip to content

Commit 058264b

Browse files
committed
fix: move configs to api
1 parent 341eb3f commit 058264b

File tree

5 files changed

+66
-39
lines changed

5 files changed

+66
-39
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@hookform/resolvers": "^3.10.0",
2929
"@reduxjs/toolkit": "^2.5.0",
3030
"@tanstack/react-table": "^8.20.6",
31-
"@ydb-platform/monaco-ghost": "^0.3.0",
31+
"@ydb-platform/monaco-ghost": "^0.4.0",
3232
"axios": "^1.7.9",
3333
"axios-retry": "^4.5.0",
3434
"colord": "^2.9.3",

src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export function YqlEditor({
8181
onCompletionDecline: codeAssist.onCompletionDecline,
8282
onCompletionIgnore: codeAssist.onCompletionIgnore,
8383
},
84-
config: codeAssist.config,
84+
config: {
85+
language: YQL_LANGUAGE_ID,
86+
},
8587
});
8688

8789
const editorDidMount = (editor: Monaco.editor.IStandaloneCodeEditor, monaco: typeof Monaco) => {

src/containers/Tenant/Query/QueryEditor/helpers.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import {codeAssistApi} from '../../../../store/reducers/codeAssist/codeAssist';
77
import type {TelemetryOpenTabs} from '../../../../types/api/codeAssist';
88
import {AUTOCOMPLETE_ON_ENTER, ENABLE_AUTOCOMPLETE} from '../../../../utils/constants';
99
import {useSetting} from '../../../../utils/hooks';
10-
import {YQL_LANGUAGE_ID} from '../../../../utils/monaco/constats';
11-
12-
const limitForTab = 10_000;
13-
const limitBeforeCursor = 8_000;
14-
const limitAfterCursor = 1_000;
1510

1611
export type EditorOptions = Monaco.editor.IEditorOptions & Monaco.editor.IGlobalEditorOptions;
1712

@@ -72,7 +67,7 @@ export function useCodeAssist() {
7267
async (queries: {text: string; name?: string}[]) => {
7368
const preparedData: TelemetryOpenTabs = queries.map((query, index) => ({
7469
FileName: query.name || `query${index}.yql`,
75-
Text: query.text.slice(0, limitForTab),
70+
Text: query.text,
7671
}));
7772
try {
7873
return sendUserQueriesData(preparedData).unwrap();
@@ -83,16 +78,7 @@ export function useCodeAssist() {
8378
[sendUserQueriesData],
8479
);
8580

86-
const config = {
87-
language: YQL_LANGUAGE_ID,
88-
textLimits: {
89-
beforeCursor: limitBeforeCursor,
90-
afterCursor: limitAfterCursor,
91-
},
92-
};
93-
9481
return {
95-
config,
9682
getCodeAssistSuggestions,
9783
onCompletionAccept,
9884
onCompletionDecline,

src/services/api/codeAssist.ts

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,64 @@ const ideInfo = {
1616
PluginVersion: '0.2',
1717
};
1818

19+
const limitForTab = 10_000;
20+
const limitBeforeCursor = 8_000;
21+
const limitAfterCursor = 1_000;
22+
23+
function prepareCodeAssistTabs(tabs: TelemetryOpenTabs): TelemetryOpenTabs {
24+
return tabs.map((tab) => {
25+
const text = tab.Text;
26+
if (text.length > limitForTab) {
27+
return {
28+
...tab,
29+
Text: text.slice(0, limitForTab),
30+
};
31+
}
32+
33+
return tab;
34+
});
35+
}
36+
1937
function prepareCodeAssistPrompt(promptFiles: PromptFile[]): CodeAssistSuggestionsFiles {
20-
return promptFiles.map((file) => ({
21-
Fragments: file.fragments.map((fragment) => ({
22-
Text: fragment.text,
23-
Start: {
24-
Ln: fragment.start.lineNumber,
25-
Col: fragment.start.column,
26-
},
27-
End: {
28-
Ln: fragment.end.lineNumber,
29-
Col: fragment.end.column,
38+
return promptFiles.map((file) => {
39+
const cursorLine = file.cursorPosition.lineNumber;
40+
const cursorCol = file.cursorPosition.column;
41+
42+
return {
43+
Fragments: file.fragments.map((fragment) => {
44+
let text = fragment.text;
45+
const isBeforeCursor =
46+
fragment.end.lineNumber < cursorLine ||
47+
(fragment.end.lineNumber === cursorLine && fragment.end.column <= cursorCol);
48+
const isAfterCursor =
49+
fragment.start.lineNumber > cursorLine ||
50+
(fragment.start.lineNumber === cursorLine && fragment.start.column > cursorCol);
51+
52+
if (isBeforeCursor) {
53+
text = text.slice(-limitBeforeCursor);
54+
} else if (isAfterCursor) {
55+
text = text.slice(0, limitAfterCursor);
56+
}
57+
58+
return {
59+
Text: text,
60+
Start: {
61+
Ln: fragment.start.lineNumber,
62+
Col: fragment.start.column,
63+
},
64+
End: {
65+
Ln: fragment.end.lineNumber,
66+
Col: fragment.end.column,
67+
},
68+
};
69+
}),
70+
Cursor: {
71+
Ln: cursorLine,
72+
Col: cursorCol,
3073
},
31-
})),
32-
Cursor: {
33-
Ln: file.cursorPosition.lineNumber,
34-
Col: file.cursorPosition.column,
35-
},
36-
Path: `${file.path}.yql`,
37-
}));
74+
Path: `${file.path}.yql`,
75+
};
76+
});
3877
}
3978

4079
// In the future code assist api will be provided to ydb-ui component explicitly by consumer service.
@@ -77,7 +116,7 @@ export class CodeAssistAPI extends BaseYdbAPI {
77116
sendCodeAssistOpenTabs(data: TelemetryOpenTabs) {
78117
return this.post(
79118
'/code-assist-telemetry',
80-
{OpenTabs: {Tabs: data, IdeInfo: ideInfo}},
119+
{OpenTabs: {Tabs: prepareCodeAssistTabs(data), IdeInfo: ideInfo}},
81120
null,
82121
{
83122
concurrentId: 'code-assist-telemetry',

0 commit comments

Comments
 (0)