2021-01-30 07:33:04 +08:00
|
|
|
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";
|
2021-04-21 01:34:17 +08:00
|
|
|
import theme from "./theme";
|
2021-01-30 07:33:04 +08:00
|
|
|
|
|
|
|
// 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
|
2021-04-21 01:34:17 +08:00
|
|
|
monaco.editor.defineTheme("custom", theme);
|
2021-01-30 07:33:04 +08:00
|
|
|
|
2021-03-26 00:39:18 +08:00
|
|
|
// 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(
|
2021-04-13 00:31:10 +08:00
|
|
|
// font-family may be either "JetBrains Mono" or "\"JetBrains Mono\""
|
|
|
|
(fontFace) => fontFace.family.includes("JetBrains Mono")
|
2021-03-26 00:39:18 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-21 01:34:17 +08:00
|
|
|
// 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 [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-01-30 07:33:04 +08:00
|
|
|
export default monaco;
|