mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
Adopt new scripts in monaco-json
This commit is contained in:
parent
94ca41beeb
commit
bc3274a7c8
8 changed files with 108 additions and 136 deletions
|
|
@ -10,30 +10,14 @@ JSON language plugin for the Monaco Editor. It provides the following features w
|
||||||
- Syntax highlighting
|
- Syntax highlighting
|
||||||
- Color decorators for all properties matching a schema containing `format: "color-hex"'` (non-standard schema extension)
|
- Color decorators for all properties matching a schema containing `format: "color-hex"'` (non-standard schema extension)
|
||||||
|
|
||||||
Schemas can be provided by configuration. See [here](https://github.com/Microsoft/monaco-json/blob/master/monaco.d.ts)
|
Schemas can be provided by configuration. See [`monaco.d.ts`](./monaco.d.ts)
|
||||||
for the API that the JSON plugin offers to configure the JSON language support.
|
for the API that the JSON plugin offers to configure the JSON language support.
|
||||||
|
|
||||||
Internally the JSON plugin uses the [vscode-json-languageservice](https://github.com/Microsoft/vscode-json-languageservice)
|
Internally the JSON plugin uses the [`vscode-json-languageservice`](https://github.com/microsoft/vscode-json-languageservice)
|
||||||
node module, providing the implementation of the features listed above. The same module is also used
|
node module, providing the implementation of the features listed above. The same module is also used
|
||||||
in [Visual Studio Code](https://github.com/Microsoft/vscode) to power the JSON editing experience.
|
in [Visual Studio Code](https://github.com/microsoft/vscode) to power the JSON editing experience.
|
||||||
|
|
||||||
## Issues
|
|
||||||
|
|
||||||
Please file issues concerning `monaco-json` in the [`monaco-editor` repository](https://github.com/Microsoft/monaco-editor/issues).
|
|
||||||
|
|
||||||
## Installing
|
|
||||||
|
|
||||||
This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module.
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
- `git clone https://github.com/Microsoft/monaco-json`
|
|
||||||
- `npm install .`
|
|
||||||
- compile with `npm run compile`
|
|
||||||
- watch with `npm run watch`
|
- watch with `npm run watch`
|
||||||
- `npm run prepublishOnly`
|
- compile with `npm run prepublishOnly`
|
||||||
- open `$/monaco-json/test/index.html` in your favorite browser.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
[MIT](https://github.com/Microsoft/monaco-json/blob/master/LICENSE.md)
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"compile": "../node_modules/.bin/mrmdir ./out && ../node_modules/.bin/tsc -p ./src/tsconfig.json && ../node_modules/.bin/tsc -p ./src/tsconfig.esm.json && node ./scripts/dts && ../node_modules/.bin/prettier --write ./monaco.d.ts",
|
|
||||||
"watch": "../node_modules/.bin/tsc -p ./src --watch",
|
"watch": "../node_modules/.bin/tsc -p ./src --watch",
|
||||||
"prepublishOnly": "../node_modules/.bin/mrmdir ./release && npm run compile && node ./scripts/release.js && node ./scripts/bundle && ../node_modules/.bin/mcopy ./out/esm/monaco.contribution.d.ts ./release/esm/monaco.contribution.d.ts && ../node_modules/.bin/mcopy ./out/esm/fillers/monaco-editor-core.d.ts ./release/esm/fillers/monaco-editor-core.d.ts"
|
"prepublishOnly": "node ./scripts/build"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
monaco-json/scripts/build.js
Normal file
43
monaco-json/scripts/build.js
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
const esbuild = require('esbuild');
|
||||||
|
const alias = require('esbuild-plugin-alias');
|
||||||
|
const path = require('path');
|
||||||
|
const cp = require('child_process');
|
||||||
|
const { copyFile, removeDir, tsc, dts } = require('../../build/utils');
|
||||||
|
|
||||||
|
removeDir(`monaco-json/release`);
|
||||||
|
removeDir(`monaco-json/out`);
|
||||||
|
|
||||||
|
tsc(`monaco-json/src/tsconfig.json`);
|
||||||
|
|
||||||
|
dts(`monaco-json/out/amd/monaco.contribution.d.ts`, `monaco-json/monaco.d.ts`, 'monaco.languages.json');
|
||||||
|
|
||||||
|
esbuild.build({
|
||||||
|
entryPoints: ['src/jsonMode.ts', 'src/json.worker.ts', 'src/monaco.contribution.ts'],
|
||||||
|
bundle: true,
|
||||||
|
target: 'esnext',
|
||||||
|
format: 'esm',
|
||||||
|
external: ['monaco-editor-core', '*/jsonMode'],
|
||||||
|
outdir: 'release/esm/',
|
||||||
|
plugins: [
|
||||||
|
alias({
|
||||||
|
'vscode-nls': path.join(__dirname, '../src/fillers/vscode-nls.ts'),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.errors.length > 0) {
|
||||||
|
console.error(result.errors);
|
||||||
|
}
|
||||||
|
if (result.warnings.length > 0) {
|
||||||
|
console.error(result.warnings);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
copyFile('monaco-json/out/amd/monaco.contribution.d.ts', 'monaco-json/release/esm/monaco.contribution.d.ts');
|
||||||
|
copyFile('monaco-json/out/amd/fillers/monaco-editor-core.d.ts', 'monaco-json/release/esm/fillers/monaco-editor-core.d.ts');
|
||||||
|
|
||||||
|
cp.spawnSync(process.execPath, [path.join(__dirname, './bundle.js')], { stdio: 'inherit', stderr: 'inherit' });
|
||||||
|
|
@ -1,24 +1,17 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
const requirejs = require('requirejs');
|
const requirejs = require('requirejs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const Terser = require('terser');
|
const terser = require('terser');
|
||||||
const helpers = require('monaco-plugin-helpers');
|
const { getBundledFileHeader } = require('../../build/utils');
|
||||||
|
|
||||||
const REPO_ROOT = path.resolve(__dirname, '..', '..');
|
const REPO_ROOT = path.resolve(__dirname, '..', '..');
|
||||||
|
|
||||||
const sha1 = helpers.getGitVersion(REPO_ROOT);
|
const BUNDLED_FILE_HEADER = getBundledFileHeader();
|
||||||
const semver = require('../../package.json').version;
|
|
||||||
const headerVersion = semver + '(' + sha1 + ')';
|
|
||||||
|
|
||||||
const BUNDLED_FILE_HEADER = [
|
|
||||||
'/*!-----------------------------------------------------------------------------',
|
|
||||||
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
|
||||||
' * monaco-json version: ' + headerVersion,
|
|
||||||
' * Released under the MIT license',
|
|
||||||
' * https://github.com/Microsoft/monaco-json/blob/master/LICENSE.md',
|
|
||||||
' *-----------------------------------------------------------------------------*/',
|
|
||||||
''
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
bundleOne('monaco.contribution');
|
bundleOne('monaco.contribution');
|
||||||
bundleOne('jsonMode', ['vs/language/json/monaco.contribution']);
|
bundleOne('jsonMode', ['vs/language/json/monaco.contribution']);
|
||||||
|
|
@ -74,8 +67,9 @@ function bundleOne(moduleId, exclude) {
|
||||||
const devFilePath = path.join(REPO_ROOT, 'monaco-json/release/dev/' + moduleId + '.js');
|
const devFilePath = path.join(REPO_ROOT, 'monaco-json/release/dev/' + moduleId + '.js');
|
||||||
const minFilePath = path.join(REPO_ROOT, 'monaco-json/release/min/' + moduleId + '.js');
|
const minFilePath = path.join(REPO_ROOT, 'monaco-json/release/min/' + moduleId + '.js');
|
||||||
const fileContents = fs.readFileSync(devFilePath).toString();
|
const fileContents = fs.readFileSync(devFilePath).toString();
|
||||||
|
console.log();
|
||||||
console.log(`Minifying ${devFilePath}...`);
|
console.log(`Minifying ${devFilePath}...`);
|
||||||
const result = await Terser.minify(fileContents, {
|
const result = await terser.minify(fileContents, {
|
||||||
output: {
|
output: {
|
||||||
comments: 'some'
|
comments: 'some'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/*---------------------------------------------------------------------------------------------
|
|
||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
||||||
*--------------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const REPO_ROOT = path.join(__dirname, '../');
|
|
||||||
const SRC_PATH = path.join(REPO_ROOT, 'out/amd/monaco.contribution.d.ts');
|
|
||||||
const DST_PATH = path.join(REPO_ROOT, 'monaco.d.ts');
|
|
||||||
|
|
||||||
const lines = fs
|
|
||||||
.readFileSync(SRC_PATH)
|
|
||||||
.toString()
|
|
||||||
.split(/\r\n|\r|\n/);
|
|
||||||
let result = [
|
|
||||||
`/*---------------------------------------------------------------------------------------------`,
|
|
||||||
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
|
|
||||||
` * Licensed under the MIT License. See License.txt in the project root for license information.`,
|
|
||||||
` *--------------------------------------------------------------------------------------------*/`,
|
|
||||||
``,
|
|
||||||
`/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />`,
|
|
||||||
``,
|
|
||||||
`declare namespace monaco.languages.json {`
|
|
||||||
];
|
|
||||||
for (let line of lines) {
|
|
||||||
if (/^import/.test(line)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
line = line.replace(/ /g, '\t');
|
|
||||||
line = line.replace(/declare /g, '');
|
|
||||||
if (line.length > 0) {
|
|
||||||
line = `\t${line}`;
|
|
||||||
result.push(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.push(`}`);
|
|
||||||
result.push(``);
|
|
||||||
|
|
||||||
fs.writeFileSync(DST_PATH, result.join('\n'));
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/*---------------------------------------------------------------------------------------------
|
|
||||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
||||||
*--------------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const helpers = require('monaco-plugin-helpers');
|
|
||||||
|
|
||||||
const REPO_ROOT = path.join(__dirname, '../../');
|
|
||||||
|
|
||||||
helpers.packageESM({
|
|
||||||
repoRoot: REPO_ROOT,
|
|
||||||
esmSource: 'monaco-json/out/esm',
|
|
||||||
esmDestination: 'monaco-json/release/esm',
|
|
||||||
entryPoints: ['monaco.contribution.js', 'jsonMode.js', 'json.worker.js'],
|
|
||||||
resolveAlias: {
|
|
||||||
'vscode-nls': path.join(REPO_ROOT, 'monaco-json/out/esm/fillers/vscode-nls.js')
|
|
||||||
},
|
|
||||||
resolveSkip: ['monaco-editor-core'],
|
|
||||||
destinationFolderSimplification: {
|
|
||||||
node_modules: '_deps',
|
|
||||||
'jsonc-parser/lib/esm': 'jsonc-parser',
|
|
||||||
'vscode-languageserver-types/lib/esm': 'vscode-languageserver-types',
|
|
||||||
'vscode-uri/lib/esm': 'vscode-uri',
|
|
||||||
'vscode-json-languageservice/lib/esm': 'vscode-json-languageservice'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -69,13 +69,13 @@ class ParentsStack {
|
||||||
class JSONState implements languages.IState {
|
class JSONState implements languages.IState {
|
||||||
private _state: languages.IState;
|
private _state: languages.IState;
|
||||||
|
|
||||||
public scanError: json.ScanError;
|
public scanError: ScanError;
|
||||||
public lastWasColon: boolean;
|
public lastWasColon: boolean;
|
||||||
public parents: ParentsStack | null;
|
public parents: ParentsStack | null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
state: languages.IState,
|
state: languages.IState,
|
||||||
scanError: json.ScanError,
|
scanError: ScanError,
|
||||||
lastWasColon: boolean,
|
lastWasColon: boolean,
|
||||||
parents: ParentsStack | null
|
parents: ParentsStack | null
|
||||||
) {
|
) {
|
||||||
|
|
@ -112,6 +112,36 @@ class JSONState implements languages.IState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const enum ScanError {
|
||||||
|
None = 0,
|
||||||
|
UnexpectedEndOfComment = 1,
|
||||||
|
UnexpectedEndOfString = 2,
|
||||||
|
UnexpectedEndOfNumber = 3,
|
||||||
|
InvalidUnicode = 4,
|
||||||
|
InvalidEscapeCharacter = 5,
|
||||||
|
InvalidCharacter = 6
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum SyntaxKind {
|
||||||
|
OpenBraceToken = 1,
|
||||||
|
CloseBraceToken = 2,
|
||||||
|
OpenBracketToken = 3,
|
||||||
|
CloseBracketToken = 4,
|
||||||
|
CommaToken = 5,
|
||||||
|
ColonToken = 6,
|
||||||
|
NullKeyword = 7,
|
||||||
|
TrueKeyword = 8,
|
||||||
|
FalseKeyword = 9,
|
||||||
|
StringLiteral = 10,
|
||||||
|
NumericLiteral = 11,
|
||||||
|
LineCommentTrivia = 12,
|
||||||
|
BlockCommentTrivia = 13,
|
||||||
|
LineBreakTrivia = 14,
|
||||||
|
Trivia = 15,
|
||||||
|
Unknown = 16,
|
||||||
|
EOF = 17
|
||||||
|
}
|
||||||
|
|
||||||
function tokenize(
|
function tokenize(
|
||||||
comments: boolean,
|
comments: boolean,
|
||||||
line: string,
|
line: string,
|
||||||
|
|
@ -124,11 +154,11 @@ function tokenize(
|
||||||
let adjustOffset = false;
|
let adjustOffset = false;
|
||||||
|
|
||||||
switch (state.scanError) {
|
switch (state.scanError) {
|
||||||
case json.ScanError.UnexpectedEndOfString:
|
case ScanError.UnexpectedEndOfString:
|
||||||
line = '"' + line;
|
line = '"' + line;
|
||||||
numberOfInsertedCharacters = 1;
|
numberOfInsertedCharacters = 1;
|
||||||
break;
|
break;
|
||||||
case json.ScanError.UnexpectedEndOfComment:
|
case ScanError.UnexpectedEndOfComment:
|
||||||
line = '/*' + line;
|
line = '/*' + line;
|
||||||
numberOfInsertedCharacters = 2;
|
numberOfInsertedCharacters = 2;
|
||||||
break;
|
break;
|
||||||
|
|
@ -147,8 +177,8 @@ function tokenize(
|
||||||
let offset = offsetDelta + scanner.getPosition();
|
let offset = offsetDelta + scanner.getPosition();
|
||||||
let type = '';
|
let type = '';
|
||||||
|
|
||||||
const kind = scanner.scan();
|
const kind = <SyntaxKind><any>scanner.scan();
|
||||||
if (kind === json.SyntaxKind.EOF) {
|
if (kind === SyntaxKind.EOF) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,50 +198,50 @@ function tokenize(
|
||||||
|
|
||||||
// brackets and type
|
// brackets and type
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case json.SyntaxKind.OpenBraceToken:
|
case SyntaxKind.OpenBraceToken:
|
||||||
parents = ParentsStack.push(parents, JSONParent.Object);
|
parents = ParentsStack.push(parents, JSONParent.Object);
|
||||||
type = TOKEN_DELIM_OBJECT;
|
type = TOKEN_DELIM_OBJECT;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.CloseBraceToken:
|
case SyntaxKind.CloseBraceToken:
|
||||||
parents = ParentsStack.pop(parents);
|
parents = ParentsStack.pop(parents);
|
||||||
type = TOKEN_DELIM_OBJECT;
|
type = TOKEN_DELIM_OBJECT;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.OpenBracketToken:
|
case SyntaxKind.OpenBracketToken:
|
||||||
parents = ParentsStack.push(parents, JSONParent.Array);
|
parents = ParentsStack.push(parents, JSONParent.Array);
|
||||||
type = TOKEN_DELIM_ARRAY;
|
type = TOKEN_DELIM_ARRAY;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.CloseBracketToken:
|
case SyntaxKind.CloseBracketToken:
|
||||||
parents = ParentsStack.pop(parents);
|
parents = ParentsStack.pop(parents);
|
||||||
type = TOKEN_DELIM_ARRAY;
|
type = TOKEN_DELIM_ARRAY;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.ColonToken:
|
case SyntaxKind.ColonToken:
|
||||||
type = TOKEN_DELIM_COLON;
|
type = TOKEN_DELIM_COLON;
|
||||||
lastWasColon = true;
|
lastWasColon = true;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.CommaToken:
|
case SyntaxKind.CommaToken:
|
||||||
type = TOKEN_DELIM_COMMA;
|
type = TOKEN_DELIM_COMMA;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.TrueKeyword:
|
case SyntaxKind.TrueKeyword:
|
||||||
case json.SyntaxKind.FalseKeyword:
|
case SyntaxKind.FalseKeyword:
|
||||||
type = TOKEN_VALUE_BOOLEAN;
|
type = TOKEN_VALUE_BOOLEAN;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.NullKeyword:
|
case SyntaxKind.NullKeyword:
|
||||||
type = TOKEN_VALUE_NULL;
|
type = TOKEN_VALUE_NULL;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.StringLiteral:
|
case SyntaxKind.StringLiteral:
|
||||||
const currentParent = parents ? parents.type : JSONParent.Object;
|
const currentParent = parents ? parents.type : JSONParent.Object;
|
||||||
const inArray = currentParent === JSONParent.Array;
|
const inArray = currentParent === JSONParent.Array;
|
||||||
type = lastWasColon || inArray ? TOKEN_VALUE_STRING : TOKEN_PROPERTY_NAME;
|
type = lastWasColon || inArray ? TOKEN_VALUE_STRING : TOKEN_PROPERTY_NAME;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.NumericLiteral:
|
case SyntaxKind.NumericLiteral:
|
||||||
type = TOKEN_VALUE_NUMBER;
|
type = TOKEN_VALUE_NUMBER;
|
||||||
lastWasColon = false;
|
lastWasColon = false;
|
||||||
break;
|
break;
|
||||||
|
|
@ -220,10 +250,10 @@ function tokenize(
|
||||||
// comments, iff enabled
|
// comments, iff enabled
|
||||||
if (comments) {
|
if (comments) {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case json.SyntaxKind.LineCommentTrivia:
|
case SyntaxKind.LineCommentTrivia:
|
||||||
type = TOKEN_COMMENT_LINE;
|
type = TOKEN_COMMENT_LINE;
|
||||||
break;
|
break;
|
||||||
case json.SyntaxKind.BlockCommentTrivia:
|
case SyntaxKind.BlockCommentTrivia:
|
||||||
type = TOKEN_COMMENT_BLOCK;
|
type = TOKEN_COMMENT_BLOCK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +261,7 @@ function tokenize(
|
||||||
|
|
||||||
ret.endState = new JSONState(
|
ret.endState = new JSONState(
|
||||||
state.getStateData(),
|
state.getStateData(),
|
||||||
scanner.getTokenError(),
|
<ScanError><any>scanner.getTokenError(),
|
||||||
lastWasColon,
|
lastWasColon,
|
||||||
parents
|
parents
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"declaration": true,
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"outDir": "../out/esm",
|
|
||||||
"target": "es5",
|
|
||||||
"lib": ["dom", "es5", "es2015.collection", "es2015.promise", "es2015.iterable"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue