/// <summary> /// Inicializa as dependências do software /// </summary> public override void Initialize() { AvaloniaXamlLoader.Load(this); OxyPlotModule.EnsureLoaded(); OxyPlotModule.Initialize(); //inicializa os serviços de código CodeAnalysisService.LoadDocument(""); }
async void textEditor_TextArea_TextEntered(object sender, TextInputEventArgs e) { try { codeService = CodeAnalysisService.LoadDocument(_editor.Document.Text); if (e.Text == "(") { var p = await codeService.GetMethodSignature(_editor.CaretOffset - 2); if (p != null) { _insightWindow = new OverloadInsightWindow(_editor.TextArea); _insightWindow.Closed += (s, a) => _insightWindow = null; _insightWindow.Provider = new OverloadProvider(p); _insightWindow.Show(); return; } } if (await codeService.ShouldTriggerCompletion(_editor.CaretOffset)) { _completionWindow = new CompletionWindow(_editor.TextArea); _completionWindow.Closed += (o, args) => _completionWindow = null; var data = await CodeAnalysisService.LoadDocument(_editor.Document.Text).GetCompletitionDataAt(_editor.CaretOffset); if (data.Count == 0 || _completionWindow == null) { return; } foreach (var d in data) { _completionWindow.CompletionList.CompletionData.Add(d); } _completionWindow.StartOffset -= 1; _completionWindow.Show(); } } catch { } }
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 TankProperties /// </summary> public TankProperties() { this.InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif _editor = this.FindControl <TextEditor>("Editor"); _editor.Background = Brushes.Transparent; _editor.Options.ConvertTabsToSpaces = true; _editor.Options.IndentationSize = 4; _editor.ShowLineNumbers = true; _editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#"); _editor.TextArea.TextEntered += textEditor_TextArea_TextEntered; _editor.TextArea.TextEntering += textEditor_TextArea_TextEntering; _editor.TextArea.TextInput += TextArea_TextInput; _editor.TextArea.Initialized += (s, a) => AnalyzeCodeSyntax(); _editor.KeyUp += TextArea_KeyUp; _editor.TextArea.IndentationStrategy = new AvaloniaEdit.Indentation.CSharp.CSharpIndentationStrategy(); _insightWindow = new OverloadInsightWindow(_editor.TextArea); _editor.FontFamily = GetPlatformFontFamily(); _editor.TextArea.PointerMoved += TextArea_PointerMoved; foldingManager = FoldingManager.Install(_editor.TextArea); foldingStretegy = new BraceFoldingStrategy(); var textMarkerService = new TextMarkerService(_editor.Document); _editor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); _editor.TextArea.TextView.LineTransformers.Add(textMarkerService); IServiceContainer services = _editor.Document.GetService <IServiceContainer>(); if (services != null) { services.AddService(typeof(ITextMarkerService), textMarkerService); } this.textMarkerService = textMarkerService; this.AddHandler(PointerWheelChangedEvent, (o, i) => { if (i.KeyModifiers != KeyModifiers.Control) { return; } if (i.Delta.Y > 0) { _editor.FontSize++; } else { _editor.FontSize = _editor.FontSize > 1 ? _editor.FontSize - 1 : 1; } }, RoutingStrategies.Bubble, true); codeService = CodeAnalysisService.LoadDocument(_editor.Document.Text); UndoCommand = new CommandAdapter(true) { Action = (p) => _editor.Undo() }; RedoCommand = new CommandAdapter(true) { Action = (p) => _editor.Redo() }; }