public int GetStateForPosition(int pos, ITextSnapshot snapshot, string fileName, ProbeAppSettings appSettings) { _snapshot = snapshot; var line = _snapshot.GetLineFromPosition(pos); var state = GetStateForLineStart(line.LineNumber, snapshot, fileName, appSettings); var lineStartPos = line.Start.Position; var fileStore = CodeModel.FileStore.GetOrCreateForTextBuffer(snapshot.TextBuffer); if (fileStore == null) { return(0); } var model = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "GetStateForPosition"); if (lineStartPos <= pos) { var lineText = line.GetTextIncludingLineBreak(); if (pos - lineStartPos < lineText.Length) { lineText = lineText.Substring(0, pos - lineStartPos); } _scanner.SetSource(lineText, line.Start.Position, line.Snapshot, model); var tokenInfo = new ProbeClassifierScanner.TokenInfo(); while (_scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state)) { ; } } return(state); }
public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span) // from IClassifier { ThreadHelper.ThrowIfNotOnUIThread(); _snapshot = span.Snapshot; var appSettings = ProbeEnvironment.CurrentAppSettings; var fileName = VsTextUtil.TryGetDocumentFileName(span.Snapshot.TextBuffer); var tracker = TextBufferStateTracker.GetTrackerForTextBuffer(span.Snapshot.TextBuffer); var spans = new List <ClassificationSpan>(); var state = tracker.GetStateForPosition(span.Start.Position, span.Snapshot, fileName, appSettings); var tokenInfo = new ProbeClassifierScanner.TokenInfo(); var fileStore = CodeModel.FileStore.GetOrCreateForTextBuffer(span.Snapshot.TextBuffer); if (fileStore == null) { return(new List <ClassificationSpan>()); } var model = fileStore.GetMostRecentModel(appSettings, fileName, span.Snapshot, "GetClassificationSpans"); _scanner.SetSource(span.GetText(), span.Start.Position, span.Snapshot, model); var disableDeadCode = ProbeToolsPackage.Instance.EditorOptions.DisableDeadCode; DisabledSectionTracker disabledSectionTracker = null; if (disableDeadCode) { disabledSectionTracker = new DisabledSectionTracker(model.DisabledSections); if (disabledSectionTracker.SetOffset(_scanner.PositionOffset)) { state |= State.Disabled; } else { state &= ~State.Disabled; } } else { state &= ~State.Disabled; } while (_scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state)) { var classificationType = GetClassificationType(tokenInfo.Type); if (classificationType != null) { spans.Add(new ClassificationSpan(new SnapshotSpan(_snapshot, new Span(span.Start.Position + tokenInfo.StartIndex, tokenInfo.Length)), classificationType)); } if (disableDeadCode) { if (disabledSectionTracker.Advance(_scanner.PositionOffset + _scanner.Position)) { state |= State.Disabled; } else { state &= ~State.Disabled; } } else { state &= ~State.Disabled; } } return(spans); }