Can I use autocomplete without implementing a parser (or language)?

If I have implemented a basic completion function like so:

function myCompletions(context: CompletionContext) {
  let word = context.matchBefore(/\w*/);
  if (word?.from == word?.to && !context.explicit) return null;
  return {
    from: word?.from,
    options: [
      { label: "match", type: "keyword" },
      { label: "hello", type: "variable", info: "(World)" },
      { label: "magic", type: "text", apply: "⠁⭒*.✩.*⭒⠁", detail: "macro" },

The autocomplete example says I should then add this to a language with{
  autocomplete: myCompletions

But as far as I can tell this means defining a parser for that language which I would rather not do. I’ve tried turning it into an extension with:

const autocompleteExt = Facet.define().of({
  autocomplete: myCompletions,

Which type checks, but doesn’t seem to work. Is there a way of doing this that does work?

1 Like

That defines an anonymous facet which is then never accessed again, so it won’t have any effect, indeed.

You can use something like EditorState.languageData.of(() => ({autocomplete: myCompletions})) as an extension to add language data for all languages. Or use the override option to autocompletion().


Thank you! override in autocompletion() worked for me. I missed the fact that existed.

I have the same motivation, I want to create autocomplete without parser.
Could you please tell me how you did add autocomplete to Editorstate