private void FormatByDaxEditor() { int lineCont = _source.GetLineCount(); for (int line = 0; line < lineCont; line++) { int lineEnd = 0; TokenInfo[] lineInfos = _source.GetColorizer().GetLineInfo(_source.GetTextLines(), line, _colorState); if (lineInfos != null) { for (int i = 0; i < lineInfos.Length; i++) { // Store it for future usage TokenInfo tokenInfo = lineInfos[i]; var te = new TokenEdit() { TokenInfo = tokenInfo }; te.TextSpan = new TextSpan() { iStartLine = line, iStartIndex = tokenInfo.StartIndex, iEndLine = line, iEndIndex = tokenInfo.EndIndex + 1 }; lineEnd = tokenInfo.EndIndex + 1; te.OriginalText = _source.GetText(te.TextSpan); if (te.TokenInfo.Token == (int)Tokens.LEX_ERROR) { te = ReplaceInvalidChars(te); } _tokenEdits.AddLast(te); } } // Insert token for EOL var tokenInfoEOL = new TokenInfo() { Type = TokenType.WhiteSpace }; var teEOL = new TokenEdit() { TokenInfo = tokenInfoEOL }; teEOL.TextSpan = new TextSpan() { iStartLine = line, iStartIndex = lineEnd, iEndLine = line + 1, iEndIndex = 0 }; teEOL.OriginalText = Environment.NewLine; _tokenEdits.AddLast(teEOL); } NormilizeWhitespaces(); InsertEol(); CheckHeadAndTail(); ApplyEdits(); }
// 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")); } }