-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improved auto complete #2
Comments
I can't use the autocomplete since there's no direct call to mocaco (editor) to keeping creating the suggestions but I add the funcions and keywords directly from the duckDb settings. const keywordsResult: any = await executeQuery(
"SELECT DISTINCT(keyword_name) FROM duckdb_keywords()"
);
const functionsResult: any = await executeQuery(
"SELECT DISTINCT ON (function_name) * FROM DUCKDB_FUNCTIONS();"
); |
Not sure I understood the reason, in my own implementation I pass the input to the auto complete extension via monaco.languages.registerCompletionItemProvider('sql', {
async provideCompletionItems(model, position) {
const word = model.getWordUntilPosition(position);
const conn = await db.connect();
const range = {
startLineNumber: position.lineNumber,
endLineNumber: position.lineNumber,
startColumn: word.startColumn,
endColumn: word.endColumn,
};
const textInRange = model.getValueInRange({
startColumn: 0,
endColumn: position.column,
startLineNumber: position.lineNumber,
endLineNumber: position.lineNumber,
});
const query = `select suggestion from sql_auto_complete('${escape(textInRange)}')`;
const items = await queryNative<{ suggestion: arrow.DataType<arrow.Type.Utf8> }>(conn, query);
if (!items) return { suggestions: [] };
const suggestions = items.values.map((item) => {
return {
label: String(item.suggestion),
kind: monaco.languages.CompletionItemKind.Field,
insertText: String(item.suggestion),
range,
};
});
return {
suggestions,
};
},
}); Note that the engine provides suggestions based on the context, and it got improved a lot in v1.2.0, so it's much better than plain matching. Of course it also keeps suggestions in sync as the user adds db's/files etc. |
HEYYY! @aszenz genius thankss! I got it now and you are right it works like a charm, I just didn't implemented it right! Thanks for sharing your code! ![]() PD: I'll release that on the next one! |
…database connections feat:autocomplete #2
Idea Statement
Currently I see this tool manually defines completion's in the Monaco editor, I think using duckdbs own auto complete engine via the extensions may give better results.
Feature implementation brainstorm
See:
https://duckdb.org/docs/api/cli/autocomplete.html
It works on wasm
The text was updated successfully, but these errors were encountered: