# SQL Autocomplete additions

**URL:** <https://discuss.codemirror.net/t/sql-autocomplete-additions/9115>\
**Category:** v6\
**Created:** [April 1, 2025, 3:18pm UTC](https://discuss.codemirror.net/t/sql-autocomplete-additions/9115 "2025-04-01T15:18:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BadMachine](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/badmachine/32/5053_2.png) [@BadMachine](https://discuss.codemirror.net/u/BadMachine)\
**Post date:** [April 1, 2025, 3:18pm UTC](https://discuss.codemirror.net/t/sql-autocomplete-additions/9115/1 "2025-04-01T15:18:50Z")

</div>

I spent 2 days trying to apply a few more suggestions using autocomplete system.  
My setup is CodeMirror with sql-lang extension, which (as we know) doesnt suggest you column names at particular places, such as WHERE … So im trying to add this manually using autocomplete extension method:

```auto
  const [ext, setExt] = useState<any>();

  useEffect(() => {
    setExt(
      sql({
        dialect: StandardSQL,
        upperCaseKeywords: true,
        // schema,
      })
    );
  }, [schema]);

  const columnCompletion: CompletionSource = useCallback((context: CompletionContext) => {
    const whereMatch = context.matchBefore(/WHERE\s+([\w\d_]*)$/);
    if (!whereMatch) {
      return schemaCompletionSource({ schema })(context);
    }

    const columnPrefix = whereMatch.text.match(/WHERE\s+([\w\d_]*)$/)?.[1] || "";

    const sqlBeforeWhere = context.state.sliceDoc(0, whereMatch.from);

    const tableMatch = sqlBeforeWhere.match(/FROM\s+['"]?([\w\d_]+)['"]?/);
    const tableName = tableMatch ? tableMatch[1] : null;

    if (!tableName) return null;

    const columnSuggestions = schema[tableName] || []; // Берём колонки таблицы

    console.log('columns ', columnSuggestions
      .filter(c => c.startsWith(columnPrefix)) // Фильтруем по уже введённому
      .map(c => ({ label: c, type: "variable" })))
    return {
      from: whereMatch.from,
      to: whereMatch.to,
      options: columnSuggestions
        .filter(c => c.startsWith(columnPrefix)) // Фильтруем по уже введённому
        .map(c => ({ label: c, type: "variable", boost: 100 }))
    };

  }, [schema])

      <CodeMirror
        value={values?.query}
        defaultValue={initialQuery}
        onChange={handleChangeQuery}
        ref={inputRef}
        basicSetup={{
          lineNumbers: false,
          autocompletion: true,
        }}
        extensions={[
          ext,
          ext?.language.data.of({
            autocomplete: columnCompletion,
          }),
        ]}
      />

```

It gives me basic autocomplete and also triggers column completion logic, BUT THERE IS NO HINTS list.  
I literally search through the whole forum + official website + stackoverflow + github and there is no solution to such problems. Can you imagine?

---

<div class="post-metadata">

**Author:** ![innazh](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/innazh/32/5457_2.png) [@innazh](https://discuss.codemirror.net/u/innazh)\
**Post date:** [April 28, 2026, 3:19pm UTC](https://discuss.codemirror.net/t/sql-autocomplete-additions/9115/2 "2026-04-28T15:19:06Z")

</div>

hey, I’m wrestling with something similar now. What solution did you come to in the end?

> I literally search through the whole forum + official website + stackoverflow + github and there is no solution to such problems. Can you imagine?

I’m as surprised as your are. Unless we’re missing something.
