private async void AnalyzeCodeSyntax()
        {
            dispatcherTimer.Stop();

            try
            {
                foldingStretegy.UpdateFoldings(foldingManager, _editor.Document);

                var errorService = ErrorService.GetService();
                errorService.Clear();


                var d = await CodeAnalysisService.LoadDocument(_editor.Document.Text).GetDiagnosticsAsync();

                var s = d.Select(x =>
                {
                    var cd    = new CompilationDiagnostic(x);
                    var line  = _editor.Document.GetLineByOffset(x.Location.SourceSpan.Start);
                    cd.Line   = line.LineNumber;
                    cd.Column = line.Length;
                    return(cd);
                });

                errorService.AddRange(s);

                textMarkerService.RemoveAll(m => true);

                foreach (var item in d)
                {
                    var         span = item.Location.SourceSpan;
                    ITextMarker m    = textMarkerService.Create(span.Start, span.Length);
                    m.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                    m.MarkerColor = item.Severity == DiagnosticSeverity.Error ? Colors.Red : Colors.LightGreen;
                    m.ToolTip     = item.ToString();
                }
            }
            catch { }
        }
        /// <summary>
        /// Cria uma nova instância de MainWindowViewModel
        /// </summary>
        public MainWindowViewModel()
        {
            // atribui os eventos do helper de conexões entre os tanques
            ConnectionHelper.ConnectionStarted   += OnConnectionStarted;
            ConnectionHelper.ConnectionCompleted += OnConnectionCompleted;

            Project        = new Project();
            Project.Levels = new ObservableCollection <Level>();
            var level = new Level(Project);

            level.Items = new ObservableCollection <Tank>()
            {
                new Tank(level)
            };
            level.Name       = "Nível 1";
            level.AddCommand = new CommandAdapter()
            {
                Action = (p) => { Project.Levels[0].Items.Add(new Tank(level)); }
            };
            Project.Levels.Add(level);

            Project.Connections = new ObservableCollection <Link>();

            //inicializa e configura o simulador
            Simulator = new Simulator();
            Simulator.SimulationType     = SimulationType.RealTime;
            Simulator.SimulationDuration = TimeSpan.FromMinutes(5);
            Simulator.Tick            += (s, a) => jobs.Enqueue(a);
            Simulator.PropertyChanged += (s, a) => UpdateCommands();

            StartSimulationLoop();

            //configura o comando de abertura de arquivo
            OpenCommand = new CommandAdapter(true)
            {
                Action = (p) => Open()
            };

            //configura o comando de salvamento do projeto
            SaveCommand = new CommandAdapter(true)
            {
                Action = (p) => Save()
            };

            //configura o comando de partida do simulador
            StartCommand = new CommandAdapter(true)
            {
                Action = async(p) =>
                {
                    //limpa os dados da plotagem atual
                    if (!Simulator.IsPaused)
                    {
                        try
                        {
                            ChartService.GetService().Clear();
                            LogService.GetService().Clear();
                            ErrorService.GetService().Clear();

                            //percorre todos os tanques
                            foreach (var l in Project.Levels)
                            {
                                foreach (var t in l.Items)
                                {
                                    //compila o código de todos os tanques
                                    await t.Compile();

                                    t.SimulationTank.Simulator        = Simulator;
                                    t.SimulationTank.SaveChartCommand = s => ExportPng(ChartControl, s);
                                    //chama o método de inicialização de cada tanque
                                    t.SimulationTank.OnSimulationStarting();
                                }
                            }
                        }
                        catch (CompilationException ce)
                        {
                            ErrorService.GetService().AddRange(ce.Errors);

                            Simulator.Stop();

                            ShowErrorDialog("A simulação falhou ao iniciar. Por favor verifique a lista de erros");

                            SelectedTabIndex = 3;

                            return;
                        }
                        catch (Exception e)
                        {
                            Simulator.Stop();

                            ShowErrorDialog("Ocorreu um erro desconhecido ao iniciar a simulação:\n" + e.Message);

                            return;
                        }
                    }

                    //inicia a simulação
                    Simulator.Start();
                }
            };

            //configura o comando de pausa do simulador
            PauseCommand = new CommandAdapter(false)
            {
                Action = (p) => Simulator.Pause()
            };

            //configura o comando de parada do simulador
            StopCommand = new CommandAdapter(false)
            {
                Action = (p) => Simulator.Stop()
            };

            //configura o comando de abertura da janela de pripriedades dos tanques
            ShowTankPropertiesCommand = new CommandAdapter(true)
            {
                Action = (p) => new Views.TankProperties().SetTank((Tank)p).ShowDialog(App.MainWindow)
            };

            //configura o comando de remoção de conexões entre tanques
            RemovePipeCommand = new CommandAdapter(true)
            {
                Action = (p) => Project.Connections.Remove((Link)p)
            };

            //configura o comando de adição de níveis
            AddLevelCommand = new CommandAdapter(true)
            {
                Action = (p) =>
                {
                    var level = new Level(Project);
                    level.Name  = $"Nível {Project.Levels.Count + 1}";
                    level.Items = new ObservableCollection <Tank>()
                    {
                        new Tank(level)
                    };
                    level.AddCommand = new CommandAdapter(true)
                    {
                        Action = (p) => level.Items.Add(new Tank(level))
                    };
                    Project.Levels.Add(level);
                }
            };

            //configura o comando para exportar imagens do diagrama
            ExportCommand = new CommandAdapter(true)
            {
                Action = Export
            };


            SimulationSettingsCommand = new CommandAdapter(true)
            {
                Action = async(p) =>
                {
                    Views.SimulationSettings s = new Views.SimulationSettings();
                    s.ViewModel.IsRealTime = Simulator.SimulationType == SimulationType.RealTime;

                    await s.ShowDialog(App.MainWindow);

                    Simulator.SimulationType     = s.ViewModel.IsRealTime ? SimulationType.RealTime : SimulationType.Transient;
                    Simulator.SimulationDuration = s.ViewModel.Duration;
                    Simulator.SimulationInterval = s.ViewModel.Interval;
                }
            };


            RefreshChartCommand = new CommandAdapter(true)
            {
                Action = (p) => ((OxyPlot.Avalonia.PlotView)p).ResetAllAxes()
            };


            ChartZoomInCommand = new CommandAdapter(true)
            {
                Action = (p) => ((OxyPlot.Avalonia.PlotView)p).ZoomAllAxes(1.1)
            };

            ChartZoomOutCommand = new CommandAdapter(true)
            {
                Action = (p) => ((OxyPlot.Avalonia.PlotView)p).ZoomAllAxes(0.9)
            };

            AboutCommand = new CommandAdapter(true)
            {
                Action = (p) => IsAboutOpen = true
            };

            CheckCommandLine();
        }