|
| 1 | +const vscode = require("vscode"); |
| 2 | + |
| 3 | +// Create a diagnostic collection |
| 4 | +const treeFilesDiagnosticCollection = vscode.languages.createDiagnosticCollection('treeNodes'); |
| 5 | + |
| 6 | +// Register a Code Action provider |
| 7 | +const treeFilesCodeActionProvider = vscode.languages.registerCodeActionsProvider('tree', { |
| 8 | + provideCodeActions(document) { |
| 9 | + const diagnostics = []; |
| 10 | + |
| 11 | + document.getText().split('\n').forEach((lineText, lineNumber) => { |
| 12 | + lineText = lineText.trim(); |
| 13 | + if (lineNumber == 0 && !lineText.endsWith('.t.sol')) { |
| 14 | + const diagnostic = new vscode.Diagnostic( |
| 15 | + new vscode.Range(0, 0, 0, lineText.length), |
| 16 | + `Should be a valid test name (ending with .t.sol)`, |
| 17 | + vscode.DiagnosticSeverity.Error |
| 18 | + ); |
| 19 | + |
| 20 | + diagnostics.push(diagnostic); |
| 21 | + } |
| 22 | + if (/^(├──|└──|│)/.test(lineText)) { |
| 23 | + const allowedPrefixes = ['it', 'when', 'given']; |
| 24 | + lineText = lineText.replace(/^[^a-zA-Z0-9]+/, ''); |
| 25 | + |
| 26 | + // Check if the line starts with an allowed prefix |
| 27 | + const prefix = lineText.split(' ')[0]; |
| 28 | + if (!allowedPrefixes.includes(prefix)) { |
| 29 | + // Create a diagnostic for the violation |
| 30 | + const diagnostic = new vscode.Diagnostic( |
| 31 | + new vscode.Range(lineNumber, 0, lineNumber, lineText.length), |
| 32 | + `Tree node should start with "it", "when", or "given"`, |
| 33 | + vscode.DiagnosticSeverity.Error |
| 34 | + ); |
| 35 | + diagnostics.push(diagnostic); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + }); |
| 40 | + |
| 41 | + treeFilesDiagnosticCollection.set(document.uri, diagnostics); |
| 42 | + |
| 43 | + }, |
| 44 | +}); |
| 45 | + |
| 46 | +module.exports = { treeFilesDiagnosticCollection, treeFilesCodeActionProvider }; |
0 commit comments