本文整理匯總了TypeScript中vscode.languages.createDiagnosticCollection方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript languages.createDiagnosticCollection方法的具體用法?TypeScript languages.createDiagnosticCollection怎麽用?TypeScript languages.createDiagnosticCollection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.languages
的用法示例。
在下文中一共展示了languages.createDiagnosticCollection方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: activate
//.........這裏部分代碼省略.........
if (token.isCancellationRequested) return null;
let [status, result] = await session.request(['errors']);
if (token.isCancellationRequested) return null;
if (status !== 'return') return;
let diagnostics = [];
result.map(({type, start, end, message}) => {
let fromType = (type) => {
switch (type) {
case 'type':
case "parser":
case "env":
case "unknown":
return vscode.DiagnosticSeverity.Error;
case "warning":
return vscode.DiagnosticSeverity.Warning;
}
};
if (type === 'type' &&
message.startsWith('Error: Signature mismatch:') &&
message.includes(': Actual declaration')) {
let regex = /^\s*File ("[^"]+"), line (\d+), characters (\d+)-(\d+): Actual declaration$/mg;
for (let match; (match = regex.exec(message)) !== null;) {
let file = JSON.parse(match[1]);
let line = JSON.parse(match[2]);
let col1 = JSON.parse(match[3]);
let col2 = JSON.parse(match[4]);
if (Path.basename(file) === Path.basename(document.fileName)) {
diagnostics.push(
new vscode.Diagnostic(
toVsRange({ line, col: col1 }, { line, col: col2 }),
message,
fromType(type.toLowerCase())
)
);
} else {
// Log here?
}
}
return;
}
diagnostics.push(
new vscode.Diagnostic(
toVsRange(start, end),
message,
fromType(type.toLowerCase())
)
);
});
return diagnostics;
};
let LINTER_DEBOUNCE_TIMER = Symbol();
let LINTER_TOKEN_SOURCE = Symbol();
let diagnosticCollection = vscode.languages.createDiagnosticCollection('ocaml');
let lintDocument = (document: vscode.TextDocument) => {
if (document.languageId !== 'ocaml') return;
clearTimeout(document[LINTER_DEBOUNCE_TIMER]);
document[LINTER_DEBOUNCE_TIMER] = setTimeout(async () => {
if (document[LINTER_TOKEN_SOURCE]) {
document[LINTER_TOKEN_SOURCE].cancel();
}
document[LINTER_TOKEN_SOURCE] = new vscode.CancellationTokenSource();
let diagnostics = await provideLinter(document, document[LINTER_TOKEN_SOURCE].token);
diagnosticCollection.set(document.uri, diagnostics);
}, configuration.get<number>('lintDelay'));
};
vscode.workspace.onDidChangeTextDocument(({document}) => {
if (document.languageId === 'ocaml') {
lintDocument(document);
return;
}
let relintOpenedDocuments = () => {
diagnosticCollection.clear();
for (let document of vscode.workspace.textDocuments) {
if (document.languageId === 'ocaml') {
lintDocument(document);
}
}
};
let path = Path.basename(document.fileName);
if (path === '.merlin') {
relintOpenedDocuments();
}
});
}