Replies: 1 comment 3 replies
-
|
You can easily define your own completion sources like shown below: import { Completion, CompletionSource, registerCompletions } from "prism-code-editor/autocomplete"
const myCompletions: Completion[] = [
"list",
"of",
"completable",
"words",
].map(label => { label, icon: "variable" })
const mySource: CompletionSource = (context, editor) => {
const wordBefore = /(?:(?!\s)[$\w\xa0-\uffff])*$/.exec(context.lineBefore)!
if (wordBefore || context.explicit) {
return {
from: context.pos - wordBefore.length,
options: myCompletions,
}
}
}
registerCompletions(["my-language"], {
sources: [mySource]
})The list of completions can also be computed inside the completion source if needed. If anything is unclear, let me know. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hi community,
I know this is closed but I was wondering if it is possible to make the autocomplete list show from predefined list? or if anyone was able to create their own autocomplete?
In my case, the user can create a list of method and variables in a different page in my app (like in settings and we save those in our backend) but when they are using the editor in another page, I would like to show those user defined methods/variables in the autocomplete.
so i think using something like
registerCompletions(['javascript',wouldn't work since we are not using any javascript definitions/rules itself such asconstructor,classand other reserved words. but rather barebones java/javascript-like syntax (i.e.if,else,(){}, operators,whatevermethodname(whateverParams)) with the variables and method names that user set.Beta Was this translation helpful? Give feedback.
All reactions