codemirror5-inline-suggestion

1.0.2 • Public • Published

codemirror5-inline-suggestion

An extension to display inline suggestion in CodeMirror v5

Installation

# via NPM
npm install codemirror5-inline-suggestion

# via Yarn
yarn add codemirror5-inline-suggestion

Usage

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.18/codemirror.min.css"
    />
  </head>
  <body>
    <textarea></textarea>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.18/codemirror.min.js"></script>
    <script src="node_modules/codemirror5-inline-suggestion/index.js"></script>
    <script>
      const editor = CodeMirror.fromTextArea(
        document.querySelector("textarea"),
        {
          lineNumbers: true,
          async inlineSuggestionRequestFn(textBefore, textAfter) {
            const content = `You are a programmer that replaces <FILL_ME> part with the right code. Only output the code that replaces <FILL_ME> part. Do not add any explanation or markdown. ${textBefore}<FILL_ME>${textAfter}`;
            const result = await fetch("<YOUR_AI_URL>", {
              method: "POST",
              body: JSON.stringify({ role: "user", content }),
            }).then((response) => response.json());
            return result.message;
          },
        },
      );
    </script>
  </body>
</html>

Package Sidebar

Install

npm i codemirror5-inline-suggestion

Weekly Downloads

6

Version

1.0.2

License

MIT

Unpacked Size

7.06 kB

Total Files

6

Last publish

Collaborators

  • azmy60