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

Add json worker to monaco editor #3424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fba9d11
feat: add json worker and language implement in dashboards
SuZhou-Joe Dec 23, 2022
48d3a91
feat: update changelog
SuZhou-Joe Dec 28, 2022
a3a9e1d
feat: reorder the import expression
SuZhou-Joe Dec 28, 2022
a85485c
feat: update
SuZhou-Joe Dec 28, 2022
e4c4d29
feat: update
SuZhou-Joe Dec 30, 2022
2d311f6
feat: add example for json language
SuZhou-Joe Jan 9, 2023
06ac508
feat: remove external link comment
SuZhou-Joe Jan 9, 2023
c225d1d
feat: modify uri
SuZhou-Joe Jan 10, 2023
f29b55f
Merge branch 'main' into main
SuZhou-Joe Jan 10, 2023
ffe75ca
feat: switch to new license header
SuZhou-Joe Jan 10, 2023
095e493
Merge branch 'main' into main
SuZhou-Joe Jan 10, 2023
c6d5f85
feat: add package @osd/monaco-next
SuZhou-Joe Feb 14, 2023
831bbb9
feat: make smaller changes
SuZhou-Joe Feb 14, 2023
636adc3
feat: update CHANGELOG.md
SuZhou-Joe Feb 14, 2023
2798a58
Merge branch 'main' into feature/alias-monaco-next
SuZhou-Joe Feb 14, 2023
3b087fe
feat: update
SuZhou-Joe Feb 15, 2023
d80b42e
feat: remve useless code change
SuZhou-Joe Feb 15, 2023
314d897
feat: modify changelog
SuZhou-Joe Feb 15, 2023
4a0f855
Merge branch 'main' into feature/alias-monaco-next
SuZhou-Joe Feb 16, 2023
e009f2b
Merge branch 'main' into feature/alias-monaco-next
SuZhou-Joe Feb 17, 2023
2cb7910
feat: some changes after code review
SuZhou-Joe Feb 18, 2023
a7189c5
Merge branch 'main' into feature/alias-monaco-next
SuZhou-Joe Feb 19, 2023
4edbed9
feat: modify README
SuZhou-Joe Feb 20, 2023
cf47b3c
Merge branch 'main' into feature/alias-monaco-next
ananzh Feb 20, 2023
7205379
Update packages/osd-monaco/README.md
SuZhou-Joe Feb 20, 2023
823d1d2
Update CHANGELOG.md
SuZhou-Joe Feb 20, 2023
0661707
Update packages/osd-monaco/src/xjson/README.md
SuZhou-Joe Feb 20, 2023
95cfb9c
Merge branch 'main' into feature/alias-monaco-next
SuZhou-Joe Feb 21, 2023
88b5159
Merge branch 'main' into feature/alias-monaco-next
ananzh Feb 21, 2023
e86afbf
Merge branch 'main' into feature/alias-monaco-next
SuZhou-Joe Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multi DataSource] UX enhacement on index pattern management stack ([#2505](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2505))
- [Multi DataSource] UX enhancement on Data source management stack ([#2521](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2521))
- [Multi DataSource] UX enhancement on Update stored password modal for Data source management stack ([#2532](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2532))
- [Monaco editor] Add json worker support ([#3424](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3424))

### 🐛 Bug Fixes

Expand Down
4 changes: 3 additions & 1 deletion packages/osd-monaco/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

A customized version of monaco that is automatically configured the way we want it to be when imported as `@osd/monaco`. Additionally, imports to this package are automatically shared with all plugins using `@osd/ui-shared-deps`.

Includes custom xjson language support. The `opensearch_ui_shared` plugin has an example of how to use it, in the future we will likely expose helpers from this package to make using it everywhere a little more seamless.
Includes custom xjson language support. The `opensearch_ui_shared` plugin has an example of how to use it, in the future we will likely expose helpers from this package to make using it everywhere a little more seamless.

Includes json language worker support.
3 changes: 3 additions & 0 deletions packages/osd-monaco/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@

export { monaco } from './monaco';
export { XJsonLang } from './xjson';
import './json';

/* eslint-disable-next-line @osd/eslint/module_migration */
import * as BarePluginApi from 'monaco-editor/esm/vs/editor/editor.api';
export { BarePluginApi };
import './monaco_environment';
export * from './worker_store';
10 changes: 10 additions & 0 deletions packages/osd-monaco/src/json/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { registerWorker } from '../worker_store';
// @ts-ignore
import jsonWorkerSrc from '!!raw-loader!../../target/public/json.editor.worker.js';

registerWorker('json', jsonWorkerSrc);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with the worker proxy service - but why did you choose not to use it for json?

8 changes: 8 additions & 0 deletions packages/osd-monaco/src/json/worker/json.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

// @ts-ignore
/* eslint-disable-next-line @osd/eslint/module_migration */
import 'monaco-editor/esm/vs/language/json/json.worker.js';
17 changes: 17 additions & 0 deletions packages/osd-monaco/src/monaco_environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { getWorker } from './worker_store';

// @ts-ignore
window.MonacoEnvironment = {
getWorker: (module: string, languageId: string) => {
const workerSrc = getWorker(languageId);
if (workerSrc) {
const blob = new Blob([workerSrc], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob));
}
},
};
19 changes: 19 additions & 0 deletions packages/osd-monaco/src/worker_store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

const workerStoreMap: Record<string, string> = {};

export const registerWorker = (workerId: string, worker: string) => {
if (!workerStoreMap[workerId]) {
workerStoreMap[workerId] = worker;
return true;
}

return false;
};

export const getWorker = (workerId: string) => {
return workerStoreMap[workerId];
};
16 changes: 3 additions & 13 deletions packages/osd-monaco/src/xjson/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { monaco } from '../monaco';
import { WorkerProxyService } from './worker_proxy_service';
import { registerLexerRules } from './lexer_rules';
import { ID } from './constants';
import { registerWorker } from '../worker_store';
// @ts-ignore
import workerSrc from '!!raw-loader!../../target/public/xjson.editor.worker.js';

Expand All @@ -42,19 +43,8 @@ const wps = new WorkerProxyService();
// Register rules against shared monaco instance.
registerLexerRules(monaco);

// In future we will need to make this map languages to workers using "id" and/or "label" values
// that get passed in. Also this should not live inside the "xjson" dir directly. We can update this
// once we have another worker.
// @ts-ignore
window.MonacoEnvironment = {
getWorker: (module: string, languageId: string) => {
joshuarrrr marked this conversation as resolved.
Show resolved Hide resolved
if (languageId === ID) {
// In OpenSearch Dashboards we will probably build this once and then load with raw-loader
const blob = new Blob([workerSrc], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob));
}
},
};
// register xjson worker to the worker map.
registerWorker(ID, workerSrc);

monaco.languages.onLanguage(ID, async () => {
return wps.setup();
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-monaco/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ const createLangWorkerConfig = (lang) => ({
},
});

module.exports = [createLangWorkerConfig('xjson')];
module.exports = [createLangWorkerConfig('xjson'), createLangWorkerConfig('json')];