0.0.11 • Published 6 months ago

codemirror-companion-extension v0.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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

0.0.10

6 months ago

0.0.11

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.3

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.2

1 year ago