Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The module 'vscode' contains the VS Code extensibility API
- // Import the module and reference it with the alias vscode in your code below
- import * as vscode from 'vscode';
- // this method is called when your extension is activated
- // your extension is activated the very first time the command is executed
- export function activate(context: vscode.ExtensionContext) {
- // Use the console to output diagnostic information (console.log) and errors (console.error)
- // This line of code will only be executed once when your extension is activated
- console.log('Congratulations, your extension "testexttypescript" is now active!');
- }
- // this method is called when your extension is deactivated
- export function deactivate() {}
- const onDidOpenTextDocument = vscode.workspace.onDidOpenTextDocument((document: vscode.TextDocument) => {
- if (document.fileName.endsWith('.sp')) {
- let compilerPath = 'D:\\Documentos\\Sourcemod scripting\\spcomp.exe';
- getCompileErrorsAndWarnings(compilerPath, document.fileName.replace(/\\/g, '/'));
- }
- });
- // run compiler and read errors and warnings
- function getCompileErrorsAndWarnings(compiler: string, file: string) {
- console.log('getCompileErrorsAndWarnings called');
- let destinationFolder = String(require('path').join(require('os').tmpdir(), '_vscode.smx.tmp'));
- require('child_process').execFile(compiler, [file, '-o', destinationFolder], (err: any, stdout: string, stderr: string) => {
- console.log('---------------------------------------------');
- console.log(stdout);
- console.log('---------------------------------------------');
- stdout.split('\n').forEach((line) => {
- if (line.startsWith(file)) {
- let matches = line.match(new RegExp(`^${file}\\(([0-9]+)\\) : (error|warning|fatal error) ([0-9]+): (.*)`));
- // separate each part
- let linenum = matches![1];
- let typemsg = matches![2];
- let typenum = matches![3];
- let message = matches![4];
- // get the piece of code with the warning/error
- let piece = message.match(new RegExp('"(.*?)"'))![1];
- console.log(piece);
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement