Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full autocomplete #2

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@

# codemirror-pluto-setup


[Pluto](https://github.com/fonsp/Pluto.jl) uses the awesome codemirror 6, but Pluto is 'buildelss', which means that we need to import dependencies directly from the jsdelivr CDN. Codemirror 6 is not meant to work in this setup. Using tools such as https://esm.sh/ , https://www.jsdelivr.com/esm or https://www.skypack.dev/ does not work in our case, because:

- downstream dependencies cannot be version-pinned easily. For pluto we want to version-pin everything.
- the modular design of codemirror 6 requires multiple modules to use the same version/instance of shared dependencies, such as `@codemirror/state`. This is hard/impossible with ES building CDNs.

This is why we have this repository to manage our dependencies and to export a single `.es.js` and `.d.ts` file.


# How to update

1. `npm install`
1. Change the `index.ts` file.
1. Change the `basic-setup.ts` file.
1. `npm run bundle`


# How to release and update pluto

1. `npm run bundle`
2. Change the `package.json` patch version number +1
2. Change the `package.json` patch version number +1 (`npm version patch`)
3. git commit etc
4. Go here: https://github.com/JuliaPluto/codemirror-pluto-setup/releases/new
5. For tag name, type in the new version number (without `v`) and select "create new tag on publish"
6. Type version name (without `v`) as release title
7. Release
8. In Pluto: update `frontend/imports/CodemirrorPlutoSetup.js` with the new version number.
8. Copy the contents of `dist/index.d.ts` and In Pluto: paste into `frontend/imports/CodemirrorPlutoSetup.d.ts`. Save without formatting.
9. git commit etc
9. Copy the contents of `dist/index.d.ts` and In Pluto: paste into `frontend/imports/CodemirrorPlutoSetup.d.ts`. Save without formatting.
10. git commit etc

## To test something inside pluto without publishing a version:

1. `npm run bundle` and commit to a new branch. Get the commit hash, e.g. `bab65fc`
2. In Pluto, use the commit hash as your version number, e.g.
2. In Pluto, use the commit hash as your version number, e.g.

```js
import { ... } from "https://cdn.jsdelivr.net/gh/JuliaPluto/codemirror-pluto-setup@bab65fc/dist/index.es.min.js"
Expand Down
172 changes: 171 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4491,6 +4491,21 @@ declare class CompletionContext {
addEventListener(type: "abort", listener: () => void): void;
}
/**
Given a a fixed array of options, return an autocompleter that
completes them.
*/
declare function completeFromList(list: readonly (string | Completion)[]): CompletionSource;
/**
Wrap the given completion source so that it will only fire when the
cursor is in a syntax node with one of the given names.
*/
declare function ifIn(nodes: readonly string[], source: CompletionSource): CompletionSource;
/**
Wrap the given completion source so that it will not fire when the
cursor is in a syntax node with one of the given names.
*/
declare function ifNotIn(nodes: readonly string[], source: CompletionSource): CompletionSource;
/**
The function signature for a completion source. Such a function
may return its [result](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult)
synchronously or as a promise. Returning null indicates no
Expand Down Expand Up @@ -4536,6 +4551,92 @@ interface CompletionResult {
*/
filter?: boolean;
}
/**
This annotation is added to transactions that are produced by
picking a completion.
*/
declare const pickedCompletion: AnnotationType<Completion>;

/**
Convert a snippet template to a function that can apply it.
Snippets are written using syntax like this:

"for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"

Each `${}` placeholder (you may also use `#{}`) indicates a field
that the user can fill in. Its name, if any, will be the default
content for the field.

When the snippet is activated by calling the returned function,
the code is inserted at the given position. Newlines in the
template are indented by the indentation of the start line, plus
one [indent unit](https://codemirror.net/6/docs/ref/#language.indentUnit) per tab character after
the newline.

On activation, (all instances of) the first field are selected.
The user can move between fields with Tab and Shift-Tab as long as
the fields are active. Moving to the last field or moving the
cursor out of the current field deactivates the fields.

The order of fields defaults to textual order, but you can add
numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
a custom order.
*/
declare function snippet(template: string): (editor: {
state: EditorState;
dispatch: (tr: Transaction) => void;
}, _completion: Completion, from: number, to: number) => void;
/**
A command that clears the active snippet, if any.
*/
declare const clearSnippet: StateCommand;
/**
Move to the next snippet field, if available.
*/
declare const nextSnippetField: StateCommand;
/**
Move to the previous snippet field, if available.
*/
declare const prevSnippetField: StateCommand;
/**
A facet that can be used to configure the key bindings used by
snippets. The default binds Tab to
[`nextSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.nextSnippetField), Shift-Tab to
[`prevSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.prevSnippetField), and Escape
to [`clearSnippet`](https://codemirror.net/6/docs/ref/#autocomplete.clearSnippet).
*/
declare const snippetKeymap: Facet<readonly KeyBinding[], readonly KeyBinding[]>;
/**
Create a completion from a snippet. Returns an object with the
properties from `completion`, plus an `apply` function that
applies the snippet.
*/
declare function snippetCompletion(template: string, completion: Completion): Completion;

/**
Returns a command that moves the completion selection forward or
backward by the given amount.
*/
declare function moveCompletionSelection(forward: boolean, by?: "option" | "page"): Command;
/**
Accept the current completion.
*/
declare const acceptCompletion: Command;
/**
Explicitly start autocompletion.
*/
declare const startCompletion: Command;
/**
Close the currently active completion.
*/
declare const closeCompletion: Command;

/**
A completion source that will scan the document for words (using a
[character categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer)), and
return those as completions.
*/
declare const completeAnyWord: CompletionSource;

/**
Returns an extension that enables autocompletion.
Expand All @@ -4553,6 +4654,75 @@ Basic keybindings for autocompletion.
- Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
*/
declare const completionKeymap: readonly KeyBinding[];
/**
Get the current completion status. When completions are available,
this will return `"active"`. When completions are pending (in the
process of being queried), this returns `"pending"`. Otherwise, it
returns `null`.
*/
declare function completionStatus(state: EditorState): null | "active" | "pending";
/**
Returns the available completions as an array.
*/
declare function currentCompletions(state: EditorState): readonly Completion[];
/**
Return the currently selected completion, if any.
*/
declare function selectedCompletion(state: EditorState): Completion | null;

type index_Completion = Completion;
type index_CompletionContext = CompletionContext;
declare const index_CompletionContext: typeof CompletionContext;
type index_CompletionResult = CompletionResult;
type index_CompletionSource = CompletionSource;
declare const index_acceptCompletion: typeof acceptCompletion;
declare const index_autocompletion: typeof autocompletion;
declare const index_clearSnippet: typeof clearSnippet;
declare const index_closeCompletion: typeof closeCompletion;
declare const index_completeAnyWord: typeof completeAnyWord;
declare const index_completeFromList: typeof completeFromList;
declare const index_completionKeymap: typeof completionKeymap;
declare const index_completionStatus: typeof completionStatus;
declare const index_currentCompletions: typeof currentCompletions;
declare const index_ifIn: typeof ifIn;
declare const index_ifNotIn: typeof ifNotIn;
declare const index_moveCompletionSelection: typeof moveCompletionSelection;
declare const index_nextSnippetField: typeof nextSnippetField;
declare const index_pickedCompletion: typeof pickedCompletion;
declare const index_prevSnippetField: typeof prevSnippetField;
declare const index_selectedCompletion: typeof selectedCompletion;
declare const index_snippet: typeof snippet;
declare const index_snippetCompletion: typeof snippetCompletion;
declare const index_snippetKeymap: typeof snippetKeymap;
declare const index_startCompletion: typeof startCompletion;
declare namespace index {
export {
index_Completion as Completion,
index_CompletionContext as CompletionContext,
index_CompletionResult as CompletionResult,
index_CompletionSource as CompletionSource,
index_acceptCompletion as acceptCompletion,
index_autocompletion as autocompletion,
index_clearSnippet as clearSnippet,
index_closeCompletion as closeCompletion,
index_completeAnyWord as completeAnyWord,
index_completeFromList as completeFromList,
index_completionKeymap as completionKeymap,
index_completionStatus as completionStatus,
index_currentCompletions as currentCompletions,
index_ifIn as ifIn,
index_ifNotIn as ifNotIn,
index_moveCompletionSelection as moveCompletionSelection,
index_nextSnippetField as nextSnippetField,
index_pickedCompletion as pickedCompletion,
index_prevSnippetField as prevSnippetField,
index_selectedCompletion as selectedCompletion,
index_snippet as snippet,
index_snippetCompletion as snippetCompletion,
index_snippetKeymap as snippetKeymap,
index_startCompletion as startCompletion,
};
}

declare type HighlightOptions = {
/**
Expand Down Expand Up @@ -4939,4 +5109,4 @@ Create an instance of the collaborative editing plugin.
*/
declare function collab(config?: CollabConfig): Extension;

export { Annotation, Compartment, Decoration, EditorSelection, EditorState, EditorView, Facet, HighlightStyle, NodeProp, PostgreSQL, SelectionRange, StateEffect, StateField, StreamLanguage, Text, Transaction, TreeCursor, ViewPlugin, ViewUpdate, WidgetType, autocompletion, bracketMatching, closeBrackets, closeBracketsKeymap, collab, combineConfig, commentKeymap, completionKeymap, defaultHighlightStyle, defaultKeymap, drawSelection, foldGutter, foldKeymap, highlightSelectionMatches, highlightSpecialChars, history, historyKeymap, html, htmlLanguage, indentLess, indentMore, indentOnInput, indentUnit, javascript, javascriptLanguage, julia as julia_andrey, julia$1 as julia_legacy, keymap, lineNumbers, markdown, markdownLanguage, parseMixed, placeholder, python, pythonLanguage, rectangularSelection, searchKeymap, sql, syntaxTree, tags };
export { Annotation, Compartment, Decoration, EditorSelection, EditorState, EditorView, Facet, HighlightStyle, NodeProp, PostgreSQL, SelectionRange, StateEffect, StateField, StreamLanguage, Text, Transaction, TreeCursor, ViewPlugin, ViewUpdate, WidgetType, index as autocomplete, bracketMatching, closeBrackets, closeBracketsKeymap, collab, combineConfig, commentKeymap, completionKeymap, defaultHighlightStyle, defaultKeymap, drawSelection, foldGutter, foldKeymap, highlightSelectionMatches, highlightSpecialChars, history, historyKeymap, html, htmlLanguage, indentLess, indentMore, indentOnInput, indentUnit, javascript, javascriptLanguage, julia as julia_andrey, julia$1 as julia_legacy, keymap, lineNumbers, markdown, markdownLanguage, parseMixed, placeholder, python, pythonLanguage, rectangularSelection, searchKeymap, sql, syntaxTree, tags };
Loading