public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (session == null || qiContent == null) return; // Map the trigger point down to our buffer. SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; var snapshot = _buffer.CurrentSnapshot; var classifier = _classifierService.GetClassifier(_buffer); var doc = new SnapshotSpan(snapshot, 0, snapshot.Length); var line = point.Value.GetContainingLine(); var idents = classifier.GetClassificationSpans(line.Extent); bool handled = HandleVariables(qiContent, ref applicableToSpan, idents, point); if (handled) return; HandleKeywords(qiContent, ref applicableToSpan, idents, point); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; SnapshotPoint? point = session.GetTriggerPoint(session.TextView.TextBuffer.CurrentSnapshot); if (!point.HasValue) return; HtmlEditorTree tree = HtmlEditorDocument.FromTextView(session.TextView).HtmlEditorTree; ElementNode node = null; AttributeNode attr = null; tree.GetPositionElement(point.Value.Position, out node, out attr); if (node == null || !node.Name.Equals("img", StringComparison.OrdinalIgnoreCase)) return; if (attr == null || !attr.Name.Equals("src", StringComparison.OrdinalIgnoreCase)) return; string url = ImageQuickInfo.GetFullUrl(attr.Value, session.TextView.TextBuffer); if (string.IsNullOrEmpty(url)) return; applicableToSpan = session.TextView.TextBuffer.CurrentSnapshot.CreateTrackingSpan(point.Value.Position, 1, SpanTrackingMode.EdgeNegative); ImageQuickInfo.AddImageContent(qiContent, url); }
internal ExpressionAnalysis(string expression, ModuleAnalysis analysis, int lineNo, ITrackingSpan span) { _expr = expression; _analysis = analysis; _lineNo = lineNo; _span = span; }
private bool HandleVariables(IList<object> qiContent, ref ITrackingSpan applicableToSpan, IList<ClassificationSpan> spans, SnapshotPoint? point) { ClassificationSpan span; string text = GetText(spans, point, PredefinedClassificationTypeNames.SymbolDefinition, out span); if (string.IsNullOrWhiteSpace(text)) return false; string value = Environment.GetEnvironmentVariable(text.Trim('%')); if (string.IsNullOrEmpty(value)) return false; string displayText = value; if (value.Equals("path", StringComparison.OrdinalIgnoreCase)) displayText = string.Join(Environment.NewLine, value.Split(';')); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(span.Span, SpanTrackingMode.EdgeNegative); qiContent.Add(displayText); string expanded = Environment.ExpandEnvironmentVariables(value); if (expanded != value) qiContent.Add(expanded); return true; }
public ProvisionalText(ITextView textView, Span textSpan) { IgnoreChange = false; _textView = textView; var wpfTextView = (IWpfTextView)_textView; _layer = wpfTextView.GetAdornmentLayer("HtmlProvisionalTextHighlight"); var textBuffer = _textView.TextBuffer; var snapshot = textBuffer.CurrentSnapshot; var provisionalCharSpan = new Span(textSpan.End - 1, 1); TrackingSpan = snapshot.CreateTrackingSpan(textSpan, SpanTrackingMode.EdgeExclusive); _textView.Caret.PositionChanged += OnCaretPositionChanged; textBuffer.Changed += OnTextBufferChanged; textBuffer.PostChanged += OnPostChanged; var projectionBuffer = _textView.TextBuffer as IProjectionBuffer; if (projectionBuffer != null) { projectionBuffer.SourceSpansChanged += OnSourceSpansChanged; } Color highlightColor = SystemColors.HighlightColor; Color baseColor = Color.FromArgb(96, highlightColor.R, highlightColor.G, highlightColor.B); _highlightBrush = new SolidColorBrush(baseColor); ProvisionalChar = snapshot.GetText(provisionalCharSpan)[0]; HighlightSpan(provisionalCharSpan.Start); }
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { HexColorValue hex = (HexColorValue)item; if (!item.IsValid) yield break; ColorModel model = ColorParser.TryParseColor(hex.Text, ColorParser.Options.None); if (model != null) { if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null) { yield return new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.Name); } if (model.Format == ColorFormat.RgbHex6) { string hex3 = ColorFormatter.FormatColor(model, ColorFormat.RgbHex3); if (hex3.Length == 4) { yield return new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.RgbHex3); } } yield return new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.Rgb); yield return new ColorConverterSmartTagAction(itemTrackingSpan, hex, model, ColorFormat.Hsl); } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (!EnsureTreeInitialized() || session == null || qiContent == null) return; // Map the trigger point down to our buffer. SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) return; Declaration dec = item.FindType<Declaration>(); if (dec == null || !dec.IsValid || !_allowed.Contains(dec.PropertyName.Text.ToUpperInvariant())) return; string fontName = item.Text.Trim('\'', '"'); if (fonts.Families.SingleOrDefault(f => f.Name.Equals(fontName, StringComparison.OrdinalIgnoreCase)) != null) { FontFamily font = new FontFamily(fontName); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative); qiContent.Add(CreateFontPreview(font, 10)); qiContent.Add(CreateFontPreview(font, 11)); qiContent.Add(CreateFontPreview(font, 12)); qiContent.Add(CreateFontPreview(font, 14)); qiContent.Add(CreateFontPreview(font, 25)); qiContent.Add(CreateFontPreview(font, 40)); } }
internal Signature(ITrackingSpan trackingSpan, string content, string prettyPrintedContent, string documentation) { this.trackingSpan = trackingSpan; this.content = content; this.prettyPrintedContent = prettyPrintedContent; this.documentation = documentation; }
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { Declaration dec = (Declaration)item; if (!item.IsValid || position > dec.Colon.Start) yield break; RuleBlock rule = dec.FindType<RuleBlock>(); if (!rule.IsValid) yield break; ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaRootForBuffer(itemTrackingSpan.TextBuffer); if (!dec.IsVendorSpecific()) { IEnumerable<Declaration> vendors = VendorHelpers.GetMatchingVendorEntriesInRule(dec, rule, schema); if (vendors.Any(v => v.Start > dec.Start)) { yield return new VendorOrderSmartTagAction(itemTrackingSpan, vendors.Last(), dec); } } else { ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, schema); if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText)) { yield return new MissingStandardSmartTagAction(itemTrackingSpan, dec, entry.DisplayText); } } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (!EnsureTreeInitialized() || session == null || qiContent == null) return; // Map the trigger point down to our buffer. SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) return; Selector sel = item.FindType<Selector>(); if (sel == null) return; // Mixins don't have specificity if (sel.SimpleSelectors.Count == 1 && sel.SimpleSelectors[0].SubSelectors.Count == 1 && sel.SimpleSelectors[0].SubSelectors[0] is LessMixinDeclaration) return; applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative); string content = GenerateContent(sel); qiContent.Add(content); }
/// <summary> /// Determine which pieces of Quickinfo content should be displayed /// </summary> public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (_disposed) throw new ObjectDisposedException("TestQuickInfoSource"); var triggerPoint = (SnapshotPoint) session.GetTriggerPoint(_buffer.CurrentSnapshot); if (triggerPoint == null) return; foreach (IMappingTagSpan<LuaTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint))) { if (curTag.Tag.type == LuaTokenTypes.ReservedWord) { var tagSpan = curTag.Span.GetSpans(_buffer).First(); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add("A reserved word"); } else if (curTag.Tag.type == LuaTokenTypes.Operators) { var tagSpan = curTag.Span.GetSpans(_buffer).First(); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add("A language operator"); } } }
public void AugmentQuickInfoSession( IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; SnapshotPoint? subjectTriggerPoint = session.GetTriggerPoint(textBuffer.CurrentSnapshot); if ( !subjectTriggerPoint.HasValue ) { return; } ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot; SnapshotSpan querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var tagAggregator = GetAggregator(session); TextExtent extent = FindExtentAtPoint(subjectTriggerPoint); if ( CheckForPrefixTag(tagAggregator, extent.Span) ) { string text = extent.Span.GetText(); string url = FindNSUri(extent.Span, GetDocText(extent.Span)); applicableToSpan = currentSnapshot.CreateTrackingSpan( extent.Span, SpanTrackingMode.EdgeInclusive ); String toolTipText = String.Format("Prefix: {0}\r\nNamespace: {1}", text, url); quickInfoContent.Add(toolTipText); } }
public void PresentItem(ITrackingSpan triggerSpan, QuickInfoItem item, bool trackMouse) { AssertIsForeground(); _triggerSpan = triggerSpan; _item = item; // It's a new list of items. Either create the editor session if this is the first time, or ask the // editor session that we already have to recalculate. if (_editorSessionOpt == null || _editorSessionOpt.IsDismissed) { // We're tracking the caret. Don't have the editor do it. var triggerPoint = triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative); _editorSessionOpt = _quickInfoBroker.CreateQuickInfoSession(_textView, triggerPoint, trackMouse: trackMouse); _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed(); } // So here's the deal. We cannot create the editor session and give it the right // signatures (even though we know what they are). Instead, the session with // call back into the ISignatureHelpSourceProvider (which is us) to get those // values. It will pass itself along with the calls back into // ISignatureHelpSourceProvider. So, in order to make that connection work, we // add properties to the session so that we can call back into ourselves, get // the signatures and add it to the session. if (!_editorSessionOpt.Properties.ContainsProperty(s_augmentSessionKey)) { _editorSessionOpt.Properties.AddProperty(s_augmentSessionKey, this); } _editorSessionOpt.Recalculate(); }
/// <summary> /// Determine which pieces of Quickinfo content should be displayed /// </summary> public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (_disposed) throw new ObjectDisposedException("TestQuickInfoSource"); var triggerPoint = (SnapshotPoint) session.GetTriggerPoint(_buffer.CurrentSnapshot); if (triggerPoint == null) return; foreach (IMappingTagSpan<OokTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint))) { if (curTag.Tag.type == OokTokenTypes.OokExclamation) { var tagSpan = curTag.Span.GetSpans(_buffer).First(); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add("Exclaimed Ook!"); } else if (curTag.Tag.type == OokTokenTypes.OokQuestion) { var tagSpan = curTag.Span.GetSpans(_buffer).First(); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add("Question Ook?"); } else if (curTag.Tag.type == OokTokenTypes.OokPeriod) { var tagSpan = curTag.Span.GetSpans(_buffer).First(); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add("Regular Ook."); } } }
internal static bool ShowCompletion(ITextView view) { bool result = false; if (ISESnippetSessionManager.activeSession != null) { ISESnippetSessionManager.activeSession.Dismiss(); } EditorImports.CompletionBroker.DismissAllSessions(view); if (!CommandImplementation.CanShowSnippet()) { return result; } ISESnippetSessionManager.activeSession = EditorImports.CompletionBroker.TriggerCompletion(view); if (ISESnippetSessionManager.activeSession == null) { return result; } ISESnippetSessionManager.activeSession.Committed += ISESnippetSessionManager.eventHandlerSessionCommitted; ISESnippetSessionManager.activeSession.Dismissed += ISESnippetSessionManager.eventHandlerSessionDismissed; ISESnippetSessionManager.activeSession.SelectedCompletionSet.SelectionStatusChanged += ISESnippetSessionManager.eventHandlerSelectionChanged; ISESnippetSessionManager.activeSession.SelectedCompletionSet.SelectionStatus = new CompletionSelectionStatus(ISESnippetSessionManager.activeSession.SelectedCompletionSet.Completions[0], true, true); ISESnippetSessionManager.selectedSnippet = (ISESnippetSessionManager.activeSession.SelectedCompletionSet.SelectionStatus.Completion.Properties["SnippetInfo"] as ISESnippet); ISESnippetSessionManager.insertSpan = ISESnippetSessionManager.activeSession.SelectedCompletionSet.ApplicableTo; ISESnippetSessionManager.canFilter = true; return true; }
public LowerCaseSmartTagAction(ITrackingSpan span) { this.span = span; tsnapshot = span.TextBuffer.CurrentSnapshot; lower = span.GetText(tsnapshot).ToLower(); display = "Convert to lower case"; }
public GenerateFieldSmartTagAction(ITrackingSpan span) { trackingSpan = span; snapShot = span.TextBuffer.CurrentSnapshot; m_upper = span.GetText(snapShot).ToUpper(); displayText = "生成属性"; }
public CustomTrackingSpan(ITrackingSpan referenceSpan) { if (referenceSpan == null) throw new ArgumentNullException("referenceSpan"); _referenceSpan = referenceSpan; }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (session == null || qiContent == null) return; // Map the trigger point down to our buffer. SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; JSONEditorDocument doc = JSONEditorDocument.FromTextBuffer(_buffer); JSONParseItem item = doc.JSONDocument.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) return; JSONMember dependency = item.FindType<JSONMember>(); if (dependency == null || dependency.Name != item) return; var parent = dependency.Parent.FindType<JSONMember>(); if (parent == null || !parent.UnquotedNameText.EndsWith("dependencies", StringComparison.OrdinalIgnoreCase)) return; applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative); UIElement element = CreateTooltip(dependency.UnquotedNameText, item); if (element != null) qiContent.Add(element); }
public void ShowToolTip(ITrackingSpan span, object toolTipContent) { if (span == null) throw new ArgumentNullException(nameof(span)); if (toolTipContent == null) throw new ArgumentNullException(nameof(toolTipContent)); ShowToolTip(span, toolTipContent, PopupStyles.None); }
public ValueOrderSignature( string syntax, string description, ITrackingSpan trackingSpan, ISignatureHelpSession session) { _propertyName = "Syntax"; _syntax = syntax ?? string.Empty; _description = description; _trackingSpan = trackingSpan; _content = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", _propertyName, _syntax); _nameParam = new CssPropertyNameParameter(this); _currentParam = _nameParam; _session = session; // In order to dismiss this tip at the appropriate time, I need to listen // to changes in the text buffer if (_trackingSpan != null && _session != null) { _session.Dismissed += OnSessionDismissed; _trackingSpan.TextBuffer.Changed += OnTextBufferChanged; } }
internal CompletionAnalysis(IServiceProvider serviceProvider, ITextView view, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options) { _view = view; _span = span; _serviceProvider = serviceProvider; _textBuffer = textBuffer; _options = (options == null) ? new CompletionOptions() : options.Clone(); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; object eventHookupValue; if (quickInfoContent.Count != 0 || session.Properties.TryGetProperty(QuickInfoUtilities.EventHookupKey, out eventHookupValue)) { // No quickinfo if it's the event hookup popup. return; } var position = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot); if (position.HasValue) { var textView = session.TextView; var args = new InvokeQuickInfoCommandArgs(textView, _subjectBuffer); Controller controller; if (_commandHandler.TryGetController(args, out controller)) { controller.InvokeQuickInfo(position.Value, trackMouse: true, augmentSession: session); } } }
/// <summary> /// Constructor for SpellDictionarySmartTagAction. /// </summary> /// <param name="span">Word to add to dictionary.</param> /// <param name="dictionary">The dictionary (used to ignore the word).</param> /// <param name="displayText">Text to show in the context menu for this action.</param> public SpellDictionarySmartTagAction(ITrackingSpan span, IYandexDictionary dictionary, string displayText, Lang lang) { _span = span; _dictionary = dictionary; _lang = lang; DisplayText = displayText; }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; var semanticModelResult = SemanticModelService.SemanticModelResult; if (semanticModelResult == null) { return; } // Map the trigger point down to our buffer. SnapshotPoint? subjectTriggerPoint = session.GetTriggerPoint(semanticModelResult.Snapshot); if (!subjectTriggerPoint.HasValue) { return; } var triggerSymbol = semanticModelResult.CompilationUnit.Symbols.FindAtPosition(subjectTriggerPoint.Value.Position); if (triggerSymbol == null) { return; } foreach(var content in SymbolQuickInfoBuilder.Build(triggerSymbol, SyntaxQuickinfoBuilderService)) { qiContent.Add(content); } var location = triggerSymbol.Location; applicableToSpan = semanticModelResult.Snapshot.CreateTrackingSpan( location.Start, location.Length, SpanTrackingMode.EdgeExclusive); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (session == null || qiContent == null || qiContent.Count > 0) return; // Map the trigger point down to our buffer. SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) return; var doc = JSONEditorDocument.FromTextBuffer(_buffer); JSONParseItem item = doc.JSONDocument.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) return; JSONMember member = item.FindType<JSONMember>(); if (member == null || member.Name == null) return; IJSONSchema schema = _schemaResolver.DetermineSchemaForTextBuffer(_buffer); if (schema != null) { IJSONSchemaPropertyNameCompletionInfo info = GetInfo(schema, member); if (info != null && !string.IsNullOrEmpty(info.PropertyDocumentation)) { applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative); qiContent.Add(info.DisplayText + Environment.NewLine + info.PropertyDocumentation); } } }
public string GetInsertionText(CssTextSource textSource, ITrackingSpan typingSpan) { string text = DisplayText; bool needsQuote = text.IndexOf(' ') != -1; if (text == "Pick from file...") { return string.Empty; } if (needsQuote) { // Prefer to use single quotes, but if the inline style uses single quotes, then use double quotes. char quote = (textSource == CssTextSource.InlineStyleSingleQuote) ? '"' : '\''; if (typingSpan != null) { // If the user already typed a quote, then use it string typingText = typingSpan.GetText(typingSpan.TextBuffer.CurrentSnapshot); if (!string.IsNullOrEmpty(typingText) && (typingText[0] == '"' || typingText[0] == '\'')) { quote = typingText[0]; } } if (text != null && text.IndexOf(quote) == -1) { text = quote.ToString() + text + quote.ToString(); } } return text; }
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { FunctionColor function = (FunctionColor)item; if (!function.IsValid) yield break; ColorModel model = ColorParser.TryParseColor(function.Text, ColorParser.Options.AllowAlpha); if (model != null) { // Don't convert RGBA and HSLA to HEX or named color if (model.Alpha == 1) { if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null) { yield return new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Name); } yield return new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.RgbHex3); } if (model.Format == ColorFormat.Rgb) { yield return new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Hsl); } else if (model.Format == ColorFormat.Hsl) { yield return new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Rgb); } } }
public UpperCaseSuggestedAction(ITrackingSpan span) { _span = span; _snapshot = span.TextBuffer.CurrentSnapshot; _upper = span.GetText(_snapshot).ToUpper(); _display = string.Format("Convert '{0}' to upper case", span.GetText(_snapshot)); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot); if (triggerPoint == null) return; // find each span that looks like a token and look it up in the dictionary foreach (IMappingTagSpan<PkgDefTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint))) { if (curTag.Tag.type == PkgDefLanguageTokens.Token) { SnapshotSpan tagSpan = curTag.Span.GetSpans(_buffer).First(); if (PkgDefTokenTagger.ValidTokens.Keys.Contains(tagSpan.GetText())) { applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); string quickInfo = PkgDefTokenTagger.ValidTokens[tagSpan.GetText()]; System.Diagnostics.Debug.WriteLine(quickInfo); quickInfoContent.Add(quickInfo); } } } }
internal static void AugmentQuickInfoWorker(ExpressionAnalysis vars, System.Collections.Generic.IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = vars.Span; if (applicableToSpan == null || String.IsNullOrWhiteSpace(vars.Expression)) { return; } bool first = true; var result = new StringBuilder(); int count = 0; List <AnalysisValue> listVars = new List <AnalysisValue>(vars.Values); HashSet <string> descriptions = new HashSet <string>(); bool multiline = false; foreach (var v in listVars) { string description = null; if (listVars.Count == 1) { if (!String.IsNullOrWhiteSpace(v.Description)) { description = v.Description; } } else { if (!String.IsNullOrWhiteSpace(v.ShortDescription)) { description = v.ShortDescription; } } description = description.LimitLines(); if (description != null && descriptions.Add(description)) { if (first) { first = false; } else { if (result.Length == 0 || result[result.Length - 1] != '\n') { result.Append(", "); } else { multiline = true; } } result.Append(description); count++; } } string expr = vars.Expression; if (expr.Length > 4096) { expr = expr.Substring(0, 4093) + "..."; } if (multiline) { result.Insert(0, expr + ": " + Environment.NewLine); } else if (result.Length > 0) { result.Insert(0, expr + ": "); } else { result.Append(expr); result.Append(": "); result.Append("<unknown type>"); } quickInfoContent.Add(result.ToString()); }
void UpdateTooltip(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { // Provide the tooltip data from the data we stashed in our callback. quickInfoContent.Add(inProgressTooltipData); // TODO: For some reason, this doesn't seem to work properly; the tooltip flickers as the mouse moves (and fires off additional requests) :( applicableToSpan = inProgressApplicableToSpan; }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { UrlItem url = (UrlItem)item; if (!url.IsValid || url.UrlString == null || !url.UrlString.Text.Contains(";base64,")) { yield break; } CComment comment = url.NextSibling as CComment; if (comment != null && comment.CommentText != null) { string path = comment.CommentText.Text.Trim(); yield return(new UpdateEmbedSmartTagAction(itemTrackingSpan, path)); } else { RuleBlock rule = item.FindType <RuleBlock>(); Declaration dec = item.FindType <Declaration>(); if (rule == null || dec == null || dec.PropertyName == null) { yield break; } foreach (Declaration sibling in rule.Declarations.Where(d => d.PropertyName != null && d != dec)) { if (sibling.PropertyName.Text == "*" + dec.PropertyName.Text || sibling.PropertyName.Text == "_" + dec.PropertyName.Text) { var visitor = new CssItemCollector <UrlItem>(); sibling.Accept(visitor); UrlItem siblingUrl = visitor.Items.FirstOrDefault(); if (siblingUrl != null && siblingUrl.UrlString != null) { yield return(new UpdateEmbedSmartTagAction(itemTrackingSpan, siblingUrl.UrlString.Text)); break; } } } } }
async Task StartTooltipRequestAsync(IQuickInfoSession session, IList <object> quickInfoContent, ITrackingSpan applicableToSpan, SnapshotPoint?triggerPoint, string filePath) { // If this position didn't have a classification, then it's uninteresting, and won't have tooltips. if (applicableToSpan == null) { return; } // Set the position so we know what request is in process. inProgressPosition = triggerPoint.Value.Position; inProgressTooltipData = null; inProgressApplicableToSpan = null; // Put dummy content in tooltip while the request in in-flight. quickInfoContent.Add("Loading..."); // Fire off a request to the service to get the data. DartAnalysisService analysisService = await provider.DartAnalysisServiceFactory.GetAnalysisServiceAsync().ConfigureAwait(false); HoverInformation[] hovers = await analysisService.GetHover(filePath, triggerPoint.Value.Position); // Build the tooltip info if the response was valid. var tooltipData = BuildTooltip(hovers); if (!string.IsNullOrWhiteSpace(tooltipData)) { // Stash the data for the next call, and tell VS to reclaculate now that we have the good info. inProgressTooltipData = tooltipData; inProgressApplicableToSpan = buffer.CurrentSnapshot.CreateTrackingSpan(hovers[0].Offset, hovers[0].Length, SpanTrackingMode.EdgeInclusive); session.Recalculate(); } else { // Otherwise, no valid response, means no tooltip. session.Dismiss(); } }
public ActiveStatementTrackingSpan(ITrackingSpan trackingSpan, ActiveStatementFlags flags) { Span = trackingSpan; Flags = flags; }
public void AugmentQuickInfoSession(IQuickInfoSession session, System.Collections.Generic.IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { if (_curSession != null && !_curSession.IsDismissed) { _curSession.Dismiss(); _curSession = null; } _curSession = session; _curSession.Dismissed += CurSessionDismissed; var vars = _textBuffer.CurrentSnapshot.AnalyzeExpression( _provider._serviceProvider, session.CreateTrackingSpan(_textBuffer), false ); AugmentQuickInfoWorker(vars, quickInfoContent, out applicableToSpan); }
static bool IsAfterDot(ITextSnapshot snapshot, ITrackingSpan applicableToSpan) { var position = applicableToSpan.GetStartPoint(snapshot).Position; return(position > 0 && snapshot[position - 1] == '.'); }
public void PresentItems( ITrackingSpan triggerSpan, IList <CompletionItem> completionItems, CompletionItem selectedItem, CompletionItem suggestionModeItem, bool suggestionMode, bool isSoftSelected, ImmutableArray <CompletionItemFilter> completionItemFilters, string filterText) { AssertIsForeground(); // check if this update is still relevant if (_textView.IsClosed || _isDismissed) { return; } if (triggerSpan != null) { _completionSet.SetTrackingSpan(triggerSpan); } _ignoreSelectionStatusChangedEvent = true; try { _completionSet.SetCompletionItems( completionItems, selectedItem, suggestionModeItem, suggestionMode, isSoftSelected, completionItemFilters, filterText); } finally { _ignoreSelectionStatusChangedEvent = false; } if (_editorSessionOpt == null) { // We're tracking the caret. Don't have the editor do it. // Map the span instead of a point to avoid affinity problems. _editorSessionOpt = _completionBroker.CreateCompletionSession( _textView, triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative), trackCaret: false); if (_textView is IDebuggerTextView debugTextView && !debugTextView.IsImmediateWindow) { debugTextView.HACK_StartCompletionSession(_editorSessionOpt); } _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed(); // So here's the deal. We cannot create the editor session and give it the right // items (even though we know what they are). Instead, the session will call // back into the ICompletionSourceProvider (which is us) to get those values. It // will pass itself along with the calls back into ICompletionSourceProvider. // So, in order to make that connection work, we add properties to the session // so that we can call back into ourselves, get the items and add it to the // session. _editorSessionOpt.Properties.AddProperty(Key, this); _editorSessionOpt.Start(); } // Call so that the editor will refresh the completion text to embolden. _editorSessionOpt?.Match(); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (!EnsureTreeInitialized() || session == null || qiContent == null) { return; } SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) { return; } ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) { return; } UrlItem urlItem = item.FindType <UrlItem>(); if (urlItem == null || urlItem.UrlString == null || !urlItem.UrlString.IsValid) { return; } string url = GetFullUrl(urlItem.UrlString.Text.Trim('\'', '"'), _buffer); if (string.IsNullOrEmpty(url)) { return; } applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(point.Value.Position, 1, SpanTrackingMode.EdgeNegative); AddImageContent(qiContent, url); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { Selector sel = (Selector)item; if (sel == null || !sel.IsValid) { yield break; } var idPart = sel.SimpleSelectors.Skip(1).FirstOrDefault(s => s.Text.StartsWith("#")); if (idPart != null) { yield return(new OverQualifySelectorSmartTagAction(sel, itemTrackingSpan, idPart.Start - sel.Start)); } }
void CalculateChange(TextContentChangedEventArgs e) { #if DEBUG Util.LogTextChanges(e.Changes); #endif if (_fullReparse == true) { return; } if (e.Changes.Count != 1) { _fullReparse = true; return; } ITextChange textChange = e.Changes[0]; if (_editSpan == null) { _editSpan = _buffer.CurrentSnapshot.CreateTrackingSpan( textChange.NewPosition, textChange.NewEnd - textChange.NewPosition, SpanTrackingMode.EdgeInclusive); #if DEBUG Util.Log("Created new edit span (" + _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position + "," + _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position + ") ", _buffer.CurrentSnapshot.GetText( _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position, _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position - _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position)); #endif } else { int oldEditStartPosition = _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position; int oldEditEndPosition = _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position; // In many cases, new edit is auto-merged with old edit by tracking span. To be more' // specific, in all cases when new edit is adjacent to the old edit, it will be // auto-merged. We need to create a new tracking span only if the new edit was non-adjacent // to the old edit (i.e. a few characters before the old edit or a few characters after // the old edit). if (textChange.NewPosition < oldEditStartPosition || textChange.NewPosition > oldEditEndPosition) { int newEditStartPosition = Math.Min(textChange.NewPosition, oldEditStartPosition); int newEditEndPosition = Math.Max(textChange.NewEnd, oldEditEndPosition); _editSpan = _buffer.CurrentSnapshot.CreateTrackingSpan( newEditStartPosition, newEditEndPosition - newEditStartPosition, SpanTrackingMode.EdgeInclusive); } #if DEBUG Util.Log("Updated edit span (" + _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position + "," + _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position + ") ", _buffer.CurrentSnapshot.GetText( _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position, _editSpan.GetEndPoint(_buffer.CurrentSnapshot).Position - _editSpan.GetStartPoint(_buffer.CurrentSnapshot).Position)); #endif } }
public CustomCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable <Completion> completions, IEnumerable <Completion> completionBuilders) : base(moniker, displayName, applicableTo, completions, completionBuilders) { PrefixMatch = true; }