System.register(["reactive-jsx", "utils", "src/client/constants.js", "./code-mirror-utils.js", "src/external/color-hash.js"], function (_export, _context) {
  "use strict";

  var _childElement, _childText, _attributeExpression, _childExpression, _children, _attributeStringLiteral, _attributes, _element, uniq, javaScriptKeywords, cssProperties, domEvents, utils, indentSelections, Completions, ColorHash, CompletionsBuilder, __SystemJSRewritingHack, stringProps, arrayProps, funcProps, Pos, importsCache, importsCacheTime, colorHash;
  function lcmFromCM(cm) {
    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
    return lively.allParents(cm.getWrapperElement(), undefined, true).find(e => e.tagName === 'LIVELY-CODE-MIRROR');
  }

  /*MD # Import MD*/

  async function searchImports() {
    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
    if (!importsCache || Date.now() - importsCacheTime > 60 * 60 * 1000) {
      globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
      _recorder_._src_components_widgets_lively_code_mirror_hint_js.importsCacheTime = Date.now();
      _recorder_._src_components_widgets_lively_code_mirror_hint_js.importsCache = await fetch(lively4url + "/../_search/files", {
        headers: {
          searchpattern: "^import",
          rootdirs: lively4url.replace(/.*\//, ""),
          excludes: "node_modules,src/external,vendor/,lodash-bound.js"
        }
      }).then(r => r.text());
    }
    return importsCache;
  }
  function colorForString(str) {
    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
    return colorHash.hex(str);
  }
  function forOrigin(completion, origin) {
    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
    if (typeof completion === 'string') {
      globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
      completion = {
        text: completion
      };
    }
    return Object.assign({
      render(element, self, data) {
        globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
        if (completion.innerRender) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          completion.innerRender(element, self, data);
        } else {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          element.append(_element("span", _attributes(), _children(_childExpression(completion.displayText || completion.text)), {
            file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
            end: {
              column: 79,
              line: 152
            },
            start: {
              column: 23,
              line: 152
            }
          }));
        }
        element.append(_element("span", _attributes(_attributeStringLiteral("style", "display: inline-block; width: 50px;")), _children(), {
          file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
          end: {
            column: 78,
            line: 154
          },
          start: {
            column: 21,
            line: 154
          }
        }));
        element.append(_element("span", _attributes(_attributeExpression("style", `background: ${colorForString(origin)}; color: black; position: absolute; right: 2px; font-size: x-small;`)), _children(_childExpression(origin)), {
          file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
          end: {
            column: 157,
            line: 155
          },
          start: {
            column: 21,
            line: 155
          }
        }));
      }
    }, completion);
  }

  /*MD # CompletionsBuilder MD*/

  function javascriptHint(cm, options) {
    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
    return new CompletionsBuilder(cm).buildHint(options);
  }
  return {
    setters: [function (_reactiveJsx) {
      _childElement = _reactiveJsx.childElement;
      _childText = _reactiveJsx.childText;
      _attributeExpression = _reactiveJsx.attributeExpression;
      _childExpression = _reactiveJsx.childExpression;
      _children = _reactiveJsx.children;
      _attributeStringLiteral = _reactiveJsx.attributeStringLiteral;
      _attributes = _reactiveJsx.attributes;
      _element = _reactiveJsx.element;
    }, function (_utils) {
      uniq = _utils.uniq;
      utils = _utils;
    }, function (_srcClientConstantsJs) {
      javaScriptKeywords = _srcClientConstantsJs.javaScriptKeywords;
      cssProperties = _srcClientConstantsJs.cssProperties;
      domEvents = _srcClientConstantsJs.domEvents;
    }, function (_codeMirrorUtilsJs) {
      indentSelections = _codeMirrorUtilsJs.indentSelections;
    }, function (_srcExternalColorHashJs) {
      ColorHash = _srcExternalColorHashJs.default;
    }],
    execute: function () {
      __SystemJSRewritingHack = {};
      _recorder_._src_components_widgets_lively_code_mirror_hint_js = _recorder_._src_components_widgets_lively_code_mirror_hint_js || {};
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "javascriptHint", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return javascriptHint;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          javascriptHint = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "forOrigin", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return forOrigin;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          forOrigin = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "colorForString", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return colorForString;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          colorForString = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "searchImports", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return searchImports;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          searchImports = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "lcmFromCM", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return lcmFromCM;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          lcmFromCM = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "uniq", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return uniq;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          uniq = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      stringProps = Object.getOwnPropertyNames(''.__proto__);
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "stringProps", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return stringProps;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          stringProps = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      arrayProps = Object.getOwnPropertyNames([].__proto__);
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "arrayProps", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return arrayProps;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          arrayProps = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      funcProps = Object.getOwnPropertyNames(function () {
        globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
      }.__proto__);
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "funcProps", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return funcProps;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          funcProps = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "domEvents", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return domEvents;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          domEvents = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "cssProperties", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return cssProperties;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          cssProperties = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "javaScriptKeywords", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return javaScriptKeywords;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          javaScriptKeywords = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "utils", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return utils;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          utils = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "indentSelections", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return indentSelections;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          indentSelections = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Pos = CodeMirror.Pos;
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "Pos", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return Pos;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          Pos = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      importsCache = _recorder_._src_components_widgets_lively_code_mirror_hint_js.importsCache;
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "importsCache", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return importsCache;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          importsCache = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      importsCacheTime = _recorder_._src_components_widgets_lively_code_mirror_hint_js.importsCacheTime;
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "importsCacheTime", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return importsCacheTime;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          importsCacheTime = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      searchImports();

      /*MD # Completions MD*/
      Completions = class Completions {
        constructor(cm) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          this.cm = cm;
          this.list = [];
          this.seenCompletions = new Set();
          this.prepareToken();
        }
        prepareToken() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const cm = this.cm;

          // Find the token at the cursor
          var cursor = cm.getCursor();
          var token = cm.getTokenAt(cursor);
          token.state = CodeMirror.innerMode(cm.getMode(), token.state).state;

          // lively.notify(token.string, token.type);
          if (token.type === 'string') {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            token = {
              start: token.start + 1,
              end: cursor.ch,
              string: token.string.substring(1, cursor.ch - token.start),
              state: token.state,
              type: 'string'
            };
          } else if (!/^[\w$_]*$/.test(token.string)) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            // If it's not a 'word-style' token, ignore the token.
            token = {
              start: cursor.ch,
              end: cursor.ch,
              string: "",
              state: token.state,
              type: token.string == "." ? "property" : null
            };
          } else if (token.end > cursor.ch) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            token.end = cursor.ch;
            token.string = token.string.slice(0, cursor.ch - token.start);
          }
          this.token = token;
        }
        maybeAdd(completion) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const simple = typeof completion === 'string';
          const text = simple ? completion : completion.text;
          if (this.seenCompletions.has(text)) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            return;
          }

          // #TODO: getTextAt(from, to) or string iff no from/to in completion
          if (!text.startsWith(this.token.string)) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            return;
          }
          this.seenCompletions.add(text);
          this.list.push(completion);
        }
        asCompletionsObject() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          if (this.list.length === 0) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            return;
          }
          const line = this.cm.getCursor().line;
          const completionsObject = {
            list: this.list,
            from: Pos(line, this.token.start),
            to: Pos(line, this.token.end)
          };
          CodeMirror.on(completionsObject, "shown", () => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          } // lively.warn("shown");
          );

          CodeMirror.on(completionsObject, "select", (completion, element) => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            if (!element.parentElement.querySelector('li.shortcut-present')) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              element.classList.add('shortcut-present');
              const hints = element.parentElement.querySelectorAll('li.CodeMirror-hint');
              hints.forEach((hint, i) => {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                if (i > 9) {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  return;
                }
                hint.prepend(_element("span", _attributes(_attributeStringLiteral("style", "position: absolute; transform: translate(-6px, 0); font-size: xx-small; color: darkgray; background: white;")), _children(_childExpression(i)), {
                  file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                  end: {
                    column: 155,
                    line: 119
                  },
                  start: {
                    column: 23,
                    line: 119
                  }
                }));
              });
            }
          });
          CodeMirror.on(completionsObject, "pick", completion => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          } // lively.warn("pick");
          );

          CodeMirror.on(completionsObject, "close", () => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          } // lively.warn("close");
          );

          return completionsObject;
        }
      };
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "Completions", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return Completions;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          Completions = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "ColorHash", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return ColorHash;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          ColorHash = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      colorHash = new ColorHash({
        saturation: 0.8,
        lightness: 0.8
      });
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "colorHash", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return colorHash;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          colorHash = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      CompletionsBuilder = class CompletionsBuilder {
        constructor(cm) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          this.cm = cm;
          this.completions = new Completions(cm);
        }
        maybeAdd(str) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          this.completions.maybeAdd(str);
        }
        async buildHint(options) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          await this.collectCompletions(options);

          // lively.notify(this.completions.list.length, 'num completions');
          return this.completions.asCompletionsObject();
        }
        async collectCompletions(options) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const cm = this.cm;
          const completions = this.completions;
          var cursor = cm.getCursor();
          const line = cm.getLine(cursor.line);
          if (line.startsWith("import")) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            await this.completeFromImport(cm);
            return;
          }
          var token = completions.token;
          // lively.notify('type: ' + token.type, 'string: ' + token.string);

          if (token.type === 'string') {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            cssProperties.map(property => forOrigin(property, 'cssProperties')).forEach(this.maybeAdd.bind(this));
            domEvents.map(property => forOrigin(property, 'domEvents')).forEach(this.maybeAdd.bind(this));
            return;
          }
          if (token.type === 'comment') {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            return;
          }
          this.completeLively();
          this.completeDoItCommand();
          await this.completeFromTern();
          if (token.type === 'property') {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            const variables = [];
            const startExpr = {};
            let lineNumber = cursor.line;
            let firstLine = true;
            whileLoop: while (lineNumber >= 0) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              let tokens;
              tokens = cm.getLineTokens(lineNumber, true);
              if (firstLine) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                firstLine = false;
                tokens = tokens.filter(t => t.start < token.start);
              }
              tokens = tokens.reverse();
              let parensBalance = 0;
              for (let {
                string,
                type,
                start
              } of tokens) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                // console.log( string, type, start )
                if (type === null && string === '(') {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  parensBalance--;
                } else if (type === null && string === ')') {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  parensBalance++;
                } else if (typeof type === 'string' && type.includes('variable')) {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  variables.push(string);
                  if (parensBalance <= 0) {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    startExpr.ch = start;
                    startExpr.line = lineNumber;
                    break whileLoop;
                  }
                }
              }
              lineNumber--;
            }
            let code;
            // lively.notify(variables, 'variables')
            try {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              code = cm.getRange(startExpr, {
                line: cursor.line,
                ch: token.start - 1
              });
            } catch (e) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              console.warn("Error in code-mirror-hint, could not comlete, because: ", e);
              return;
            }
            const decls = [];

            // lively.getClientBounds(document.body)
            //   .topLeft().subPt(pt(-10, 0)).x.rFOOOOOO

            const uniqueVariables = new Set(variables);
            decls.push(`var decls = await System.import('src/components/widgets/lively-code-mirror-hint-decls.js');`);
            const codeMirrorDecls = 'cm, lcm';
            if (['cm', 'lcm'].some(vari => uniqueVariables.has(vari))) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              decls.push(`var { cm, lcm } = await decls.codeMirror();`);
            }
            const babelDecls = 'babel, t, template, path, parentPath, node, parentNode, identifier, scope, binding';
            if (babelDecls.split(', ').some(vari => uniqueVariables.has(vari))) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              decls.push(`var { ${babelDecls} } = await decls.babel();`);
            }
            const finalCode = `(async () => {
try {
${decls.join(`;
`)}
return ${code}
} catch(e) {}
})()`;
            var {
              value,
              isError
            } = await options.codemirror.boundEval(finalCode);
            if (isError) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              lively.warn(value);
            } else {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              value = await value;
              this.gatherCompletionsForObject(value, 'x');
            }
          }
          var tprop = token;
          const getToken = cm.getTokenAt.bind(cm);
          // If it is a property, find out what it is a property of.
          while (tprop.type == "property") {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            tprop = getToken(Pos(cursor.line, tprop.start));
            if (tprop.string != ".") {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              break;
            }
            tprop = getToken(Pos(cursor.line, tprop.start));
            if (!context) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              var context = [];
            }
            context.push(tprop);
          }
          if (context && context.length === 1 && context[0].string === 'this') {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.completeMembersOfThis();
          }
          var global = options && options.globalScope || window;
          if (context && context.length) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            // If this is a property, see if it belongs to some object we can
            // find in the current environment.
            var obj = context.pop(),
              base;
            if (obj.type && obj.type.indexOf("variable") === 0 || obj.string == "this") {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              if (options && options.additionalContext) base = options.additionalContext[obj.string];
              if (base === undefined && obj && obj.string) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                // #TODO instead of doing a blackbox evaluation of a string, we could look into the various scopes... 
                // in the module or live prgoramming data structures... e.g. from AST with trace data such as #ContinuousEditor
                // documentation: getDoitContext() and getTargetModule()
                var {
                  value,
                  isError
                } = await options.codemirror.boundEval(obj.string);
                if (!isError) {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  base = value;
                }
              }
              if (!options || options.useGlobalScope !== false) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                base = base || global[obj.string];
              }
            } else if (obj.type == "string") {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              base = "";
            } else if (obj.type == "atom") {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              base = 1;
            } else if (obj.type == "function") {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              // #TODO make it work for function calls such as pt(10,10), too.... 
              if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') && typeof global.jQuery == 'function') {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                base = global.jQuery();
              } else if (global._ != null && obj.string == '_' && typeof global._ == 'function') {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                base = global._();
              }
              ;
            }
            while (base != null && context.length) base = base[context.pop().string];
            if (base != null) this.gatherCompletionsForObject(base);
            return;
          }
          const c = cm.getCursor();
          const prevToken = cm.getTokenAt({
            line: c.line,
            ch: token.start - 0
          });
          const prevPrevToken = cm.getTokenAt({
            line: c.line,
            ch: token.start - 1
          });
          if (prevToken.string == ":" && prevPrevToken.string == ":") {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.completeUtilsFunctions(token);
            return;
          }

          // If not, just look in the global object and any local scope
          // (reading into JS mode internals to get at the local and global variables)

          for (var v = token.state.localVars; v; v = v.next) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.maybeAdd(forOrigin(v.name, 'local'));
          }
          for (var w = token.state.globalVars; w; w = w.next) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.maybeAdd(forOrigin(w.name, 'global'));
          }
          if (!options || options.useGlobalScope !== false) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.gatherCompletionsForObject(global);
          }
          javaScriptKeywords.map(keyword => forOrigin(keyword + ' ', 'keyword')).forEach(this.maybeAdd.bind(this));
        }

        /*MD ## Completions for an Object MD*/
        gatherCompletionsForObject(obj, hintPrefix = '') {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          this.allProps(obj, hintPrefix);
          if (typeof obj == "string") {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.forPropList(stringProps, hintPrefix + 'str');
          } else if (obj instanceof Array) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.forPropList(arrayProps, hintPrefix + 'arr');
          } else if (obj instanceof Function) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.forPropList(funcProps, hintPrefix + 'fun');
          }
        }
        forPropList(propList, origin) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          propList.map(name => forOrigin(name, origin)).forEach(this.maybeAdd.bind(this));
        }
        allProps(obj, hintPrefix) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          for (var o = obj; o; o = Object.getPrototypeOf(o)) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            Object.getOwnPropertyNames(o).forEach(prop => this.addObjectProp(o, prop, hintPrefix));
          }
        }
        addObjectProp(obj, prop, hintPrefix) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          let completion = prop;
          const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
          let value = descriptor.value;
          if (value) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            if (typeof value === 'function') {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              let str = value.toString().split('\n').first.substring(0, 50);
              completion = {
                text: prop,
                innerRender(element, self, data) {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  element.append(_element("span", _attributes(), _children(_childExpression(prop), _childText(" "), _childElement(_element("span", _attributes(_attributeStringLiteral("style", "color: rgba(200, 200, 200, 0.9)")), _children(_childExpression(str)), {
                    file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                    end: {
                      column: 98,
                      line: 404
                    },
                    start: {
                      column: 40,
                      line: 404
                    }
                  }))), {
                    file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                    end: {
                      column: 105,
                      line: 404
                    },
                    start: {
                      column: 27,
                      line: 404
                    }
                  }));
                },
                hint: (cm, self, data) => {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  const args = this.parseArgsFrom(`const fn = ${value}`, 'FunctionExpression') || this.parseArgsFrom(`class C {${value}}`, 'ClassMethod') || [];
                  this.completeFunction(cm, self, data, prop, args);
                  CodeMirror.commands.indentAuto(cm);
                }
              };
              this.maybeAdd(forOrigin(completion, hintPrefix + 'prop'));
              return;
            } else if (value.toString) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              value = value.toString().substring(0, 50);
            }
            lively.n;
            completion = {
              text: prop,
              innerRender(element, self, data) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                element.append(_element("span", _attributes(), _children(_childExpression(prop), _childText(" "), _childElement(_element("span", _attributes(_attributeStringLiteral("style", "color: rgba(200, 200, 200, 0.9)")), _children(_childExpression(value)), {
                  file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                  end: {
                    column: 98,
                    line: 422
                  },
                  start: {
                    column: 38,
                    line: 422
                  }
                }))), {
                  file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                  end: {
                    column: 105,
                    line: 422
                  },
                  start: {
                    column: 25,
                    line: 422
                  }
                }));
              }
            };
          } else {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          }
          this.maybeAdd(forOrigin(completion, hintPrefix + 'prop'));
        }
        parseArgsFrom(code, nodeType) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const args = [];
          try {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            code.traverseAsAST({
              [nodeType](path) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                const params = path.get('params');
                params.forEach(param => {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  if (param.isIdentifier()) {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    args.push(param.node.name);
                  } else {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    // RestElement, Patterns
                    let arg = '';
                    param.traverse({
                      Identifier(path) {
                        globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                        arg += path.node.name;
                      }
                    });
                    args.push(arg);
                  }
                });
              }
            });
            return args;
          } catch (e) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          }
        }

        /*MD ## Specific Completions MD*/
        completeMembersOfThis() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          let currentClass;
          this.cm.eachLine(lineHandle => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            const classMatch = lineHandle.text.match(/^(?:\s|export\s|default\s)*class\s+([_$a-zA-z][_$a-zA-Z0-9]*).*\{$/);
            if (classMatch) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              currentClass = classMatch[1];
              // lively.notify(Object.getOwnPropertyNames(lineHandle));
              return;
            }
            const firstLine = lineHandle.text;
            const match = firstLine.match(/^\s*((?:async\s|get\s|set\s|static\s)*)([_$a-zA-z][_$a-zA-Z0-9]*)(\*?\s*\(.*\)\s*\{)$/);
            if (match) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              const [, modifiers, name, argsAndBodyStart] = match;
              if (javaScriptKeywords.includes(name) || name === 'constructor') {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                return;
              }
              const myClass = currentClass;
              const completion = {
                text: name,
                innerRender(element, self, data) {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  function grayish(content) {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    const style = "color: rgba(200, 200, 200, 0.9); display:inline-block; max-width: 50ch;";
                    return _element("span", _attributes(_attributeExpression("style", style)), _children(_childExpression(content)), {
                      file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                      end: {
                        column: 57,
                        line: 481
                      },
                      start: {
                        column: 21,
                        line: 481
                      }
                    });
                  }
                  element.append(_element("span", _attributes(), _children(_childExpression(grayish(modifiers + (myClass ? myClass + '::' : ''))), _childExpression(name), _childExpression(grayish(argsAndBodyStart))), {
                    file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                    end: {
                      column: 127,
                      line: 483
                    },
                    start: {
                      column: 27,
                      line: 483
                    }
                  }));
                },
                hint: (cm, self, data) => {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  if (modifiers.includes('get') || modifiers.includes('set')) {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    cm.replaceRange(data.text, self.from, self.to);
                  } else {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    const args = this.parseArgsFrom(`class C {${firstLine}}}`, 'ClassMethod') || [];
                    this.completeFunction(cm, self, data, name, args);
                  }
                  CodeMirror.commands.indentAuto(cm);
                }
              };
              // lively.notify(name);
              this.maybeAdd(forOrigin(completion, 'member'));
            }
          });
        }
        async completeFromImport(cm) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const getCompletionsFromImports = async () => {
            var _context2;
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            // #TODO make faster with index and caching
            // but: #TODO what is the workflox / programming XP, we aim for?
            var text = await searchImports();
            var imports = (_context2 = text.split("\n").map(ea => ea.replace(/.*:/, "").replace(/;$/, "").replace(/"/g, "'")).filter(ea => !ea.match('\'\.\.?/')).filter(ea => ea.startsWith("import ")).sort(), uniq).call(_context2);
            imports.map(i => forOrigin(i, 'import')).forEach(this.maybeAdd.bind(this));
          };
          const getToken = cm.getTokenAt.bind(cm);

          // Find the token at the cursor
          var cursor = cm.getCursor();
          var token = getToken(cursor);

          // use a "line" token
          this.completions.token = {
            start: 0,
            end: cursor.ch,
            string: cm.getLine(cursor.line),
            state: token.state,
            type: null
          };
          await getCompletionsFromImports();
        }
        completeUtilsFunctions(token) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          Object.keys(utils).filter(ea => ea.startsWith(token.string)).forEach(utilFuncName => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            const completion = {
              text: utilFuncName,
              displayText: "util." + utilFuncName,
              hint: (cm, self, data) => {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                var offset = 0;
                cm.replaceRange(utilFuncName + "()", self.from, self.to);
                var lines = cm.getValue().split("\n");
                var imports = lines.filter(ea => ea.match(/^import .*from ['"]utils['"];?/));
                if (!imports.find(ea => ea.match(utilFuncName))) {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  var utils = imports.find(ea => ea.match(/import {.*} from 'utils';/));
                  if (utils) {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    var funcs = utils.replace(/.*{ */, "").replace(/ *}.*/, "").split(/ *, */);
                    funcs.push(utilFuncName);
                    lines = lines.map(ea => ea == utils ? `import { ${funcs.sort().join(", ")} } from 'utils';` : ea);
                    cm.setValue(lines.join("\n"));
                  } else {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    var prefix = `import { ${utilFuncName} } from 'utils';\n`;
                    cm.setValue(prefix + cm.getValue());
                    offset += 1;
                  }
                }
                cm.setCursor({
                  line: self.from.line + offset,
                  ch: self.from.ch + utilFuncName.length + "(".length
                });
              }
            };
            this.completions.maybeAdd(forOrigin(completion, 'utils'));
          });
        }
        completeLively() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const hintTexts = ['lively.', 'gs.'];
          hintTexts.forEach(text => {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            if (['variable', null].includes(this.completions.token.type)) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              this.maybeAdd({
                text,
                hint: (cm, self, data) => {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  cm.replaceRange(text, self.from, self.to);
                  CodeMirror.commands.indentAuto(cm);
                  CodeMirror.commands.autocomplete(cm);
                }
              });
            }
          });
          if (['variable', null].includes(this.completions.token.type)) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            this.maybeAdd({
              text: 'notify',
              render(element, self, data) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                element.append(_element("span", _attributes(), _children(_childText("lively.notify("), _childElement(_element("span", _attributes(_attributeStringLiteral("style", "color: rgba(200, 200, 200, 0.9); display:inline-block; max-width: 50ch;")), _children(_childText("msg")), {
                  file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                  end: {
                    column: 141,
                    line: 578
                  },
                  start: {
                    column: 45,
                    line: 578
                  }
                })), _childText(")")), {
                  file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                  end: {
                    column: 149,
                    line: 578
                  },
                  start: {
                    column: 25,
                    line: 578
                  }
                }));
              },
              hint: (cm, self, data) => {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                cm.replaceRange('lively.notify(', self.from, self.to);
                cm.replaceSelection(')', 'start');
                // cm.replaceSelection('', 'around');
                // cm.replaceRange(text, self.from, self.to);
                CodeMirror.commands.indentAuto(cm);
                CodeMirror.commands.autocomplete(cm);
              }
            });
          }
        }
        completeDoItCommand() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const token = this.completions.token;
          const str = token.string;
          const cm = this.cm;
          var cursor = cm.getCursor();
          if (str.length >= 1 && 'DoItCommand'.startsWith(str)) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            var tprop = token;
            const getToken = cm.getTokenAt.bind(cm);
            if (token.type == "variable") {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              const {
                type,
                string,
                start
              } = getToken(Pos(cursor.line, tprop.start));
              if (type === null && string === ' ') {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                const {
                  type,
                  string
                } = getToken(Pos(cursor.line, start));
                if (type === 'keyword' && string === 'new') {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  this.maybeAdd({
                    text: 'DoItCommand(args)',
                    hint: async (cm, self, data) => {
                      globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                      cm.setSelection(self.from, self.to);
                      cm.replaceSelection(`DoItCommand({
  label: 'DoItCommand',
  do: () => {
    
  },
  undo: () => {
    
  },
  redo: () => {
    
  }
})`, 'around');
                      indentSelections.call(cm);
                      const startLine = cm.getCursor('start').line;
                      cm.setCursor(startLine + 3, Infinity);
                      CodeMirror.commands.autocomplete(cm);
                    }
                  });
                }
              }
            }
          }
        }

        /*MD ## Tern Integration MD*/
        async completeFromTern() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          const lcm = lcmFromCM(this.cm);
          const tw = await lcm.ternWrapper;
          const fileName = lcm.getTargetModule();
          const data = await tw.request({
            query: {
              type: "completions",
              types: true,
              file: fileName,
              end: this.cm.getCursor(),
              depths: true,
              docs: true,
              urls: true,
              origins: true,
              filter: false,
              caseInsensitive: false,
              guess: false,
              sort: false,
              expandWordForward: true,
              omitObjectPrototype: true,
              includeKeywords: false,
              inLiteral: true,
              start: undefined,
              // #TODO: improve by checking for selections first
              lineCharPositions: true
            },
            files: [{
              type: 'full',
              name: fileName,
              text: lcm.value
            }]
          });
          data.completions.map(({
            name,
            type
          }) => forOrigin(type && type !== '?' ? {
            text: name,
            innerRender(element, self, data) {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              element.append(_element("span", _attributes(), _children(_childExpression(name), _childText(" "), _childElement(_element("span", _attributes(_attributeStringLiteral("style", "color: rgba(200, 200, 200, 0.9); display:inline-block; max-width: 50ch;")), _children(_childExpression(type)), {
                file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                end: {
                  column: 135,
                  line: 671
                },
                start: {
                  column: 36,
                  line: 671
                }
              }))), {
                file: 'https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js',
                end: {
                  column: 142,
                  line: 671
                },
                start: {
                  column: 23,
                  line: 671
                }
              }));
            },
            hint: (cm, self, data) => {
              globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
              if (type.startsWith('fn(') && !/^[A-Z]/.test(name)) {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                const parseArgsFromTernType = str => {
                  globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                  const findMatchingParen = (str, start) => {
                    globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                    str = str.substring(start);
                    const matches = [...str.matchAll(/[()]/g)].map(match => ({
                      char: match[0],
                      index: match.index
                    }));
                    let openParens = 1;
                    for (let match of matches) {
                      globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                      const {
                        char,
                        index
                      } = match;
                      if (char === '(') {
                        globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                        openParens++;
                      } else if (char === ')') {
                        globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                        openParens--;
                        if (openParens === 0) {
                          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                          return index + start;
                        }
                      } else {
                        globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                        lively.error(`parseFnFromTern: match ${char} at position ${index} should never happen`);
                      }
                    }
                    return -1;
                  };
                  const start = str.indexOf('(') + 1;
                  const end = findMatchingParen(str, start);
                  const argsString = str.substring(start, end);
                  return argsString.split(', ').map(argWithType => argWithType.replace(/:.*/gm, '').replace(/\?/gm, ''));
                };
                this.completeFunction(cm, self, data, data.text, parseArgsFromTernType(type));
              } else {
                globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
                cm.replaceRange(data.text, self.from, self.to);
              }
              CodeMirror.commands.indentAuto(cm);
            }
          } : name, 'tern')).forEach(this.maybeAdd.bind(this));
        }

        /*MD ## Performing Completions MD*/
        completeFunction(cm, self, data, funcName, args = []) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          cm.replaceRange(funcName + '(', self.from, self.to);
          cm.replaceSelection(')', 'start');
          const [firstArg, ...rest] = args;
          if (rest.length > 0) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            cm.replaceSelection(', ' + rest.join(', '), 'start');
          }
          if (firstArg) {
            globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
            cm.replaceSelection(firstArg, 'around');
          }
        }
      };
      Object.defineProperty(_recorder_._src_components_widgets_lively_code_mirror_hint_js, "CompletionsBuilder", {
        get() {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          return CompletionsBuilder;
        },
        set(thisIsVererySecretVariableName) {
          globalThis.systemActivity["https://lively-kernel.org/lively4/lively4-ansgar/src/components/widgets/lively-code-mirror-hint.js"]++;
          CompletionsBuilder = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      CodeMirror.registerHelper("hint", "javascript", javascriptHint);
    }
  };
});