Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add edit words suggestion #2658

Merged
merged 5 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Spotless Apply
  • Loading branch information
leechor authored and github-actions[bot] committed Dec 16, 2023
commit 57fe2c25f40fab6348259642c7a1f1c7025c47be
21 changes: 15 additions & 6 deletions dinky-web/src/components/CustomEditor/CodeEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { editor, languages, Position } from 'monaco-editor';
import { buildAllSuggestionsToEditor } from '@/components/CustomEditor/CodeEdit/function';
import { handleInitEditorAndLanguageOnBeforeMount } from '@/components/CustomEditor/function';
import { StateType } from '@/pages/DataStudio/model';
import {MonacoEditorOptions, SuggestionInfo} from '@/types/Public/data';
import { MonacoEditorOptions, SuggestionInfo } from '@/types/Public/data';
import { convertCodeEditTheme } from '@/utils/function';
import { Editor, Monaco, OnChange } from '@monaco-editor/react';
import { connect } from '@umijs/max';
Expand Down Expand Up @@ -128,9 +128,18 @@ const CodeEdit = (props: CodeEditFormProps & connect) => {
kind: monaco.languages.CompletionItemKind.Text,
insertText: word
}));
let completionList: ProviderResult<CompletionList> = buildAllSuggestionsToEditor(model, position, wordSuggestions);
const suggestions: Promise<languages.CompletionList> = allSuggestions.then((res) => {
return {suggestions: [...(res?.suggestions ?? []), ...(completionList as CompletionList)?.suggestions]};
let completionList: ProviderResult<CompletionList> = buildAllSuggestionsToEditor(
model,
position,
wordSuggestions
);
const suggestions: Promise<languages.CompletionList> = allSuggestions.then((res) => {
return {
suggestions: [
...(res?.suggestions ?? []),
...(completionList as CompletionList)?.suggestions
]
};
});

context.triggerKind =
Expand Down Expand Up @@ -161,7 +170,7 @@ const CodeEdit = (props: CodeEditFormProps & connect) => {
editor.onDidChangeModelContent((e) => {
const model = editor.getModel();
if (model) {
const segmenter = new Intl.Segmenter("en", {granularity: "word"});
const segmenter = new Intl.Segmenter('en', { granularity: 'word' });
const segments = segmenter.segment(model.getValue());
const segmentedWords = [];
for (const segment of segments) {
Expand All @@ -172,7 +181,7 @@ const CodeEdit = (props: CodeEditFormProps & connect) => {
}
const uniqueSegmentedWords = Array.from(new Set(segmentedWords));
reloadCompilation(monacoIns, uniqueSegmentedWords);
}
}
});

if (enableSuggestions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import CodeShow from '@/components/CustomEditor/CodeShow';
import { SseData } from '@/models/Sse';
import {DataStudioTabsItemType, StateType, VIEW} from '@/pages/DataStudio/model';
import { DataStudioTabsItemType, StateType, VIEW } from '@/pages/DataStudio/model';
import { SSE_TOPIC } from '@/pages/DevOps/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { parseMilliSecondStr } from '@/utils/function';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const StudioEditor: React.FC<EditorProps & connect> = (props) => {
});
});
registerEditorKeyBindingAndAction(editor);

};

const handleEditChange = (v: string | undefined) => {
Expand Down
Loading