Skip to content

Commit

Permalink
JSON 補完機能実装 in js/monaco-editor/json.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2000 committed Mar 27, 2022
1 parent d73e0a5 commit c8b5a5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
36 changes: 32 additions & 4 deletions js/monaco-editor/json/index.js
Expand Up @@ -9,8 +9,36 @@ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
document.body.appendChild(div);
})();

monaco.editor.create(document.getElementById('root'), {
value: `const foo = () => 0;`,
language: 'javascript',
theme: 'vs-dark'
async function init() {

const SCHEMA_URL = './schema/Bookmarks.json';

async function getJsonFromUri(jsonUri) {
const response = await fetch(jsonUri);
const json = await response.json();
return json;
}

const schemaUri = monaco.Uri.parse(SCHEMA_URL);
const schema = await getJsonFromUri(SCHEMA_URL);

monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [
{
uri: schemaUri,
fileMatch: ['*'],
schema: schema
}
]
});

monaco.editor.create(document.getElementById('root'), {
value: "",
language: 'json',
});
}

document.addEventListener('DOMContentLoaded', () => {
init();
});
2 changes: 1 addition & 1 deletion js/monaco-editor/json/webpack.config.js
Expand Up @@ -28,7 +28,7 @@ module.exports = {
},
plugins: [
new MonacoWebpackPlugin({
languages: ['typescript', 'javascript', 'css']
languages: ['json']
})
]
};

0 comments on commit c8b5a5e

Please sign in to comment.