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

Feat: autocomplete #2144

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

youknowedo
Copy link
Contributor

Added autocomplete to the web editor. Uses the default CodeMirror JavaScript autocomplete with some custom completions for Sprig-specific functions. It also includes tooltips that show the documentation for that function imported from the docs.

Copy link

vercel bot commented Aug 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sprig ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 9:55pm

@youknowedo
Copy link
Contributor Author

Currently reads the docs, puts it inside an HTMLElements innerHTML, and then reads the innerHTML again. This is because the regex seemed to have problems with the Unicode characters the "compiled content" would give. Feel free to change it since there must be a more efficient way to do this, I just haven't figured it out yet.

@recursiveforte recursiveforte self-requested a review August 19, 2024 18:28
Copy link
Contributor

@JosiasAurel JosiasAurel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the way the completion looks. However it might break if the documentation doc changes.
Now that the Sprig engine is in the sprig repository, it might be better to generate completion from the [exposed engine API].(

const api: BaseEngineAPI = {
)

Comment on lines +1 to +45
import { autocompletion } from "@codemirror/autocomplete";
import {
defaultKeymap,
history,
historyKeymap,
indentWithTab,
insertNewlineAndIndent,
} from "@codemirror/commands";
import { javascript } from "@codemirror/lang-javascript";
import {
bracketMatching,
defaultHighlightStyle,
foldGutter,
foldKeymap,
indentOnInput,
indentUnit,
syntaxHighlighting,
} from "@codemirror/language";
import { lintGutter } from "@codemirror/lint";
import type { NormalizedError } from '../state'
import {
getSearchQuery,
highlightSelectionMatches,
search,
searchKeymap,
setSearchQuery,
} from "@codemirror/search";
import { EditorState } from "@codemirror/state";
import {
crosshairCursor,
drawSelection,
dropCursor,
EditorView,
highlightActiveLine,
highlightActiveLineGutter,
highlightSpecialChars,
keymap,
lineNumbers,
rectangularSelection,
} from "@codemirror/view";
import { effect, signal } from "@preact/signals";
import { h, render } from "preact";
import SearchBox from "../../components/search-box";
import type { NormalizedError } from "../state";
import { sprigFunctionCompletion } from "./autocomplete";
import widgets from "./widgets";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally good to avoid formatting changes in a PR as it makes it hard to read the diff. Can you undo the formatting here?

Comment on lines +122 to +134
const iter = query.value.getCursor(update.state);
for (
let item = iter.next();
!item.done;
item = iter.next()
) {
count++;
if (
item.value.from <=
update.state.selection.main.from &&
item.value.to >= update.state.selection.main.to
)
index = count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo the formatting changes. It makes it hard to read what has actually changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants