[英]Getting errors from Monaco editor
I would like to get hold of the errors created by default by Monaco editor.我想掌握摩纳哥编辑器默认创建的错误。
看起来您可以调用monaco.editor.getModelMarkers({})
来获取文档中所有标记的列表,然后自己过滤以将其限制为您感兴趣的错误。我更喜欢更清楚的-记录的路线,但在我的临时测试中这是有效的。
Given a monaco model, you can have access to the worker.给定 monaco 模型,您可以访问工作人员。 This is similar to a ts.LanguageService but the signatures are async.
这类似于 ts.LanguageService 但签名是异步的。 With that you can then call getSemanticDiagnostics() and all the rest.
有了它,你就可以调用 getSemanticDiagnostics() 和所有其他的。
monaco.languages.typescript.getTypeScriptWorker()
.then(_worker=>{_worker(model.uri)
.then(worker=>{
worker.getScriptFileNames().then(ff=>{
ff.forEach(sf=>{
worker.getSemanticDiagnostics(sf).then(dd=>{
console.log('\n\n DIAGNOSTICS FOR '+sf)
console.log(dd.map(d=>d.messageText))})
})
This is a simple sample to log errors:这是一个记录错误的简单示例:
import * as monaco from 'monaco-editor'
// ...
monaco.editor.onDidChangeMarkers(([uri]) => {
const markers = monaco.editor.getModelMarkers({resource: uri})
console.log('markers:', markers.map(
({ message, startLineNumber, startColumn, endLineNumber, endColumn }) =>
`${message} [${startLineNumber}:${startColumn}-${endLineNumber}:${endColumn}]`,
))
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.