<commit_before>﻿using System;
using System.Windows;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Controls;
using System.IO;
using System.Diagnostics;
using System.Windows.Input;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace VSPackage.CPPCheckPlugin
{
	[Guid("98C5C8D0-34D9-406F-AA2E-C85B47C9F268")]
	public class MainToolWindow : ToolWindowPane
	{
		public MainToolWindow() : base(null)
		{
			Debug.Assert(_instance == null); // Only 1 instance of this tool window makes sense
			_instance = this;

			_listView = _ui.listView;
			_ui.EditorRequestedForProblem += openProblemInEditor;
			_ui.SuppressionRequested += suppressProblem;

			Caption = "Cppcheck analysis results";
			Content = _ui;
		}

		public static MainToolWindow Instance
		{
			get{return _instance;}
		}

		public void show()
		{
			IVsWindowFrame frame = Frame as IVsWindowFrame;
			if (frame != null)
				frame.Show();
		}

		public void clear()
		{
			_listView.Items.Clear();
		}

		public void displayProblem(Problem problem)
		{
			_listView.Items.Add(new MainToolWindowUI.ProblemsListItem(problem));
		}

		private void openProblemInEditor(Problem problem)
		{
			IVsUIShellOpenDocument shellOpenDocument = (IVsUIShellOpenDocument)GetService(typeof(IVsUIShellOpenDocument));
			Debug.Assert(shellOpenDocument != null);
			Guid guidCodeView = VSConstants.LOGVIEWID.Code_guid;
			Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = null;
			IVsUIHierarchy hierarchy = null;
			uint itemId = 0;
			IVsWindowFrame windowFrame = null;
			if (shellOpenDocument.OpenDocumentViaProject(problem.FileName, ref guidCodeView, out sp, out hierarchy, out itemId, out windowFrame) != VSConstants.S_OK)
			{
				Debug.WriteLine("Error opening file " + problem.FileName);
				return;
			}

			if (windowFrame != null)
				windowFrame.Show();

			EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(SDTE));
			Debug.Assert(dte != null);
			Debug.Assert(dte.ActiveDocument != null);
			EnvDTE.TextSelection selection = dte.ActiveDocument.Selection as EnvDTE.TextSelection;
			Debug.Assert(selection != null);
			selection.GotoLine(problem.Line);
		}

		private void suppressProblem(Problem problem, ICodeAnalyzer.SuppressionScope scope)<commit_msg>Bugfix for the previous commit<commit_after>﻿using System;
using System.Windows;
using System.Windows.Threading;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Controls;
using System.IO;
using System.Diagnostics;
using System.Windows.Input;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace VSPackage.CPPCheckPlugin
{
	[Guid("98C5C8D0-34D9-406F-AA2E-C85B47C9F268")]
	public class MainToolWindow : ToolWindowPane
	{
		public MainToolWindow() : base(null)
		{
			Debug.Assert(_instance == null); // Only 1 instance of this tool window makes sense
			_instance = this;

			_listView = _ui.listView;
			_ui.EditorRequestedForProblem += openProblemInEditor;
			_ui.SuppressionRequested += suppressProblem;

			Caption = "Cppcheck analysis results";
			Content = _ui;
		}

		public static MainToolWindow Instance
		{
			get{return _instance;}
		}

		public void show()
		{
			IVsWindowFrame frame = Frame as IVsWindowFrame;
			if (frame != null)
				frame.Show();
		}

		public void clear()
		{
			_listView.Items.Clear();
		}

		public void displayProblem(Problem problem)
		{
			Application.Current.Dispatcher.BeginInvoke(new Action(()=>_listView.Items.Add(new MainToolWindowUI.ProblemsListItem(problem))));
		}

		private void openProblemInEditor(Problem problem)
		{
			IVsUIShellOpenDocument shellOpenDocument = (IVsUIShellOpenDocument)GetService(typeof(IVsUIShellOpenDocument));
			Debug.Assert(shellOpenDocument != null);
			Guid guidCodeView = VSConstants.LOGVIEWID.Code_guid;
			Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = null;
			IVsUIHierarchy hierarchy = null;
			uint itemId = 0;
			IVsWindowFrame windowFrame = null;
			if (shellOpenDocument.OpenDocumentViaProject(problem.FileName, ref guidCodeView, out sp, out hierarchy, out itemId, out windowFrame) != VSConstants.S_OK)
			{
				Debug.WriteLine("Error opening file " + problem.FileName);
				return;
			}

			if (windowFrame != null)
				windowFrame.Show();

			EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(SDTE));
			Debug.Assert(dte != null);
			Debug.Assert(dte.ActiveDocument != null);
			EnvDTE.TextSelection selection = dte.ActiveDocument.Selection as EnvDTE.TextSelection;
			Debug.Assert(selection != null);
			selection.GotoLine(problem.Line);
		}

		private void suppressProblem(Problem problem, ICodeAnalyzer.SuppressionScope scope)
{'fraction_non_alphanumeric': 0.09989594172736732, 'fraction_numerical': 0.009157127991675338, 'mean_word_length': 4.728247914183552, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4129219', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1481, 'n_words': 314}