/// <devdoc> /// This method will be called by Visual Studio in response to a package close /// (disposing will be true in this case). The default implementation revokes all /// services and calls Dispose() on any created services that implement IDisposable. /// </devdoc> protected override void Dispose(bool disposing) { if (disposing) { Solution.Dispose(); _ = BreakpointChangeWatcher.StopAsync(); Z80AsmClassifierProvider.DetachFromPackage(); Z80AsmViewTaggerProvider.DetachFromPackage(); } base.Dispose(disposing); }
private async void OnVmStateChanged(object sender, VmStateChangedEventArgs args) { if (args.NewState == VmState.Running || args.NewState == VmState.Stopped) { // --- Remove current breakpoint information var oldFile = CurrentBreakpointFile; var oldLine = CurrentBreakpointLine; CurrentBreakpointFile = null; CurrentBreakpointLine = -1; if (oldFile != null) { Z80AsmViewTaggerProvider.UpdateBreakpointVisuals(oldFile, oldLine); } } var package = SpectNetPackage.Default; if (args.NewState == VmState.Paused && package.EmulatorViewModel.Machine.RunsInDebugMode && !package.Options.DisableSourceNavigation) { // --- Set up breakpoint information var address = package.EmulatorViewModel.Machine.SpectrumVm.Cpu.Registers.PC; if (CompiledOutput?.SourceMap != null && CompiledOutput.SourceMap.TryGetValue(address, out var fileInfo)) { // --- Add highlight to the current source code line CurrentBreakpointFile = CompiledOutput .SourceFileList[fileInfo.FileIndex].Filename; CurrentBreakpointLine = fileInfo.Line; if (package.Options.ForceShowSourceCode) { package.ShowToolWindow <SpectrumEmulatorToolWindow>(); var document = package.ApplicationObject.Documents.Open(CurrentBreakpointFile); document.Activate(); } else { package.ApplicationObject.Documents.Open(CurrentBreakpointFile); package.ShowToolWindow <SpectrumEmulatorToolWindow>(); } await Task.Delay(10); Z80AsmViewTaggerProvider.UpdateBreakpointVisuals(CurrentBreakpointFile, CurrentBreakpointLine); } } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); // --- Background initialization part Default = this; // --- Prepare project system extension files CheckCpsFiles(); Z80AsmLanguage = new Z80AsmLanguageService(this); // --- Special providers for the ZX Spectrum virtual machine DebugInfoProvider = new VsIntegratedSpectrumDebugInfoProvider(); SpectrumMachine.Reset(); SpectrumMachine.RegisterDefaultProviders(); SpectrumMachine.RegisterProvider <IRomProvider>(() => new PackageRomProvider()); SpectrumMachine.RegisterProvider <IBeeperProvider>(() => new AudioWaveProvider()); SpectrumMachine.RegisterProvider <ISoundProvider>(() => new AudioWaveProvider(AudioProviderType.Psg)); SpectrumMachine.RegisterProvider <ITapeLoadProvider>(() => new VsIntegratedTapeLoadProvider()); SpectrumMachine.RegisterProvider <ITapeSaveProvider>(() => new VsIntegratedTapeSaveProvider()); SpectrumMachine.RegisterProvider <IKempstonProvider>(() => new KempstonProvider()); SpectrumMachine.RegisterProvider <ISpectrumDebugInfoProvider>(() => DebugInfoProvider); SpectrumMachine.RegisterStackDebugSupport(new SimpleStackDebugSupport()); // --- Initialize other services BreakpointChangeWatcher = new BreakpointChangeWatcher(); BreakpointChangeWatcher.Start(); // --- Main thread initialization part await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // --- Initialize the package here InitializeCommands(); // --- Register custom editors RegisterEditorFactory(new RomEditorFactory()); RegisterEditorFactory(new TzxEditorFactory()); RegisterEditorFactory(new TapEditorFactory()); // --- Manage the solution and its events Solution = new SolutionStructure(); Solution.ActiveProjectChanged += OnActiveProjectChanged; ErrorList = new ErrorListWindow(); TaskList = new TaskListWindow(); // --- Create view models EmulatorViewModel = new EmulatorViewModel(); SpectrumViewModel = new SpectrumEmulatorToolWindowViewModel(); KeyboardToolModel = new KeyboardToolWindowViewModel(); RegistersViewModel = new RegistersToolWindowViewModel(); MemoryViewModel = new MemoryToolWindowViewModel(); DisassemblyViewModel = new DisassemblyToolWindowViewModel(); StackViewModel = new StackToolWindowViewModel(); BasicListViewModel = new BasicListToolWindowViewModel(); WatchViewModel = new WatchToolWindowViewModel(); // --- Prepare the provider for debugging DebugInfoProvider.Prepare(); // --- Prepare language services Z80AsmClassifierProvider.AttachToPackage(); Z80AsmViewTaggerProvider.AttachToPackage(); Log("SpectNetIdePackage initialized."); }