mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
'use strict';
|
|
import * as vscode from 'vscode';
|
|
import * as path from 'path';
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
|
|
const collection = vscode.languages.createDiagnosticCollection('test');
|
|
if (vscode.window.activeTextEditor) {
|
|
updateDiagnostics(vscode.window.activeTextEditor.document, collection);
|
|
}
|
|
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(e => updateDiagnostics(e.document, collection)));
|
|
|
|
}
|
|
|
|
function updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {
|
|
if (document && path.basename(document.uri.fsPath) === 'sample-demo.rs') {
|
|
collection.set(document.uri, [{
|
|
code: '',
|
|
message: 'cannot assign twice to immutable variable `x`',
|
|
range: new vscode.Range(new vscode.Position(3, 4), new vscode.Position(3, 10)),
|
|
severity: vscode.DiagnosticSeverity.Error,
|
|
source: '',
|
|
relatedInformation: [
|
|
new vscode.DiagnosticRelatedInformation(new vscode.Location(document.uri, new vscode.Range(new vscode.Position(1, 8), new vscode.Position(1, 9))), 'first assignment to `x`')
|
|
]
|
|
}]);
|
|
} else {
|
|
collection.clear();
|
|
}
|
|
}
|
|
|
|
// this method is called when your extension is deactivated
|
|
export function deactivate() {
|
|
} |