forked from remcohaszing/monaco-yaml
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
97 changed files
with
15,181 additions
and
4,061 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> | ||
<link | ||
rel="stylesheet" | ||
data-name="vs/editor/editor.main" | ||
href="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.css" | ||
/> | ||
</head> | ||
|
||
<body> | ||
<h2>Monaco Editor YAML test page</h2> | ||
<code id="path"></code> | ||
<div | ||
id="container" | ||
style="width:800px;height:600px;border:1px solid grey" | ||
></div> | ||
|
||
<style> | ||
.x-highlight-range { | ||
background-color: lightblue; | ||
} | ||
</style> | ||
|
||
<script> | ||
// Loading basic-languages to get the YAML language definition | ||
var paths = { | ||
'vs/basic-languages': '../node_modules/monaco-languages/release/dev', | ||
'vs/language/yaml': '../release/dev', | ||
vs: '../node_modules/monaco-editor-core/dev/vs', | ||
}; | ||
if (document.location.protocol === 'http:') { | ||
// Add support for running local http server | ||
let testIndex = document.location.pathname.indexOf('/test/'); | ||
if (testIndex !== -1) { | ||
let prefix = document.location.pathname.substr(0, testIndex); | ||
paths['vs/language/yaml'] = prefix + '/release/dev'; | ||
} | ||
} | ||
var require = { | ||
paths: paths, | ||
}; | ||
</script> | ||
<script src="../node_modules/monaco-editor-core/dev/vs/loader.js"></script> | ||
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.nls.js"></script> | ||
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script> | ||
|
||
<script> | ||
require([ | ||
'vs/basic-languages/monaco.contribution', | ||
'vs/language/yaml/monaco.contribution', | ||
], function() { | ||
const yaml = `p1: `; | ||
const modelUri = monaco.Uri.parse('a://b/foo.json'); | ||
const editor = monaco.editor.create( | ||
document.getElementById('container'), | ||
{ | ||
language: 'yaml', | ||
showFoldingControls: 'always', | ||
model: monaco.editor.createModel(yaml, 'yaml', modelUri), | ||
} | ||
); | ||
|
||
monaco.languages.yaml.yamlDefaults.setDiagnosticsOptions({ | ||
enableSchemaRequest: true, | ||
validate: true, | ||
schemas: [ | ||
{ | ||
uri: 'http://myserver/foo-schema.json', // id of the first schema | ||
fileMatch: [modelUri.toString()], // associate with our model | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
p1: { | ||
enum: ['v1', 'v2'], | ||
}, | ||
p2: { | ||
$ref: 'http://myserver/bar-schema.json', // reference the second schema | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
uri: 'http://myserver/bar-schema.json', // id of the first schema | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
q1: { | ||
enum: ['x1', 'x2'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
require(['vs/editor/contrib/quickOpen/quickOpen'], async quickOpen => { | ||
const NEVER_CANCEL_TOKEN = { | ||
isCancellationRequested: false, | ||
onCancellationRequested: () => Event.NONE, | ||
}; | ||
|
||
let oldDecorations = []; | ||
|
||
async function _getSymbolForPosition(model, position) { | ||
const symbols = await quickOpen.getDocumentSymbols( | ||
model, | ||
false, | ||
NEVER_CANCEL_TOKEN | ||
); | ||
|
||
function _recur(symbol) { | ||
let target = symbol; | ||
if (symbol && symbol.children && symbol.children.length) { | ||
target = | ||
_recur( | ||
symbol.children.find(child => | ||
child.range.containsPosition(position) | ||
) | ||
) || symbol; | ||
} | ||
|
||
return target; | ||
} | ||
|
||
return _recur({ children: symbols }); | ||
} | ||
|
||
editor.onDidChangeCursorSelection(async ({ selection }) => { | ||
const model = editor.getModel(); | ||
const position = selection.getPosition(); | ||
const symbol = await _getSymbolForPosition(model, position); | ||
|
||
console.log(`${symbol.name}: ${symbol.range}`); | ||
if (symbol && symbol.range) { | ||
const decoration = { | ||
range: symbol.range, | ||
options: { | ||
isWholeLine: false, | ||
className: 'x-highlight-range', | ||
}, | ||
}; | ||
|
||
oldDecorations = editor.deltaDecorations( | ||
oldDecorations, | ||
decoration ? [decoration] : [] | ||
); | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
{ | ||
"name": "monaco-yaml", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "YAML plugin for the Monaco Editor", | ||
"scripts": { | ||
"compile": "rimraf ./out && yarn compile:umd && yarn compile:esm", | ||
"compile:umd": "tsc -p ./src/tsconfig.json", | ||
"compile:esm": "tsc -p ./src/tsconfig.esm.json", | ||
"watch": "tsc -p ./src --watch", | ||
"prepublish": "rimraf ./out && rimraf ./release && yarn compile:umd && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts" | ||
"prepublish": "rimraf ./out && rimraf ./release && yarn compile:umd && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts", | ||
"lint": "prettier \"{src,test}/**/*.{json,scss,html,ts}\" --write", | ||
"test": "jest" | ||
}, | ||
"author": "Kevin Decker <[email protected]> (http://incaseofstairs.com)", | ||
"maintainers": [ | ||
|
@@ -23,19 +25,61 @@ | |
"url": "https://github.com/pengx17/monaco-yaml/issues" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.4", | ||
"@types/mocha": "^5.2.5", | ||
"@types/jest": "^23.3.10", | ||
"@types/node": "^10.9.3", | ||
"husky": "^1.2.1", | ||
"jest": "^23.6.0", | ||
"js-yaml": "^3.12.0", | ||
"jsonc-parser": "^2.0.2", | ||
"lint-staged": "^8.1.0", | ||
"monaco-editor-core": "0.15.5", | ||
"monaco-languages": "1.6.0", | ||
"monaco-plugin-helpers": "^1.0.2", | ||
"prettier": "^1.15.3", | ||
"requirejs": "^2.3.5", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^23.10.5", | ||
"typescript": "^3.1.6", | ||
"uglify-es": "^3.3.9", | ||
"vscode-languageserver-types": "3.12.0", | ||
"yaml-language-server": "^0.1.0" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"semi": true | ||
}, | ||
"lint-staged": { | ||
"linters": { | ||
"*.{json,scss,html}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"ignore": [ | ||
"src/backend/vendor/**/*" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"jest": { | ||
"globals": { | ||
"ts-jest": { | ||
"tsConfig": "./test/tsconfig.json" | ||
} | ||
}, | ||
"moduleFileExtensions": [ | ||
"js", | ||
"ts" | ||
], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest" | ||
}, | ||
"testMatch": [ | ||
"**/test/*.test.+(ts|js)" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const EOL = '\n'; | ||
export const EOL = '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.