private void FormatByDaxFormatter(DaxFormatterCom.FormattingCulture formattingCulture)
        {
            string originalText = _source.GetText(_formattingSpan);

            if (!string.IsNullOrEmpty(originalText))
            {
                try
                {
                    var formattedText = DaxFormatterCom.Format(originalText, formattingCulture);
                    _editManager.Add(new EditSpan(_formattingSpan, formattedText));
                }
                catch (Exception e)
                {
                    DaxEditorPackage.WriteToGeneral(e.Message);
                    System.Windows.MessageBox.Show(e.Message, "Exception from daxformatter.com", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                }
            }
        }
Esempio n. 2
0
        // Help for functions and keywords.  Initiated by pressing F1.
        public override void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context)
        {
            string searchingKeyword = null;
            // Search keyword as the function that presented where cursor stays or just before it
            Source source = (Source)this.GetSource(buffer);

            Debug.Assert(ptsSelection.Length > 0);
            int line        = ptsSelection[0].iStartLine;
            int endPosition = ptsSelection[0].iEndIndex;
            var colorState  = new DaxEditor.DaxFormatter.DummyColorState();

            TokenInfo[] lineInfos = source.GetColorizer().GetLineInfo(buffer, line, colorState);
            foreach (var tokenInfo in lineInfos)
            {
                if (!(tokenInfo.Type == TokenType.Identifier || tokenInfo.Type == TokenType.Keyword))
                {
                    continue;
                }
                var span = new TextSpan();
                span.iStartLine  = line;
                span.iEndLine    = line;
                span.iStartIndex = tokenInfo.StartIndex;
                span.iEndIndex   = tokenInfo.EndIndex + 1;

                searchingKeyword = source.GetText(span);

                if (span.iEndIndex >= endPosition)
                {
                    break;
                }
            }

            if (!string.IsNullOrEmpty(searchingKeyword))
            {
                ErrorHandler.ThrowOnFailure(context.RemoveAttribute(null, null));
                ErrorHandler.ThrowOnFailure(context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup, "keyword", "SQL11.AS.DAXREF." + searchingKeyword + ".F1"));
            }
        }