mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 03:16:01 +00:00
code completion context is only current query
This commit is contained in:
@@ -96,6 +96,11 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
export function getCodeCompletionCommandText() {
|
||||
if (currentPart != null) return currentPart.text;
|
||||
return editor.getValue();
|
||||
}
|
||||
|
||||
const requireEditorPlugins = () => {};
|
||||
requireEditorPlugins();
|
||||
|
||||
|
||||
@@ -39,7 +39,12 @@
|
||||
$: effect = useEffect(() => {
|
||||
const editor = domEditor?.getEditor();
|
||||
if ($tabVisible && conid && database && !readOnly && editor) {
|
||||
return mountCodeCompletion({ conid, database, editor });
|
||||
return mountCodeCompletion({
|
||||
conid,
|
||||
database,
|
||||
editor,
|
||||
getText: () => domEditor.getCodeCompletionCommandText(),
|
||||
});
|
||||
}
|
||||
return () => {};
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ const COMMON_KEYWORDS = [
|
||||
'go',
|
||||
];
|
||||
|
||||
export function mountCodeCompletion({ conid, database, editor }) {
|
||||
export function mountCodeCompletion({ conid, database, editor, getText }) {
|
||||
setCompleters([]);
|
||||
addCompleter({
|
||||
getCompletions: async function (editor, session, pos, prefix, callback) {
|
||||
@@ -44,7 +44,7 @@ export function mountCodeCompletion({ conid, database, editor }) {
|
||||
const lastKeywordMatch = line.match(/([a-zA-Z0-9_]*)\s*$/);
|
||||
const lastKeyword = lastKeywordMatch ? lastKeywordMatch[1].toUpperCase().trim() : '';
|
||||
|
||||
const sources = analyseQuerySources(editor.getValue(), [
|
||||
const sources = analyseQuerySources(getText(), [
|
||||
...dbinfo.tables.map(x => x.pureName),
|
||||
...dbinfo.views.map(x => x.pureName),
|
||||
...dbinfo.matviews.map(x => x.pureName),
|
||||
|
||||
Reference in New Issue
Block a user