void UpdateSyntaxHighlighting(FileName fileName) { var oldHighlighter = primaryTextEditor.GetService <IHighlighter>(); var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); var highlighter = SD.EditorControlService.CreateHighlighter(document); primaryTextEditor.SyntaxHighlighting = highlighting; primaryTextEditor.TextArea.TextView.LineTransformers.RemoveAll(t => t is HighlightingColorizer); primaryTextEditor.TextArea.TextView.LineTransformers.Insert(0, new HighlightingColorizer(highlighter)); primaryTextEditor.UpdateCustomizedHighlighting(); // Dispose the old highlighter; necessary to avoid memory leaks as // semantic highlighters might attach to global parser events. if (oldHighlighter != null) { oldHighlighter.Dispose(); } }