This commit is contained in:
Liyas Thomas
2020-02-23 06:58:13 +05:30
parent 16779d496e
commit 9c09a8128a

View File

@@ -48,10 +48,10 @@ export default {
} }
}, },
theme() { theme() {
this.editor.setTheme("ace/theme/" + this.defineTheme()); this.editor.setTheme(`ace/theme/${this.defineTheme()}`);
}, },
lang(value) { lang(value) {
this.editor.getSession().setMode("ace/mode/" + value); this.editor.getSession().setMode(`ace/mode/${value}`);
}, },
options(value) { options(value) {
this.editor.setOptions(value); this.editor.setOptions(value);
@@ -62,27 +62,36 @@ export default {
let langTools = ace.require("ace/ext/language_tools"); let langTools = ace.require("ace/ext/language_tools");
const editor = ace.edit(this.$refs.editor, { const editor = ace.edit(this.$refs.editor, {
theme: "ace/theme/" + this.defineTheme(), theme: `ace/theme/${this.defineTheme()}`,
mode: "ace/mode/" + this.lang, mode: `ace/mode/${this.lang}`,
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableLiveAutocompletion: true, enableLiveAutocompletion: true,
...this.options ...this.options
}); });
const completer = { const completer = {
getCompletions: (editor, _session, pos, _prefix, callback) => { getCompletions: (
editor,
_session,
{ row, column },
_prefix,
callback
) => {
if (this.validationSchema) { if (this.validationSchema) {
const completions = getAutocompleteSuggestions(this.validationSchema, editor.getValue(), { line: pos.row, character: pos.column }); const completions = getAutocompleteSuggestions(
this.validationSchema,
editor.getValue(),
{ line: row, character: column }
);
callback(null, callback(
completions.map((completion) => { null,
return { completions.map(({ label, detail }) => ({
name: completion.label, name: label,
value: completion.label, value: label,
score: 1.0, score: 1.0,
meta: completion.detail meta: detail
}; }))
})
); );
} else { } else {
callback(null, []); callback(null, []);
@@ -130,14 +139,14 @@ export default {
if (this.validationSchema) { if (this.validationSchema) {
this.editor.session.setAnnotations( this.editor.session.setAnnotations(
gql.validate(this.validationSchema, doc).map(err => { gql
return { .validate(this.validationSchema, doc)
row: err.locations[0].line - 1, .map(({ locations, message }) => ({
column: err.locations[0].column - 1, row: locations[0].line - 1,
text: err.message, column: locations[0].column - 1,
text: message,
type: "error" type: "error"
}; }))
})
); );
} }
} catch (e) { } catch (e) {