Adding basic autocompletion

This commit is contained in:
2023-10-29 22:28:55 +01:00
parent b276516a0e
commit dbd77211cb
2 changed files with 27 additions and 2 deletions

View File

@ -34,6 +34,12 @@ import { EditorView } from "codemirror";
import { toposTheme } from "./themes/toposTheme"; import { toposTheme } from "./themes/toposTheme";
import { javascript } from "@codemirror/lang-javascript"; import { javascript } from "@codemirror/lang-javascript";
import { inlineHoveringTips } from "./documentation/inlineHelp"; import { inlineHoveringTips } from "./documentation/inlineHelp";
import { toposCompletions } from "./documentation/inlineHelp";
import { javascriptLanguage } from "@codemirror/lang-javascript"
const jsCompletions = javascriptLanguage.data.of({
autocomplete: toposCompletions
})
export const editorSetup: Extension = (() => [ export const editorSetup: Extension = (() => [
highlightActiveLineGutter(), highlightActiveLineGutter(),
@ -47,8 +53,7 @@ export const editorSetup: Extension = (() => [
bracketMatching(), bracketMatching(),
closeBrackets(), closeBrackets(),
autocompletion(), autocompletion(),
// rectangularSelection(), jsCompletions,
// crosshairCursor(),
highlightActiveLine(), highlightActiveLine(),
highlightSelectionMatches(), highlightSelectionMatches(),
keymap.of([ keymap.of([

View File

@ -1,5 +1,7 @@
import { hoverTooltip } from "@codemirror/view"; import { hoverTooltip } from "@codemirror/view";
import { type EditorView } from "@codemirror/view"; import { type EditorView } from "@codemirror/view";
import { CompletionContext } from "@codemirror/autocomplete"
interface InlineCompletion { interface InlineCompletion {
name: string; name: string;
@ -968,3 +970,21 @@ export const inlineHoveringTips = hoverTooltip(
}; };
} }
); );
export const toposCompletions = (context: CompletionContext) => {
let word = context.matchBefore(/\w*/)
if (word) {
if (word.from == word.to && !context.explicit)
return null
return {
from: word.from,
options: Object.keys(completionDatabase).map((key) => ({
label: key,
type: completionDatabase[key].category,
info: `${completionDatabase[key].description}`,
}))
}
}
}