mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-17 13:27:50 +08:00
700987dc02
* Implement editor completion for Elixir cells * Add completion tests * Refactor completion * Only extract Markdown docs for now * Fix Elixir version-dependent test * Fix docs matching * Use upcoming Code.cursor_context/2 * Start temporary completion processes under a supervisor * Show Erlang docs in completion items * Update to latest Code.cursor_context * Refactor completion * Fix module completion when alias expands to Erlang module * Remove tests-generated notebook * Show variables and map fields differently * Adjust signatures formatting
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
|
import ElixirLanguageConfiguration from "./elixir/language_configuration";
|
|
import ElixirMonarchLanguage from "./elixir/monarch_language";
|
|
import ElixirOnTypeFormattingEditProvider from "./elixir/on_type_formatting_edit_provider";
|
|
import theme from "./theme";
|
|
|
|
// Register the Elixir language and add relevant configuration
|
|
monaco.languages.register({ id: "elixir" });
|
|
|
|
monaco.languages.setLanguageConfiguration(
|
|
"elixir",
|
|
ElixirLanguageConfiguration
|
|
);
|
|
|
|
monaco.languages.registerOnTypeFormattingEditProvider(
|
|
"elixir",
|
|
ElixirOnTypeFormattingEditProvider
|
|
);
|
|
|
|
monaco.languages.setMonarchTokensProvider("elixir", ElixirMonarchLanguage);
|
|
|
|
// Define custom theme
|
|
monaco.editor.defineTheme("custom", theme);
|
|
|
|
// See https://github.com/microsoft/monaco-editor/issues/648#issuecomment-564978560
|
|
// Without this selecting text with whitespace shrinks the whitespace.
|
|
document.fonts.addEventListener("loadingdone", (event) => {
|
|
const jetBrainsMonoLoaded = event.fontfaces.some(
|
|
// font-family may be either "JetBrains Mono" or "\"JetBrains Mono\""
|
|
(fontFace) => fontFace.family.includes("JetBrains Mono")
|
|
);
|
|
|
|
if (jetBrainsMonoLoaded) {
|
|
// We use JetBrains Mono in all instances of the editor,
|
|
// so we wait until it loads and then tell Monaco to remeasure
|
|
// fonts and updates its cache.
|
|
monaco.editor.remeasureFonts();
|
|
}
|
|
});
|
|
|
|
// Define custom completion provider.
|
|
// In our case the completion behaviour is cell-dependent,
|
|
// so we delegate the implementation to the appropriate cell.
|
|
// See cell/live_editor.js for more details.
|
|
monaco.languages.registerCompletionItemProvider("elixir", {
|
|
provideCompletionItems: (model, position) => {
|
|
if (model.__getCompletionItems) {
|
|
return model.__getCompletionItems(model, position);
|
|
} else {
|
|
return [];
|
|
}
|
|
},
|
|
});
|
|
|
|
export default monaco;
|