Commit 8226acb7 authored by Jérome Perrin's avatar Jérome Perrin

monaco: enable linter for python scripts WIP

parent fdb09553
......@@ -72,6 +72,59 @@
}
});
})
.declareJob('runPyLint', function() {
var context = this;
return new RSVP.Queue()
.push(function() {
return RSVP.delay(500);
})
.push(function() {
if (
context.state.model_language === 'python' &&
context.state.check_source_code_url
) {
const data = new FormData();
const checker_parameters = {
code: context.editor.getValue()
};
data.append('data', JSON.stringify(checker_parameters));
fetch(context.state.check_source_code_url, {
method: 'POST',
body: data
// signal: controller.signal
})
.then(response => response.json())
.then(
data => {
monaco.editor.setModelMarkers(
context.editor.getModel(),
'pylint',
data['annotations'].map(annotation => {
return {
startLineNumber: annotation.row + 1,
endLineNumber: annotation.row + 1,
startColumn: annotation.col,
endColumn: Infinity,
message: annotation.text,
severity:
annotation.type === 'error'
? monaco.MarkerSeverity.Error
: monaco.MarkerSeverity.Warning
};
})
);
},
e => {
if (!(e instanceof DOMException) /* AbortError */) {
throw e;
}
/* ignore aborted requests */
}
);
}
});
})
.declareMethod('render', function(options) {
var model_language,
state_dict = {
......@@ -84,11 +137,18 @@
model_language = 'javascript';
} else if (options.portal_type === 'Web Style') {
model_language = 'css';
} else if (options.portal_type === 'Python Script') {
} else if (
options.portal_type === 'Python Script' ||
options.portal_type === 'Test Component' ||
options.portal_type === 'Extension Component' ||
options.portal_type === 'Document Component' ||
options.portal_type === 'Extension Component'
) {
model_language = 'python';
}
state_dict.model_language = model_language;
state_dict.value = options.value || '';
state_dict.check_source_code_url = options.check_source_code_url || '';
return this.changeState(state_dict);
})
......@@ -171,6 +231,11 @@
.push(addExtraLibrary('./monaco-renderjs.d.ts', 'renderjs'))
.push(addExtraLibrary('./monaco-jio.d.ts', 'jio'));
}
if (this.state.model_language === 'python') {
this.editor.getModel().onDidChangeContent(this.runPyLint.bind(this));
this.runPyLint();
}
}
return queue;
})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment