/// <summary> /// Parses the entire source code /// </summary> private async void ParseDocument() { // --- Do not start parsing over existing parsing if (_isProcessing) { return; } _isProcessing = true; await Task.Run(() => { try { // --- Get the entire text of the source code var span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); var source = _buffer.CurrentSnapshot.GetText(span); // --- Let's use the Z80 assembly parser to obtain tags var visitor = Z80AsmVisitor.VisitSource(source); lock (_locker) { _z80SyntaxTreeVisitor = visitor; } // --- Code is parsed, sign the change ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); } finally { _isProcessing = false; } }); }
private void OnClassificationChanged(SnapshotSpan span) { if (this._buffer.CurrentSnapshot.Version == span.Snapshot.Version) { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); } }
public void textChanged(object o, TextContentChangedEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); ParseTree.Tree.Parse(e.After.GetText(), out bool parsed); results.Clear(); var root = ParseTree.Tree.Root(); Parse(root); //results.Add(new Result { span = new Span(0, e.After.Length - 1), type = NodeType.MPLCONTENT }); var errorStack = ParseTree.Tree.GetErrorStack(); generalPane.Clear(); if (!parsed) { try { foreach (var error in errorStack) { var document = getPropertyFromBuffer <ITextDocument>(e.Before.TextBuffer); string message = document.FilePath + error.getMessage() + '\n'; generalPane.OutputString(message); generalPane.Activate(); } } catch (InvalidOperationException er) { generalPane.OutputString(er.Message); generalPane.Activate(); } } ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(e.After, 0, e.After.Length))); }
private void Subclassification_Changed(object sender, ClassificationChangedEventArgs e) { var c = (IClassifier)sender; var refreshSpans = c.GetClassificationSpans(e.ChangeSpan); ClassificationChanged?.Invoke(this, e); }
private List <PrioritiesClassificationSpan> ParseMultiLine(SnapshotSpan span) { List <PrioritiesClassificationSpan> classifications = new List <PrioritiesClassificationSpan>(); string code = span.GetText(); int startPosition = IndexOfCommentStart(code); if (startPosition < 0) { return(new List <PrioritiesClassificationSpan>()); } int segmentIndex = span.Start.Position + startPosition; int lineNumber = span.Snapshot.GetLineNumberFromPosition(segmentIndex); try { string codeSegment = span.Snapshot.GetLineFromLineNumber(lineNumber).GetText(); int endPosition = IndexOfCommentEnd(codeSegment); while (endPosition < 0) { ++lineNumber; codeSegment = span.Snapshot.GetLineFromLineNumber(lineNumber).GetText(); endPosition = IndexOfCommentEnd(codeSegment); } } catch (ArgumentOutOfRangeException) { lineNumber = lineNumber - 1; } int startIndex = span.Start.Position + startPosition; int endIndex = span.Snapshot.GetLineFromLineNumber(lineNumber).End.Position; var multiSpan = new SnapshotSpan(span.Snapshot, startIndex, (endIndex - startIndex)); if (multiSpan.End > span.End) { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(span.End + 1, multiSpan.End))); } var priorClassification = new PrioritiesClassificationSpan { Span = new ClassificationSpan(multiSpan, m_Type), Priority = 400 }; classifications.Add(priorClassification); if (m_MultiLineComments.Any(a => a.Tracking.GetSpan(span.Snapshot).Span == multiSpan.Span) == false) { m_MultiLineComments.Add(new MultiLineComment() { Version = span.Snapshot.Version, Tracking = span.Snapshot.CreateTrackingSpan(multiSpan.Span, SpanTrackingMode.EdgeExclusive) }); } return(classifications); }
internal GlslClassifier(ITextBuffer textBuffer, SyntaxColorParser parser, ILogger logger) { if (textBuffer is null) { throw new ArgumentNullException(nameof(textBuffer)); } if (parser is null) { throw new ArgumentNullException(nameof(parser)); } if (logger is null) { throw new ArgumentNullException(nameof(logger)); } var observableSnapshot = Observable.Return(textBuffer.CurrentSnapshot).Concat( Observable.FromEventPattern <TextContentChangedEventArgs>(h => textBuffer.Changed += h, h => textBuffer.Changed -= h) .Select(e => e.EventArgs.After)); parser.Changed += _ => UpdateSpans(); void UpdateSpans() { #if DEBUG var time = Stopwatch.StartNew(); #endif var snapshotSpan = new SnapshotSpan(textBuffer.CurrentSnapshot, 0, textBuffer.CurrentSnapshot.Length); var spans = parser.CalculateSpans(snapshotSpan); #if DEBUG logger.Log($"{time.ElapsedTicks * 1e3f / Stopwatch.Frequency}ms : tokens={spans.Count}"); #endif this.spans = spans; ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(snapshotSpan)); } observableSnapshot .Throttle(TimeSpan.FromSeconds(0.3f)) .Subscribe(_ => UpdateSpans()); //UpdateSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, 0, textBuffer.CurrentSnapshot.Length)); //textBuffer.Changed += (s, a) => //{ // // ignore not up-to-date versions // if (a.After != textBuffer.CurrentSnapshot) return; // var start = a.Changes.Min(change => Math.Min(change.OldPosition, change.NewPosition)); // var end = a.Changes.Max(change => Math.Max(change.OldEnd, change.NewEnd)); // var length = Math.Min(end - start, textBuffer.CurrentSnapshot.Length); // var changeSpan = new SnapshotSpan(textBuffer.CurrentSnapshot, start, length); // var changeText = changeSpan.GetText(); // //if(changeText.Contains('{') || changeText.Contains('}') || changeText.Contains('*') || ) // //UpdateSpans(changeSpan); // UpdateSpans(new SnapshotSpan(textBuffer.CurrentSnapshot, 0, textBuffer.CurrentSnapshot.Length)); //}; }
private void RebuidTokens() { CommentTable.Clear(); ClassfificationList.Clear(); QuickInfoList.Clear(); StructNameList.Clear(); BracePairList.Clear(); OutlineList.Clear(); ErrorList.Clear(); var snapshot = this.Buffer.CurrentSnapshot; var lexer = new FlatbufferLexer(new AntlrInputStream(snapshot.GetText())); foreach (var token in lexer.GetAllTokens()) { if (token.Type == FlatbufferLexer.COMMENT) { ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), FBSComment)); var txt = token.Text; if (txt.StartsWith("//")) { txt = txt.Substring(2).Trim(); } else if (txt.StartsWith("/*")) { txt = txt.Substring(2, txt.Length - 4).Trim().Trim('*').Trim(); } var lines = txt.Split('\n'); for (int i = 0; i < lines.Length; i++) { CommentTable.Add(token.Line + i, txt); } } } lexer.Reset(); var parser = new FlatbufferParser(new CommonTokenStream(lexer)); parser.ErrorHandler = classificationErrorHandler; parser.RemoveErrorListeners(); parser.AddErrorListener(classificationErrorListener); parser.schema().Accept <int>(classificationVisitor); var dom = this.Buffer.Properties.GetProperty(typeof(ITextDocument)); if (dom != null) { filePath = (dom as ITextDocument).FilePath; FBSProject builder = new FBSProject("", new string[] { filePath }, ErrorReport); builder.Build(filePath, snapshot.GetText()); } ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))); }
private void AnalysisUpdated(IAnalysisResult analysisResult, RescanReason reason, CancellationToken ct) { _analysisResult = analysisResult; if (reason != RescanReason.ContentChanged) { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(analysisResult.Snapshot, 0, analysisResult.Snapshot.Length))); } }
public void Update(AmmyFile <Top> file) { _latestFile = file; var snapshot = (ITextSnapshot)_latestFile.Meta.Snapshot; var snapshotSpan = new SnapshotSpan(snapshot, 0, snapshot.Length); var eventArgs = new ClassificationChangedEventArgs(snapshotSpan); ClassificationChanged?.Invoke(this, eventArgs); }
private void OnEditorOptionsChanged(EditorChangedEventArgs args) { // NOTE: if the state of editor option was changed => raise that classifications were changed for the current buffer if (args.Changes.TryGetValue(Language, out var isEnable) && isEnable != _isEnable) { _isEnable = isEnable; var span = new SnapshotSpan(_textBuffer.CurrentSnapshot, new Span(0, _textBuffer.CurrentSnapshot.Length)); ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); } }
void TagAggregator_TagsChanged(object?sender, TagsChangedEventArgs e) { if (ClassificationChanged is null) { return; } foreach (var span in e.Span.GetSpans(textBuffer)) { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); } }
/// <summary> /// Parses the entire source code /// </summary> private async void ParseDocument() { // --- Do not start parsing over existing parsing if (_isProcessing) { _reParse = true; return; } _isProcessing = true; await DoParse(); while (_reParse) { _reParse = false; _isProcessing = true; await DoParse(); } async Task DoParse() { await Task.Run(() => { try { // --- Get the entire text of the source code var span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); var source = _buffer.CurrentSnapshot.GetText(span); // --- Let's use the Z80 assembly parser to obtain tags var inputStream = new AntlrInputStream(source); var lexer = new ZxBasicLexer(inputStream); var tokenStream = new CommonTokenStream(lexer); var parser = new ZxBasicParser(tokenStream); var context = parser.compileUnit(); var treeWalker = new ParseTreeWalker(); var parserListener = new ZxBasicParserListener(_buffer); treeWalker.Walk(parserListener, context); lock (_locker) { _tokenMap = parserListener.TokenMap; } // --- Code is parsed, sign the change ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); } finally { _isProcessing = false; } }); } }
private async void ParseDocument() { if (_isProcessing) return; _isProcessing = true; await Task.Run(() => { _doc = _buffer.CurrentSnapshot.ParseToMarkdown(_file); SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); _isProcessing = false; }); }
private Task OnNewAnalysisEntryAsync(PythonTextBufferInfo sender, AnalysisEntry entry) { var analyzer = entry?.Analyzer; if (analyzer == null) { Debug.Assert(entry == null, "Should not have new analysis entry without an analyzer"); return(Task.CompletedTask); } var snapshot = sender.CurrentSnapshot; ClassificationChanged?.Invoke( this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)) ); return(Task.CompletedTask); }
private Task OnTextContentChangedAsync(PythonTextBufferInfo sender, TextContentChangedEventArgs e) { // NOTE: Runs on background thread if (e == null) { Debug.Fail("Invalid type passed to event"); } var snapshot = e.After; if (snapshot.IsReplBufferWithCommand()) { return(Task.CompletedTask); } Span changedSpan = new Span(0, 0); foreach (var change in e.Changes) { if (changedSpan.Length == 0) { changedSpan = change.NewSpan; } else { changedSpan = Span.FromBounds( Math.Min(change.NewSpan.Start, changedSpan.Start), Math.Max(change.NewSpan.End, changedSpan.End) ); } } if (changedSpan.Length > 0) { ClassificationChanged?.Invoke( this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, changedSpan)) ); } return(Task.CompletedTask); }
/// <summary> /// Parses the entire source code /// </summary> private async void ParseDocument() { // --- Do not start parsing over existing parsing if (_isProcessing) { return; } _isProcessing = true; await Task.Run(() => { try { // --- Get the entire text of the source code var span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); var source = _buffer.CurrentSnapshot.GetText(span); // --- Let's use the Z80 assembly parser to obtain tags var inputStream = new AntlrInputStream(source); var lexer = new Z80TestLexer(inputStream); var tokenStream = new CommonTokenStream(lexer); var parser = new Z80TestParser(tokenStream); var context = parser.compileUnit(); var commentWalker = new ParseTreeWalker(); var parserListener = new Z80TestParserListener(tokenStream); commentWalker.Walk(parserListener, context); _commentSpans = parserListener.CommentSpans; _z80TestVisitor = new Z80TestVisitor(); _z80TestVisitor.Visit(context); // --- Code is parsed, sign the change ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); } finally { _isProcessing = false; } }); }
private async void ParseDocument() { if (_isProcessing) { return; } _isProcessing = true; await Task.Run(() => { var rawText = _buffer.CurrentSnapshot.GetText(); _doc = MarkdownParser.Parse(rawText, _pipeline); SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length); ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span)); _isProcessing = false; }); }
private void OnNewClassifications(ITextSnapshot snapshot) { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))); }
protected virtual void OnTextChanged(int start, int oldLength, int newLength) { // Invalidate items starting from start of the change and onward // Expand range to take into accound token that might be just touching // changed area. For example, in PHP / is punctuation token and adding * // to it should remove / so tokenizer can recreate comment token. // However / is technically outside of the changed area and hence may end up // lingering on. int initialIndex = -1; int changeStart = start; var touchingTokens = Tokens.GetItemsContainingInclusiveEnd(start); if (touchingTokens != null && touchingTokens.Count > 0) { initialIndex = touchingTokens.Min(); start = Tokens[initialIndex].Start; } // nothing is touching but we still might have tokens right after us if (initialIndex < 0) { initialIndex = Tokens.GetFirstItemAfterOrAtPosition(start); } if (initialIndex == 0) { start = Tokens[0].Start; } else { while (initialIndex > 0) { if (Tokens[initialIndex - 1].End == start) { start = Tokens[initialIndex - 1].Start; initialIndex--; } else { break; } } } _lastValidPosition = Math.Min(_lastValidPosition, start); if (Tokens.Count > 0) { Tokens.RemoveInRange(TextRange.FromBounds(_lastValidPosition, Tokens[Tokens.Count - 1].End), true); } // In line-based tokenizers like SaSS or Jade we need to start at the beginning // of the line i.e. at 'anchor' position that is calculated depending on // the particular language syntax. _lastValidPosition = GetAnchorPosition(_lastValidPosition); RemoveSensitiveTokens(_lastValidPosition, Tokens); VerifyTokensSorted(); _lastValidPosition = Tokens.Count > 0 ? Math.Min(_lastValidPosition, Tokens[Tokens.Count - 1].End) : 0; ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs( new SnapshotSpan(TextBuffer.CurrentSnapshot, Span.FromBounds(_lastValidPosition, TextBuffer.CurrentSnapshot.Length))) ); }
public void InvokeClassificationChanged(ClassificationChangedEventArgs eventArgs) { ClassificationChanged?.Invoke(this, eventArgs); }
private void LexerClassificationChanged(object sender, ClassificationChangedEventArgs e) { ClassificationChanged?.Invoke(sender, e); }
private async Task OnTextContentChangedAsync(PythonTextBufferInfo sender, TextContentChangedEventArgs e) { // NOTE: Runs on background thread if (e == null) { Debug.Fail("Invalid type passed to event"); } var snapshot = e.After; if (snapshot.IsReplBufferWithCommand()) { return; } int firstLine = int.MaxValue, lastLine = int.MinValue; foreach (var change in e.Changes) { if (change.LineCountDelta > 0) { firstLine = Math.Min(firstLine, snapshot.GetLineNumberFromPosition(change.NewPosition)); lastLine = Math.Max(lastLine, snapshot.GetLineNumberFromPosition(change.NewEnd)); } else if (change.LineCountDelta < 0) { firstLine = Math.Min(firstLine, snapshot.GetLineNumberFromPosition(change.NewPosition)); if (change.OldEnd < snapshot.Length) { lastLine = Math.Max(lastLine, snapshot.GetLineNumberFromPosition(change.OldEnd)); } else { lastLine = snapshot.LineCount - 1; } } else { int line = snapshot.GetLineNumberFromPosition(change.NewPosition); firstLine = Math.Min(firstLine, line); lastLine = Math.Max(lastLine, line); } } if (lastLine >= firstLine) { SnapshotSpan changedSpan; try { if (lastLine == firstLine) { changedSpan = snapshot.GetLineFromLineNumber(firstLine).ExtentIncludingLineBreak; } else { changedSpan = new SnapshotSpan( snapshot.GetLineFromLineNumber(firstLine).Start, snapshot.GetLineFromLineNumber(lastLine).EndIncludingLineBreak ); } } catch (ArgumentException ex) { Debug.Fail(ex.ToUnhandledExceptionMessage(GetType())); return; } await Task.Yield(); ClassificationChanged?.Invoke( this, new ClassificationChangedEventArgs(changedSpan) ); } }
protected override void RaiseChanged(SnapshotSpan span) { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); }
private void Classifier_ClassificationChanged(Object sender, ClassificationChangedEventArgs e) { ClassificationChanged?.Invoke(sender, e); }
private void FireClassificationChanged() { // This is only here to suppress the warning that the event is never used. // Classification should never change for a function signature. ClassificationChanged?.Invoke(this, null); }
protected virtual void OnClassificationChanged(ClassificationChangedEventArgs e) { ClassificationChanged?.Invoke(this, e); }
public List <PrioritiesClassificationSpan> Parse(SnapshotSpan span) { List <PrioritiesClassificationSpan> classifications = new List <PrioritiesClassificationSpan>(); bool isInsideOfComment = false; for (int i = m_MultiLineComments.Count - 1; i >= 0; i--) { var comment = m_MultiLineComments[i]; var multiSpan = comment.Tracking.GetSpan(span.Snapshot); if (multiSpan.Length == 0) { m_MultiLineComments.RemoveAt(i); continue; } if (span.IntersectsWith(multiSpan) == false) { continue; } isInsideOfComment = true; if (span.Snapshot.Version == comment.Version) { var prioSpan = new PrioritiesClassificationSpan(); prioSpan.Span = new ClassificationSpan(multiSpan, m_Type); prioSpan.Priority = 400; classifications.Add(prioSpan); } else { m_MultiLineComments.RemoveAt(i); ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(multiSpan)); continue; } } if (isInsideOfComment == false) { classifications.AddRange(ParseMultiLine(span)); } string code = span.GetText(); var matches = m_Regex.Matches(code); if (matches.Count == 0) { return(classifications); } foreach (Match match in matches) { if (IsMatchInString(match, span)) { continue; } Span spanWord = new Span(span.Start.Position + match.Index, span.GetText().Length - match.Index); SnapshotSpan snapshot = new SnapshotSpan(span.Snapshot, spanWord); var prioSpan = new PrioritiesClassificationSpan(); prioSpan.Span = new ClassificationSpan(snapshot, m_Type); prioSpan.Priority = 400; classifications.Add(prioSpan); } return(classifications); }
/// <summary> /// Force refresh a span stored on last update (assume it corresponds to currently active document) /// </summary> public void Invalidate() { ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(CurrentSpan)); }
void HexTagAggregator_TagsChanged(object sender, HexTagsChangedEventArgs e) => ClassificationChanged?.Invoke(this, new HexClassificationChangedEventArgs(e.Span));
private void Compleate(object sender, EventArgs e) { var span = new SnapshotSpan(TextBuffer.CurrentSnapshot, 0, TextBuffer.CurrentSnapshot.Length); ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(span)); }