Skip to content

Commit

Permalink
fixing contextual autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Mar 17, 2023
1 parent dcd9bd3 commit a43203c
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions lib/waveql-completions-with.js
@@ -1,29 +1,43 @@
'use strict';


// const {TreeCursor} = require('@lezer/common');

const getSig = require('./get-sig.js');
const getScopeType = require('./get-scope-type.js');
const getVarType = require('./get-var-type.js');

// signal autocomplete
// https://codemirror.net/examples/autocompletion/
const waveqlCompletionsWith = (/* deso */) => {
const waveqlCompletionsWith = (deso) => {
// const {wires} = deso;
return (context) => {
const word = context.matchBefore(/\w*/);
if (word.from == word.to && !context.explicit) {
return (context /* : CompletionContext */) => {
const word = context.matchBefore(/[\w_.()[\]]+/);
if (!word || word.from == word.to && !context.explicit) {
return null;
}
const cursor = context.state.selection.main.head; // getCursor
const token = context.tokenBefore(['namespace', 'variableName']);
// const cursorLine = context.state.doc.line(n + 1).text; // getLine
// const line = cm.getLine(cursor.line);
// const
// const foo = context.state.values.find(e => e.tree).tree.resolve(word.from); // Tree(context.state);
const foo = context.state.values.find(e => e.tree).tree;
console.log(context, word, cursor, token, foo);
const values = context.state.values;
const tree = values.find(e => e.tree).tree;
const children = tree.children;
const tree0 = children[0];
const props = tree0.props;
const propKeys = Object.keys(props);
const pathKey = propKeys.find(key => props[key].path);

const path = props[pathKey].path;
const scope = getSig(deso.wires, path);

const options = (scope.body || []).map(ero => {
const type = (
(ero.kind === 'var') ? ero.kind + '-' + getVarType(ero.type).icon :
(ero.kind === 'scope') ? ero.kind + '-' + getScopeType(ero.type).icon :
undefined
);
return {label: ero.name, type};
});
return {
from: word.from,
options: [
{label: 'match', type: 'keyword'},
{label: 'hello', type: 'variable', info: '(World)'},
{label: 'magic', type: 'text', apply: '⠁⭒*.✩.*⭒⠁', detail: 'macro'}
]
options
};
};
};
Expand Down

0 comments on commit a43203c

Please sign in to comment.