codemirror-companion-extension
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

codemirror-companion-extension

This package implements inline suggestions for the CodeMirror code editor. It's a backward-compatible fork of saminzadeh's project that allows the user to display text different than that being accepted, and to instantly trigger the completion function upon accepting the previous completion.

Screenshot

Install

npm install codemirror-companion-extension --save

Usage

Edit codemirror-extension-inline-suggestion

import CodeMirror from '@uiw/react-codemirror';
import { inlineSuggestion } from 'codemirror-companion-extension';

const fetchSuggestion = async (state) => {
  // or make an async API call here based on editor state
  return 'hello';
};

function App() {
  return (
    <CodeMirror
      value=""
      height="200px"
      extensions={[
        inlineSuggestion({
          fetchFn: inlineSuggestion,
          delay: 1000,
          continue_suggesting: true,
        }),
      ]}
    />
  );
}

export default App;

Alternatively, you can use forceableInlineSuggestion to trigger the suggestion forcefully:

export default function App() {
  const { extension, force_fetch } = forceableInlineSuggestion({
    fetchFn: () => 'hello',
    delay: 25000,
    continue_suggesting: true,
  });
  return (
    <>
      <CodeMirror extensions={[extension]} />
      <button onClick={force_fetch}>Generate a completion</button>
    </>
  );
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i codemirror-companion-extension

Weekly Downloads

49

Version

0.0.11

License

MIT

Unpacked Size

48.9 kB

Total Files

21

Last publish

Collaborators

  • rizerphe