From aa2820ba71c6880c701442d41bcde67c4652f658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Thu, 4 May 2017 10:59:52 +0200 Subject: Fixed 'Bug 55915 - Editor doesn't render the full text' Extracted roslyn classification highlighting so it can be re used for c# bypassing the slow textmate highlighter in future versions. --- .../MonoDevelop.VBNet/VBNetTextEditorExtension.cs | 84 +--------------------- 1 file changed, 3 insertions(+), 81 deletions(-) (limited to 'main/src/addins/VBNetBinding') diff --git a/main/src/addins/VBNetBinding/MonoDevelop.VBNet/VBNetTextEditorExtension.cs b/main/src/addins/VBNetBinding/MonoDevelop.VBNet/VBNetTextEditorExtension.cs index 4aee67be78..78de131c09 100644 --- a/main/src/addins/VBNetBinding/MonoDevelop.VBNet/VBNetTextEditorExtension.cs +++ b/main/src/addins/VBNetBinding/MonoDevelop.VBNet/VBNetTextEditorExtension.cs @@ -110,92 +110,14 @@ namespace MonoDevelop.VBNet ); workspace.OpenSolutionInfo (sInfo); - Editor.SyntaxHighlighting = new ClassificationSyntaxHighlighting (workspace, documentId); - workspace.InformDocumentOpen (documentId, Editor); + Editor.SyntaxHighlighting = new RoslynClassificationHighlighting (workspace, documentId, "source.vb"); + workspace.InformDocumentOpen (documentId, Editor); } public override void Dispose () { base.Dispose (); - workspace.CloseDocument (documentId); - } - - class ClassificationSyntaxHighlighting : ISyntaxHighlighting - { - DocumentId documentId; - MonoDevelopWorkspace workspace; - - public ClassificationSyntaxHighlighting (MonoDevelopWorkspace workspace, DocumentId documentId) - { - this.workspace = workspace; - this.documentId = documentId; - } - - public event EventHandler HighlightingStateChanged; - - public async Task GetHighlightedLineAsync (IDocumentLine line, CancellationToken cancellationToken) - { - List coloredSegments = new List (); - - int offset = line.Offset; - int length = line.Length; - var span = new TextSpan (offset, length); - - var classifications = Classifier.GetClassifiedSpans (await workspace.GetDocument (documentId).GetSemanticModelAsync (), span, workspace, cancellationToken); - - - int lastClassifiedOffsetEnd = offset; - ScopeStack scopeStack; - - foreach (var curSpan in classifications) { - if (curSpan.TextSpan.Start > lastClassifiedOffsetEnd) { - scopeStack = vbScope.Push (EditorThemeColors.UserTypes); - ColoredSegment whitespaceSegment = new ColoredSegment (lastClassifiedOffsetEnd, curSpan.TextSpan.Start - lastClassifiedOffsetEnd, scopeStack); - coloredSegments.Add (whitespaceSegment); - } - - string styleName = GetStyleNameFromClassificationType (curSpan.ClassificationType); - scopeStack = vbScope.Push (styleName); - ColoredSegment curColoredSegment = new ColoredSegment (curSpan.TextSpan.Start, curSpan.TextSpan.Length, scopeStack); - coloredSegments.Add (curColoredSegment); - - lastClassifiedOffsetEnd = curSpan.TextSpan.End; - } - - if (offset + length > lastClassifiedOffsetEnd) { - scopeStack = vbScope.Push (EditorThemeColors.UserTypes); - ColoredSegment whitespaceSegment = new ColoredSegment (lastClassifiedOffsetEnd, offset + length - lastClassifiedOffsetEnd, scopeStack); - coloredSegments.Add (whitespaceSegment); - } - - return new HighlightedLine (line, coloredSegments); - } - - private string GetStyleNameFromClassificationType (string classificationType) - { - switch (classificationType) { - case ClassificationTypeNames.Comment: - case ClassificationTypeNames.ExcludedCode: - return "comment.source.vb"; - case ClassificationTypeNames.PreprocessorKeyword: - return "keyword.source.vb"; - case ClassificationTypeNames.Keyword: - return "keyword.source.vb"; - case ClassificationTypeNames.StringLiteral: - return "string.quoted.double.source.cs"; - case ClassificationTypeNames.VerbatimStringLiteral: - return "string.quoted.other.verbatim.source.vb"; - default: - return ""; - } - } - - static readonly ScopeStack vbScope = new ScopeStack ("source.vb"); - - public Task GetScopeStackAsync (int offset, CancellationToken cancellationToken) - { - return Task.FromResult (vbScope); - } + workspace.CloseDocument (documentId); } } } -- cgit v1.2.3