Skip to content

Commit

Permalink
fix: only register lg & lu languages once on the monaco instance (#2467)
Browse files Browse the repository at this point in the history
* fix: remove duplicate entries in LgEditor list

* add fix for Lu too

* move changes to languages/*.ts
  • Loading branch information
beyackle authored Apr 1, 2020
1 parent abda9aa commit be2d064
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions Composer/packages/lib/code-editor/src/languages/lg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import { Monaco } from '@monaco-editor/react';

const LANGUAGE_NAME = 'botbuilderlg';

function createKeywordsProposals(monaco: Monaco, range) {
// returning a static list of proposals, not even looking at the prefix (filtering is done by the Monaco editor),
// here you could do a server side lookup
Expand Down Expand Up @@ -42,7 +44,10 @@ function createKeywordsProposals(monaco: Monaco, range) {
}

export function registerLGLanguage(monaco: Monaco) {
monaco.languages.setMonarchTokensProvider('botbuilderlg', {
// return if we've already registered this language to the editor
if (monaco.languages.getLanguages().some(lang => lang.id === LANGUAGE_NAME)) return;

monaco.languages.setMonarchTokensProvider(LANGUAGE_NAME, {
ignoreCase: true,
brackets: [
{ open: '{', close: '}', token: 'delimiter.curly' },
Expand Down Expand Up @@ -120,13 +125,13 @@ export function registerLGLanguage(monaco: Monaco) {
});

monaco.languages.register({
id: 'botbuilderlg',
id: LANGUAGE_NAME,
extensions: ['.lg'],
aliases: ['LG', 'language-generation'],
mimetypes: ['application/lg'],
});

monaco.languages.setLanguageConfiguration('botbuilderlg', {
monaco.languages.setLanguageConfiguration(LANGUAGE_NAME, {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
Expand All @@ -150,7 +155,7 @@ export function registerLGLanguage(monaco: Monaco) {
],
});

monaco.languages.registerCompletionItemProvider('botbuilderlg', {
monaco.languages.registerCompletionItemProvider(LANGUAGE_NAME, {
provideCompletionItems: function(model, position) {
const lineText = model.getValueInRange({
startLineNumber: position.lineNumber,
Expand Down
13 changes: 9 additions & 4 deletions Composer/packages/lib/code-editor/src/languages/lu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

import { Monaco } from '@monaco-editor/react';

const LANGUAGE_NAME = 'lu';

export function registerLULanguage(monaco: Monaco) {
monaco.languages.setMonarchTokensProvider('lu', {
// return if we've already registered this language to the editor
if (monaco.languages.getLanguages().some(lang => lang.id === LANGUAGE_NAME)) return;

monaco.languages.setMonarchTokensProvider(LANGUAGE_NAME, {
tokenizer: {
root: [
[/^\s*#/, { token: 'intent', next: '@intent' }],
Expand Down Expand Up @@ -52,21 +57,21 @@ export function registerLULanguage(monaco: Monaco) {
});

monaco.languages.register({
id: 'lu',
id: LANGUAGE_NAME,
extensions: ['.lu'],
aliases: ['LU', 'language-understanding'],
mimetypes: ['application/lu'],
});

monaco.languages.setLanguageConfiguration('lu', {
monaco.languages.setLanguageConfiguration(LANGUAGE_NAME, {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
],
});

monaco.editor.defineTheme('lu', {
monaco.editor.defineTheme(LANGUAGE_NAME, {
base: 'vs',
inherit: false,
colors: {},
Expand Down

0 comments on commit be2d064

Please sign in to comment.