How to enable Auto completion for SQL language. #40
-
I saw that code highlight is supported for SQL language. But i am not understanding how to implment auto completion for SQL. I have only seen autocomplete example of CSS,HTML,javascript. Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Answered by
FIameCaster
Dec 26, 2024
Replies: 1 comment · 2 replies
-
I haven't made autocompletion for any languages other than HTML, CSS, and JavaScript. If you want autocomplete for SQL, you'll have to make it yourself. If all you want is autocomplete for SQL keywords, then this is easily doable. import { getClosestToken } from "prism-code-editor/utils"
import { Completion, CompletionSource, registerCompletions } from "prism-code-editor/autocomplete"
const options: Completion[] = listOfSqlKeywords.map(label => ({ label, icon: "keyword" }))
const sqlSource: CompletionSource = (context, editor) => {
if (getClosestToken(editor, ".string, .comment", 0, 0, context.pos)) {
return // Disable autocomplete in comments and strings
}
const wordBefore = /\w*$/.exec(context.lineBefore)![0]
if (wordBefore || context.explicit) {
return {
from: context.pos - wordBefore.length,
options: options,
}
}
}
registerCompletions(["sql"], {
sources: [sqlSource]
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tanujkucp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I haven't made autocompletion for any languages other than HTML, CSS, and JavaScript. If you want autocomplete for SQL, you'll have to make it yourself. If all you want is autocomplete for SQL keywords, then this is easily doable.