-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix: code assistant option #1922
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae97fda
fix: code assistant option
astandrik f784bf7
fix: add usage
astandrik fc6ff3f
fix: better naming
astandrik 30f1b23
fix: default true
astandrik 97af66f
fix: condition
astandrik aafff94
fix: use instance instead of hook
astandrik 48e7356
fix: better code
astandrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import React from 'react'; | ||
|
||
import NiceModal from '@ebay/nice-modal-react'; | ||
import {useMonacoGhost} from '@ydb-platform/monaco-ghost'; | ||
import {createMonacoGhostInstance} from '@ydb-platform/monaco-ghost'; | ||
import throttle from 'lodash/throttle'; | ||
import type Monaco from 'monaco-editor'; | ||
|
||
|
@@ -11,7 +13,7 @@ import { | |
selectUserInput, | ||
} from '../../../../store/reducers/query/query'; | ||
import type {QueryAction} from '../../../../types/store/query'; | ||
import {LAST_USED_QUERY_ACTION_KEY} from '../../../../utils/constants'; | ||
import {ENABLE_CODE_ASSISTANT, LAST_USED_QUERY_ACTION_KEY} from '../../../../utils/constants'; | ||
import { | ||
useEventHandler, | ||
useSetting, | ||
|
@@ -23,9 +25,8 @@ import {useUpdateErrorsHighlighting} from '../../../../utils/monaco/highlightErr | |
import {QUERY_ACTIONS} from '../../../../utils/query'; | ||
import {SAVE_QUERY_DIALOG} from '../SaveQuery/SaveQuery'; | ||
import i18n from '../i18n'; | ||
import {useSavedQueries} from '../utils/useSavedQueries'; | ||
|
||
import {useCodeAssist, useEditorOptions} from './helpers'; | ||
import {useCodeAssistHelpers, useEditorOptions} from './helpers'; | ||
import {getKeyBindings} from './keybindings'; | ||
|
||
const CONTEXT_MENU_GROUP_ID = 'navigation'; | ||
|
@@ -45,8 +46,11 @@ export function YqlEditor({ | |
}: YqlEditorProps) { | ||
const input = useTypedSelector(selectUserInput); | ||
const dispatch = useTypedDispatch(); | ||
const [monacoGhostInstance, setMonacoGhostInstance] = | ||
React.useState<ReturnType<typeof createMonacoGhostInstance>>(); | ||
const historyQueries = useTypedSelector(selectQueriesHistory); | ||
const savedQueries = useSavedQueries(); | ||
const [isCodeAssistEnabled] = useSetting(ENABLE_CODE_ASSISTANT); | ||
|
||
const editorOptions = useEditorOptions(); | ||
const updateErrorsHighlighting = useUpdateErrorsHighlighting(); | ||
|
||
|
@@ -71,20 +75,18 @@ export function YqlEditor({ | |
window.ydbEditor = undefined; | ||
}; | ||
|
||
const codeAssist = useCodeAssist(); | ||
const {registerMonacoGhost} = useMonacoGhost({ | ||
api: { | ||
getCodeAssistSuggestions: codeAssist.getCodeAssistSuggestions, | ||
}, | ||
eventHandlers: { | ||
onCompletionAccept: codeAssist.onCompletionAccept, | ||
onCompletionDecline: codeAssist.onCompletionDecline, | ||
onCompletionIgnore: codeAssist.onCompletionIgnore, | ||
}, | ||
config: { | ||
language: YQL_LANGUAGE_ID, | ||
}, | ||
}); | ||
const {monacoGhostConfig, prepareUserQueriesCache} = useCodeAssistHelpers(); | ||
|
||
React.useEffect(() => { | ||
if (monacoGhostInstance && isCodeAssistEnabled) { | ||
monacoGhostInstance.register(monacoGhostConfig); | ||
prepareUserQueriesCache(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we prepare cache every time any useEffect dependency changes? |
||
} | ||
|
||
return () => { | ||
monacoGhostInstance?.unregister(); | ||
}; | ||
}, [isCodeAssistEnabled, monacoGhostConfig, monacoGhostInstance, prepareUserQueriesCache]); | ||
|
||
const editorDidMount = (editor: Monaco.editor.IStandaloneCodeEditor, monaco: typeof Monaco) => { | ||
window.ydbEditor = editor; | ||
|
@@ -100,18 +102,9 @@ export function YqlEditor({ | |
}); | ||
|
||
if (window.api.codeAssist) { | ||
registerMonacoGhost(editor); | ||
codeAssist.prepareUserQueriesCache([ | ||
...historyQueries.map((query, index) => ({ | ||
name: `query${index}.yql`, | ||
text: query.queryText, | ||
})), | ||
...savedQueries.map((query) => ({ | ||
name: query.name, | ||
text: query.body, | ||
})), | ||
]); | ||
setMonacoGhostInstance(createMonacoGhostInstance(editor)); | ||
} | ||
|
||
initResizeHandler(editor); | ||
initUserPrompt(editor, getLastQueryText); | ||
editor.focus(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not use state for editor instance? Will
window.ydbEditor
be enough?