internal void AddVarInfo(List <Inline> list, IXVariable var) { Run temp; var name = var.Name; var hasValue = !string.IsNullOrEmpty(var.Value); if (var.Kind == Kind.DbField) { if (hasValue) { name = var.Value + "->" + name; } } temp = new Run(name + " "); temp.Foreground = txtBrush; list.Add(temp); if (hasValue && var.Kind != Kind.DbField) // default value { temp = new Run(" := " + var.Value + " "); temp.Foreground = txtBrush; list.Add(temp); } temp = new Run(XSettings.FormatKeyword(var.ParamTypeDesc) + " "); temp.Foreground = this.kwBrush; list.Add(temp); temp = new Run(var.TypeName); temp.Foreground = this.txtBrush; list.Add(temp); if (var.IsArray) { temp = new Run("[] "); temp.Foreground = this.txtBrush; list.Add(temp); } }
int IVsLanguageDebugInfo.GetProximityExpressions(IVsTextBuffer pBuffer, int iLine, int iCol, int cLines, out IVsEnumBSTR ppEnum) { ppEnum = null; var file = getFile(pBuffer); var list = new List <String>(); XElement member; // We use our orignal syntax here (so SELF and ":"). The expression compiler // in the debugger takes care of translating SELF to this and ':' to '.' if (file != null) { member = file.FindMemberAtRow(iLine); switch (member.Kind) { case Kind.Method: case Kind.Access: case Kind.Assign: case Kind.Property: case Kind.Event: case Kind.Field: case Kind.Constructor: case Kind.Destructor: case Kind.Operator: if (!member.Modifiers.HasFlag(Modifiers.Static)) { list.Add(XSettings.FormatKeyword("SELF")); } break; } var buffer = _editorAdaptersFactoryService.GetDataBuffer(pBuffer); Dictionary <string, XVariable> locals = null; if (member != null) { if (member is XMemberDefinition) { locals = new Dictionary <string, XVariable>(StringComparer.OrdinalIgnoreCase); var tm = member as XMemberDefinition; var vars = tm.GetLocals(buffer.CurrentSnapshot, iLine, file.Project.ParseOptions.Dialect); foreach (var v in vars) { locals.Add(v.Name, (XVariable)v); } foreach (var p in tm.Parameters) { locals.Add(p.Name, (XVariable)p); } } addtokens(buffer, iLine, list, file, locals); } } ppEnum = new VsEnumBSTR(list); return(VSConstants.S_OK); }
int IVsLanguageDebugInfo.GetProximityExpressions(IVsTextBuffer pBuffer, int iLine, int iCol, int cLines, out IVsEnumBSTR ppEnum) { ppEnum = null; var file = getFile(pBuffer); var list = new List <String>(); XSourceEntity member; // We use our original syntax here (so SELF and ":"). The expression compiler // in the debugger takes care of translating SELF to this and ':' to '.' if (file != null) { member = file.FindMemberAtRow(iLine); if (member.Kind.IsClassMember(file.Project.ParseOptions.Dialect)) { if (!member.Modifiers.HasFlag(Modifiers.Static)) { list.Add(XSettings.FormatKeyword("SELF")); } } var buffer = _editorAdaptersFactoryService.GetDataBuffer(pBuffer); Dictionary <string, IXVariableSymbol> locals = null; if (member != null) { if (member is XSourceMemberSymbol tm) { locals = new Dictionary <string, IXVariableSymbol>(StringComparer.OrdinalIgnoreCase); var location = new XSharpSearchLocation(tm.File, tm, buffer.CurrentSnapshot, iLine); var vars = tm.GetLocals(location); foreach (var v in vars) { if (!locals.ContainsKey(v.Name)) { locals.Add(v.Name, v); } } foreach (var p in tm.Parameters) { if (!locals.ContainsKey(p.Name)) { locals.Add(p.Name, p); } } } addtokens(buffer, iLine, list, file, locals); } } ppEnum = new VsEnumBSTR(list); return(VSConstants.S_OK); }
private void InitDescription(XSourceEntity member) //, _VSOBJDESCOPTIONS flags, IVsObjectBrowserDescription3 description) { description = new List <Tuple <string, VSOBDESCRIPTIONSECTION> >(); string descText; if (member != null) { string modifier = ""; string access = ""; if ((member is XSourceTypeSymbol) && (member.Kind != Kind.Namespace)) { modifier = member.Modifiers.ToDisplayString(); access = member.Visibility.ToDisplayString(); } else if ((member is XSourceMemberSymbol) && ((member.Kind != Kind.Function) && (member.Kind != Kind.Procedure))) { modifier = member.Modifiers.ToDisplayString(); access = member.Visibility.ToDisplayString(); } // if (!string.IsNullOrEmpty(modifier)) { description.Add(Item(modifier + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE)); } // if (!string.IsNullOrEmpty(access)) { description.Add(Item(access + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE)); } // if (member.Kind != Kind.Field) { VSOBDESCRIPTIONSECTION descName = VSOBDESCRIPTIONSECTION.OBDS_MISC; descText = XSettings.FormatKeyword(member.Kind.DisplayName()) + " "; if (member.Kind == Kind.Constructor) { descName = VSOBDESCRIPTIONSECTION.OBDS_NAME; } description.Add(Item(descText, descName)); } if (member.Kind != Kind.Constructor) { descText = member.Name; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_NAME)); } // Parameters ? if (member.Kind.HasParameters()) { descText = "("; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); XSourceMemberSymbol realmember; XSourceTypeSymbol type = member as XSourceTypeSymbol; if (member.Kind == Kind.Delegate && type?.XMembers.Count > 0) { realmember = type.XMembers[0]; } else { realmember = member as XSourceMemberSymbol; } if (realmember != null && realmember.HasParameters) { // int paramNum = 1; foreach (IXParameterSymbol param in realmember.Parameters) { descText = param.Name; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_PARAM)); descText = param.ParamTypeDesc; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); descText = param.TypeName; // description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); // Need a comma ? if (paramNum < realmember.ParameterCount) { paramNum++; descText = ","; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_COMMA)); } } } descText = ")"; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (member.Kind.HasReturnType()) { descText = XLiterals.AsKeyWord; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); descText = member.TypeName; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); } description.Add(Item(null, VSOBDESCRIPTIONSECTION.OBDS_ENDDECL)); } // if (member.File?.Project != null) { string summary = null, returns = null, remarks = null; List <string> pNames = new List <string>(); List <string> pDescriptions = new List <string>(); if (member is XSourceMemberSymbol symbol1) { summary = XSharpXMLDocMember.GetMemberSummary(symbol1, member.File?.Project, out returns, out remarks); XSharpXMLDocMember.GetMemberParameters(symbol1, member.File?.Project, pNames, pDescriptions); } else if (member is XSourceTypeSymbol symbol) { summary = XSharpXMLDocMember.GetTypeSummary(symbol, member.File?.Project, out returns, out remarks); } if (!string.IsNullOrEmpty(summary)) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(SUMMARY, VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(Item(summary, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (pNames.Count > 0) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(PARAMETERS, VSOBDESCRIPTIONSECTION.OBDS_NAME)); for (int i = 0; i < pNames.Count; i++) { description.Add(Item(NEWLINE + pNames[i], VSOBDESCRIPTIONSECTION.OBDS_PARAM)); description.Add(Item(" : ", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(pDescriptions[i], VSOBDESCRIPTIONSECTION.OBDS_MISC)); } } if (!string.IsNullOrEmpty(returns)) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(RETURNS, VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(Item(returns, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (!string.IsNullOrEmpty(remarks)) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(REMARKS, VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(Item(remarks, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } } }
static internal void addReturnType(this List <ClassifiedTextRun> content, string typeName) { content.addPair(" " + XSettings.FormatKeyword("AS "), typeName.GetXSharpTypeName()); }
private void initDescription(XEntityDefinition member) //, _VSOBJDESCOPTIONS flags, IVsObjectBrowserDescription3 description) { description = new List <Tuple <string, VSOBDESCRIPTIONSECTION> >(); // string descText = this.Name; // string namesp = ""; string className = ""; if (member != null) { if (member.Parent != null) { if (member.Parent is IXType) { namesp = ((IXType)member.Parent).Namespace; className = ((IXType)member.Parent).Name; } } // string modifier = ""; string access = ""; if ((member is XTypeDefinition) && (member.Kind != Kind.Namespace)) { modifier = member.Modifiers.ToDisplayString(); access = member.Visibility.ToDisplayString(); } else if ((member is XMemberDefinition) && ((member.Kind != Kind.Function) && (member.Kind != Kind.Procedure))) { modifier = member.Modifiers.ToDisplayString(); access = member.Visibility.ToDisplayString(); } // if (!String.IsNullOrEmpty(modifier)) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(modifier + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE)); } // if (!String.IsNullOrEmpty(access)) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(access + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE)); //description.AddDescriptionText3(access, VSOBDESCRIPTIONSECTION.OBDS_MISC, null); } // if (member.Kind != Kind.Field) { VSOBDESCRIPTIONSECTION descName = VSOBDESCRIPTIONSECTION.OBDS_MISC; descText = XSettings.FormatKeyword(member.Kind.DisplayName()) + " "; if (member.Kind == Kind.Constructor) { descName = VSOBDESCRIPTIONSECTION.OBDS_NAME; } description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, descName)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC, null); } if (member.Kind != Kind.Constructor) { descText = member.Name; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_NAME)); } //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_NAME, null); // Parameters ? if (member.Kind.HasParameters()) { descText = "("; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC, null); XMemberDefinition realmember; XTypeDefinition type = member as XTypeDefinition; if (member.Kind == Kind.Delegate && type?.XMembers.Count > 0) { realmember = type.XMembers[0]; } else { realmember = member as XMemberDefinition; } if (realmember != null && realmember.HasParameters) { // int paramNum = 1; foreach (XVariable param in realmember.Parameters) { descText = param.Name; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_PARAM)); descText = param.ParamTypeDesc; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_PARAM, null); descText = param.TypeName; // IVsNavInfo navInfo = buildNavInfo(member.File, param.TypeName); // description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo); // Need a comma ? if (paramNum < realmember.ParameterCount) { paramNum++; descText = ","; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_COMMA)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_COMMA, null); } } } descText = ")"; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC, null); } if (member.Kind.HasReturnType()) { descText = XLiterals.AsKeyWord; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC, null); descText = member.TypeName; description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE, null); } // //if (!((member.Kind == Kind.Function) || (member.Kind == Kind.Procedure) || (member.Kind == Kind.VODLL)) && // ((member.Parent is XTypeDefinition) && (member.Parent.Kind == Kind.Class))) //{ // descText = " CLASS "; // description.Add(new Tuple<string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); // //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC, null); // descText = className; // description.Add(new Tuple<string, VSOBDESCRIPTIONSECTION>(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); // //description.AddDescriptionText3(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE, null); //} // description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(null, VSOBDESCRIPTIONSECTION.OBDS_ENDDECL)); //description.AddDescriptionText3(null, VSOBDESCRIPTIONSECTION.OBDS_ENDDECL, null); } // if (member.File?.Project != null) { string summary = null, returns = null, remarks = null; List <string> pNames = new List <string>(); List <string> pDescriptions = new List <string>(); if (member is XMemberDefinition) { summary = XSharpXMLDocMember.GetMemberSummary((XMemberDefinition)member, member.File?.Project, out returns, out remarks); XSharpXMLDocMember.GetMemberParameters((XMemberDefinition)member, member.File?.Project, pNames, pDescriptions); } else if (member is XTypeDefinition) { summary = XSharpXMLDocMember.GetTypeSummary((XTypeDefinition)member, member.File?.Project, out returns, out remarks); } if (!String.IsNullOrEmpty(summary)) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\n", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\nSummary:\n", VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(summary, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (pNames.Count > 0) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\n", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\nParameters:", VSOBDESCRIPTIONSECTION.OBDS_NAME)); for (int i = 0; i < pNames.Count; i++) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\n" + pNames[i], VSOBDESCRIPTIONSECTION.OBDS_PARAM)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(" : ", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(pDescriptions[i], VSOBDESCRIPTIONSECTION.OBDS_MISC)); } } if (!String.IsNullOrEmpty(returns)) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\n", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\nReturn:\n", VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(returns, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (!String.IsNullOrEmpty(remarks)) { description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\n", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>("\nRemarks:\n", VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(new Tuple <string, VSOBDESCRIPTIONSECTION>(remarks, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } } }
void formatKeyword(Completion completion) { completion.InsertionText = XSettings.FormatKeyword(completion.InsertionText); }
internal static List <XSharpToken> GetTokenList(XSharpSearchLocation location, out CompletionState state, bool includeKeywords = false, bool underCursor = false) { location = AdjustStartLineNumber(location); var line = getLineFromBuffer(location); // state = CompletionState.General; if (line.Count == 0) { return(line); } // if the token appears after comma or paren then strip the tokens // now look forward and find the first token that is on or after the triggerpoint var result = new List <XSharpToken>(); var last = XSharpLexer.Eof; bool allowdot = location.Project?.ParseOptions?.AllowDotForInstanceMembers ?? false; var cursorPos = location.Position; var done = false; var list = new XSharpTokenList(line); while (!done && !list.Eoi()) { var token = list.ConsumeAndGet(); int openToken = 0; XSharpToken closeToken = null; bool isHit = token.StartIndex <= cursorPos && token.StopIndex >= cursorPos && underCursor; bool isNotLast = token.StopIndex < location.Position - 1; if (token.StartIndex > cursorPos) { // after the cursor we only include the open tokens // so we can see if the id under the cursor is a method, constructor etc switch (token.Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: case XSharpLexer.LBRKT: break; case XSharpLexer.LT: // if this is a generic type // then add the complete bool first = true; bool endoflist = false; while (!endoflist) { endoflist = true; if (list.La1 == XSharpLexer.ID || XSharpLexer.IsType(list.La1)) { if (list.La2 == XSharpLexer.GT || list.La2 == XSharpLexer.COMMA) { if (first) { result.Add(token); first = false; } result.Add(list.ConsumeAndGet()); // la1 result.Add(list.ConsumeAndGet()); // la2 endoflist = false; } } } continue; default: done = true; break; } if (done) { continue; } } switch (token.Type) { // after these tokens we "restart" the list case XSharpLexer.EOS: if (token.Position < cursorPos && token != line.Last()) { // an EOS inside a line before the cursor // so there are 2 or more statements on the same line // clear the first statement result.Clear(); state = CompletionState.General; } else { // Exit loop, ignore the rest of the statements done = true; } continue; case XSharpLexer.WS: case XSharpLexer.Eof: continue; case XSharpLexer.TO: case XSharpLexer.UPTO: case XSharpLexer.DOWNTO: case XSharpLexer.IN: if (!isHit) { result.Clear(); if (isNotLast) // there has to be a space after the token { state = CompletionState.General; } else { state = CompletionState.None; } } else { result.Add(token); } break; case XSharpLexer.LCURLY: state = CompletionState.Constructors; result.Add(token); break; case XSharpLexer.LPAREN: state = CompletionState.StaticMembers | CompletionState.InstanceMembers; result.Add(token); break; case XSharpLexer.LBRKT: state = CompletionState.Brackets; result.Add(token); break; case XSharpLexer.ID: case XSharpLexer.NAMEOF: case XSharpLexer.TYPEOF: case XSharpLexer.SIZEOF: result.Add(token); break; case XSharpLexer.RCURLY: case XSharpLexer.RPAREN: case XSharpLexer.RBRKT: bool add = true; if (result.Count > 0 && token == list.LastOrDefault) { var lasttoken = result.Last(); if (lasttoken.Type == XSharpLexer.COLON || lasttoken.Type == XSharpLexer.DOT) { // closing char after colon or dot add = false; done = true; } } if (add) { result.Add(token); // delete everything between parens, curly braces and brackets closing token before cursor pos if (token.Position < location.Position) { closeToken = token; if (token.Type == XSharpLexer.RCURLY) { openToken = XSharpLexer.LCURLY; } else if (token.Type == XSharpLexer.RPAREN) { openToken = XSharpLexer.LPAREN; } else if (token.Type == XSharpLexer.RBRKT) { openToken = XSharpLexer.LBRKT; } } } break; case XSharpLexer.STATIC: // These tokens are all before a namespace of a (namespace dot) type if (isNotLast) // there has to be a space after the token { state = CompletionState.General; } else { state = CompletionState.None; } break; case XSharpLexer.USING: if (isNotLast) // there has to be a space after the token { if (list.Expect(XSharpLexer.STATIC)) { state = CompletionState.Namespaces | CompletionState.Types; result.Clear(); } else if (list.La1 == XSharpLexer.ID) { state = CompletionState.Namespaces; result.Clear(); } } break; case XSharpLexer.MEMBER: if (isNotLast) // there has to be a space after the token { state = CompletionState.StaticMembers; } else { state = CompletionState.None; } break; case XSharpLexer.AS: case XSharpLexer.IS: case XSharpLexer.REF: case XSharpLexer.INHERIT: if (!isHit) { result.Clear(); } else { result.Add(token); } if (isNotLast) // there has to be a space after the token { state = CompletionState.Namespaces | CompletionState.Types; } else { state = CompletionState.None; } break; case XSharpLexer.IMPLEMENTS: result.Clear(); if (isNotLast) { state = CompletionState.Namespaces | CompletionState.Interfaces; } else { state = CompletionState.None; } break; case XSharpLexer.COLON: state = CompletionState.InstanceMembers; result.Add(token); break; case XSharpLexer.DOT: if (!state.HasFlag(CompletionState.Namespaces)) { state = CompletionState.Namespaces | CompletionState.Types | CompletionState.StaticMembers; if (allowdot) { state |= CompletionState.InstanceMembers; } } result.Add(token); break; case XSharpLexer.QMARK: if (result.Count != 0) // when at start of line then do not add. Otherwise it might be a Nullable type or conditional access expression { result.Add(token); } break; case XSharpLexer.QQMARK: if (result.Count != 0) // when at start of line then do not add. Otherwise it might be a binary expression { result.Add(token); } break; case XSharpLexer.BACKSLASH: case XSharpLexer.BACKBACKSLASH: // this should only be seen at start of line // clear the list to be sure result.Clear(); break; case XSharpLexer.NAMESPACE: state = CompletionState.Namespaces; break; case XSharpLexer.COMMA: case XSharpLexer.ASSIGN_OP: case XSharpLexer.COLONCOLON: case XSharpLexer.SELF: case XSharpLexer.SUPER: state = CompletionState.General; result.Add(token); break; default: state = CompletionState.General; if (XSharpLexer.IsOperator(token.Type)) { result.Add(token); } else if (XSharpLexer.IsType(token.Type)) { result.Add(token); } else if (XSharpLexer.IsConstant(token.Type)) { result.Add(token); } else if (XSharpLexer.IsKeyword(token.Type) && includeKeywords) // For code completion we want to include keywords { token.Text = XSettings.FormatKeyword(token.Text); result.Add(token); } break; } last = token.Type; // remove everything between parens, curly braces or brackets when the closing token is before the cursor if (openToken != 0 && closeToken != null) { var iLast = result.Count - 1; int count = 0; while (iLast >= 0 && result[iLast] != closeToken) { iLast--; } int closeType = closeToken.Type; while (iLast >= 0) { var type = result[iLast].Type; if (type == closeType) { count += 1; } else if (type == openToken) { count -= 1; if (count == 0) { if (iLast < result.Count - 1) { result.RemoveRange(iLast + 1, result.Count - iLast - 2); } break; } } iLast -= 1; } } } // when the list ends with a comma, drop the ending comma. Why ? if (result.Count > 0) { var end = result.Last(); if (end.Type == XSharpLexer.COMMA) { result.RemoveAt(result.Count - 1); } } return(result); }
private void formatToken(ITextEdit editSession, int offSet, IToken token) { if (token.Channel == XSharpLexer.Hidden || token.Channel == XSharpLexer.PREPROCESSORCHANNEL || token.Type == XSharpLexer.TEXT_STRING_CONST) { return; } bool syncKeyword = false; // Some exceptions are (pseudo) functions. These should not be formatted switch (token.Type) { case XSharpLexer.UDC_KEYWORD: syncKeyword = XSettings.UDCKeywordCase; break; case XSharpLexer.NAMEOF: case XSharpLexer.SIZEOF: case XSharpLexer.TYPEOF: // these are keywords but should be excluded I think syncKeyword = false; break; case XSharpLexer.TRUE_CONST: case XSharpLexer.FALSE_CONST: case XSharpLexer.MACRO: case XSharpLexer.LOGIC_AND: case XSharpLexer.LOGIC_OR: case XSharpLexer.LOGIC_NOT: case XSharpLexer.LOGIC_XOR: case XSharpLexer.VO_AND: case XSharpLexer.VO_OR: case XSharpLexer.VO_NOT: case XSharpLexer.VO_XOR: syncKeyword = true; break; default: if (token.Type >= XSharpLexer.FIRST_NULL && token.Type <= XSharpLexer.LAST_NULL) { syncKeyword = true; } else if (XSharpLexer.IsKeyword(token.Type)) { syncKeyword = token.Text[0] != '#'; } break; } if (syncKeyword) { var keyword = token.Text; var transform = XSettings.FormatKeyword(keyword, _settings.KeywordCase); if (String.Compare(transform, keyword) != 0) { int startpos = offSet + token.StartIndex; editSession.Replace(startpos, transform.Length, transform); } } if (token.Type == XSharpLexer.ID && XSettings.IdentifierCase) { var identifier = token.CleanText(); var lineNumber = getCurrentLine(); var currentMember = _textView.FindMember(); // if (currentMember == null) { return; } IXVariableSymbol element = null; // Search in Parameters if (currentMember.Parameters != null) { element = currentMember.Parameters.Where(x => XSharpTokenTools.StringEquals(x.Name, identifier)).FirstOrDefault(); } if (element == null) { // then Locals var location = new XSharpSearchLocation(currentMember.File, currentMember, null, lineNumber); var locals = currentMember.GetLocals(location); if (locals != null) { element = locals.Where(x => XSharpTokenTools.StringEquals(x.Name, identifier)).FirstOrDefault(); } if (element == null) { if (currentMember.Parent is IXTypeSymbol type) { var field = XSharpLookup.SearchPropertyOrField(location, type, identifier, Modifiers.Private).FirstOrDefault(); } } } } }