private static XSharpSearchLocation AdjustStartLineNumber(XSharpSearchLocation location) { ClassifyBuffer(location); var line = location.LineNumber; var doc = location.GetDocument(); var lineFlags = doc.LineState; while (line >= 0 && lineFlags.GetFlags(line).HasFlag(LineFlags.Continued)) { line--; } return(location.With(line, location.Position)); }
internal static List <XSharpToken> GetTokenListBeforeCaret(XSharpSearchLocation location, out CompletionState state) { var tokens = GetTokenList(location, out state, false); var result = new List <XSharpToken>(); foreach (var token in tokens) { if (token.Position <= location.Position) { result.Add(token); } } return(result); }
internal void AddTypeNames(XCompletionList compList, XSharpSearchLocation location, string startWith, bool onlyInterfaces = false, bool afterDot = false) { if (startWith == null) { return; } // PE Types AddPETypeNames(compList, location, startWith, onlyInterfaces, afterDot); // Find Source Types AddSourceTypeNames(compList, location, startWith, onlyInterfaces, afterDot); // And our own Types AddXSharpTypeNames(compList, location, startWith); }
internal void FillExtensions(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol type, string startWith) { WriteOutputMessage($"FillExtensions for type {type?.FullName}"); if (type != null) { var extensions = _file.Project.GetExtensions(type.FullName); IEnumerable <IXMemberSymbol> selection = extensions; if (!string.IsNullOrEmpty(startWith)) { selection = extensions.Where(x => nameStartsWith(x.Name, startWith)); } if (selection.Count() > 0) { FillMembers(location, compList, null, selection, Modifiers.Public, true); } foreach (var ifname in type.Interfaces) { var lifname = ifname; var lookupproject = _file.Project; if (type is XSourceTypeSymbol sourceType) { var typedef = sourceType; var origfile = XSolution.FindFullPath(typedef.File.FullPath); lookupproject = origfile.Project; var reftype = SystemTypeController.FindType(lifname, typedef.FileUsings, lookupproject.AssemblyReferences); if (reftype != null) { lifname = reftype.FullName; } } extensions = lookupproject.GetExtensions(lifname); selection = extensions; if (!string.IsNullOrEmpty(startWith)) { selection = extensions.Where(x => nameStartsWith(x.Name, startWith)); } if (selection.Count() > 0) { FillMembers(location, compList, null, selection, Modifiers.Public, true); } } } //WriteOutputMessage($"FillExtensions complete for type {sType.FullName}"); }
internal static XSharpSearchLocation FindLocation(this ITextBuffer buffer, SnapshotPoint point) { if (buffer == null) { return(null); } int line = point.GetContainingLine().LineNumber; var file = buffer.GetFile(); var snapshot = buffer.CurrentSnapshot; var member = XSharpLookup.FindMember(line, file); var ns = XSharpTokenTools.FindNamespace(point, file); string currentNS = ""; if (ns != null) { currentNS = ns.FullName; } var location = new XSharpSearchLocation(file, member, snapshot, line, point, currentNS); return(location); }
internal void AddPETypeNames(XCompletionList compList, XSharpSearchLocation location, string startWith, bool onlyInterfaces = false, bool afterDot = false) { IList <XPETypeSymbol> types; if (afterDot) { types = location.Project.GetAssemblyTypesInNamespace(startWith, location.Usings.ToArray()); } else { // where is this called ? types = new List <XPETypeSymbol>(); } foreach (var type in types) { if (onlyInterfaces && type.Kind != Kind.Interface) { continue; } if (isHiddenTypeSymbol(type, out var displayName)) { continue; } if (!afterDot && !displayName.StartsWith(startWith)) { continue; } var typeAnalysis = new XTypeAnalysis(type); ImageSource icon = _glyphService.GetGlyph(typeAnalysis.GlyphGroup, typeAnalysis.GlyphItem); if (!compList.Add(new XSCompletion(displayName, displayName, typeAnalysis.Prototype, icon, null, Kind.Class, ""))) { break; } } }
internal void AddXSharpTypeNames(XCompletionList compList, XSharpSearchLocation location, string startWith, IList <string> usings = null, string NameToExclude = "") { if (usings == null) { usings = location.Usings; } var list = location.Project.GetTypes(startWith, usings); foreach (var typeInfo in list) { if (String.Compare(typeInfo.FullName, NameToExclude) == 0) { continue; } // Then remove it ImageSource icon = _glyphService.GetGlyph(typeInfo.getGlyphGroup(), typeInfo.getGlyphItem()); if (!compList.Add(new XSCompletion(typeInfo.Name, typeInfo.Name, typeInfo.FullName, icon, null, typeInfo.Kind, ""))) { break; } } }
/// <summary> /// Add Members for our Types to the completionlist /// </summary> /// <param name="compList"></param> /// <param name="xType"></param> /// <param name="minVisibility"></param> internal void FillMembers(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol xType, Modifiers minVisibility, bool staticOnly, string startWith) { FillMembers(location, compList, xType, xType.GetMembers(startWith), minVisibility, staticOnly); }
/// <summary> /// Add members to the completionlist /// </summary> /// <param name="compList"></param> /// <param name="members"></param> /// <param name="minVisibility"></param> /// <param name="staticOnly"></param> internal void FillMembers(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol type, IEnumerable <IXMemberSymbol> members, Modifiers minVisibility, bool staticOnly) { if (members.Count() == 0) { return; } WriteOutputMessage($"FillMembers {type?.FullName}: {members.Count()} members"); foreach (var elt in members) { bool add = true; if (IsHiddenMemberName(elt.Name)) { continue; } switch (elt.Kind) { case Kind.EnumMember: add = true; break; case Kind.Constructor: case Kind.Destructor: case Kind.Operator: add = false; break; default: if (!elt.Kind.IsGlobalTypeMember() && elt.IsStatic != staticOnly) { add = false; } if (add) { add = elt.IsVisible(minVisibility); } if (staticOnly && elt.IsStatic && type != null) { if (elt.Parent.FullName == "System.Object" && type.FullName != "System.Object") { add = false; } } break; } if (type != null && type.Kind == Kind.Enum && elt.DeclaringType != null && elt.DeclaringType != type.FullName && elt.Name != "HasFlag") { add = false; } if (!add) { continue; } // ImageSource icon = _glyphService.GetGlyph(elt.getGlyphGroup(), elt.getGlyphItem()); string toAdd = ""; if (elt.Kind.HasParameters() && elt.Kind != Kind.Constructor && !elt.Kind.IsProperty() && elt.Kind != Kind.Event) { toAdd = "("; } if (!compList.Add(new XSCompletion(elt.Name, elt.Name + toAdd, elt.Prototype, icon, null, elt.Kind, elt.Value))) { break; } } }
internal void BuildCompletionListMembers(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol type, Modifiers minVisibility, bool staticOnly, string startWith) { if (type == null) { return; } // FillMembers(location, compList, type, minVisibility, staticOnly, startWith); if (type is XSourceTypeSymbol sourceType) { sourceType.ForceComplete(); var baseType = sourceType.BaseTypeName; if (string.IsNullOrWhiteSpace(baseType)) { if (type.Kind == Kind.Enum) { baseType = "System.Enum"; } else if (type.Kind == Kind.Delegate) { baseType = "System.Delegate"; } else { baseType = "System.Object"; } } var parentType = sourceType.File.FindType(baseType, sourceType.Namespace); if (parentType != null && parentType.FullName == sourceType.FullName) { ; // recursion ! WriteOutputMessage("*** Recursion detected *** " + sourceType.FullName + " inherits from " + parentType.FullName); } else if (baseType == "System.Enum" && staticOnly) { ; // do nothing } else { BuildCompletionListMembers(location, compList, parentType, Modifiers.Protected, staticOnly, startWith); } foreach (var ifname in sourceType.Interfaces) { var iftype = sourceType.File.FindType(ifname, sourceType.Namespace); if (iftype != null) { BuildCompletionListMembers(location, compList, iftype, Modifiers.Public, staticOnly, startWith); } } } if (type is XPETypeSymbol && type.Children.Count > 0) { AddTypeNames(compList, location, type.FullName, false); } if (type is XSourceTypeSymbol) { var usings = location.Usings.ToList(); usings.Add(type.FullName); AddXSharpTypeNames(compList, location, type.FullName, usings, type.FullName); } if (!staticOnly) { FillExtensions(location, compList, type, startWith); } }
internal void AddNamespaces(XCompletionList compList, XSharpSearchLocation location, string startWith) { // We are looking for NameSpaces, in References if (startWith == null) { return; } var namespaces = location.Project.AllNamespaces; // Calculate the length we must remove int startLen = 0; int dotPos = startWith.LastIndexOf('.'); if (dotPos != -1) { startLen = dotPos + 1; } ImageSource icon = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic); ImageSource iconClass = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupClass, StandardGlyphItem.GlyphItemPublic); foreach (string nameSpace in namespaces.Where(ns => nameStartsWith(ns, startWith))) { string displayName = nameSpace; // remove the start if (startLen > 0) { displayName = displayName.Substring(startLen); } // Do we have another part dotPos = displayName.IndexOf('.'); // Then remove it if (dotPos > 0) { displayName = displayName.Substring(0, dotPos); } // XSCompletion item; if (!compList.ContainsKey(displayName)) { if (displayName.IndexOf("<") > 0) { item = new XSCompletion(displayName, displayName, nameSpace, iconClass, null, Kind.Class, ""); } else { item = new XSCompletion(displayName, displayName, "Namespace " + nameSpace, icon, null, Kind.Namespace, ""); } if (!compList.Add(item)) { break; } } } // // And our own Namespaces AddXSharpNamespaces(compList, location, startWith, icon); // We should also add the external NameSpaces var prjs = location.Project.ReferencedProjects; foreach (var prj in prjs) { AddXSharpNamespaces(compList, location, startWith, icon); } }
//internal void AddGenericCompletion(XCompletionList compList, XSharpSearchLocation location, string startWith ) //{ // if (XSettings.CompleteLocals && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericLocals(compList, location, startWith); // } // if (XSettings.CompleteSelf && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericSelfMembers(compList, location, startWith); // } // if (XSettings.CompleteParent && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericInheritedMembers(compList, location, startWith); // } // if (XSettings.CompleteNamespaces && compList.Count < XSettings.MaxCompletionEntries) // { // AddNamespaces(compList, location, startWith); // } // if (XSettings.CompleteTypes && compList.Count < XSettings.MaxCompletionEntries) // { // AddTypeNames(compList, location, startWith); // } // if (XSettings.CompleteFunctions && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericFunctions(compList, location, startWith, true); // } // if (XSettings.CompleteFunctionsP && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericFunctions(compList, location, startWith, false); // } // if (XSettings.CompleteFunctionsA && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericFunctionsAssemblies(compList, location, startWith, false); // } // if (XSettings.CompleteGlobals && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericGlobals(compList, location, startWith, true); // } // if (XSettings.CompleteGlobalsP && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericGlobals(compList, location, startWith, false); // } // if (XSettings.CompleteGlobalsA && compList.Count < XSettings.MaxCompletionEntries) // { // AddGenericGlobalsAssemblies(compList, location, startWith, false); // } // if (XSettings.CompleteSnippets) // { // // todo: Add Snippets // } // if (XSettings.CompleteKeywords) // { // AddXSharpKeywords(compList, startWith); // } //} internal void AddGenericGlobals(XCompletionList compList, XSharpSearchLocation location, string startWith, bool onlyProject) { var found = location.Project.FindGlobalMembersLike(startWith, onlyProject); FillMembers(location, compList, null, found, Modifiers.Public, false); }
internal static IList <XSharpToken> GetTokensUnderCursor(XSharpSearchLocation location, out CompletionState state) { var tokens = GetTokenList(location, out state, true, true).Where((t) => t.Channel == XSharpLexer.DefaultTokenChannel).ToList(); // Find "current" token if (tokens.Count > 0) { var tokenUnderCursor = tokens.Count - 1; for (int i = tokens.Count - 1; i >= 0; i--) { var token = tokens[i]; if (token.StartIndex <= location.Position && token.StopIndex >= location.Position) { tokenUnderCursor = i; break; } } var selectedToken = tokens[tokenUnderCursor]; var nextToken = tokenUnderCursor < tokens.Count - 1 ? tokens[tokenUnderCursor + 1] : null; bool done = false; switch (selectedToken.Type) { case XSharpLexer.NAMEOF: case XSharpLexer.TYPEOF: case XSharpLexer.SIZEOF: case XSharpLexer.SELF: case XSharpLexer.SUPER: if (nextToken != null && nextToken.Type == XSharpLexer.LPAREN) { return(tokens); } break; default: if (XSharpLexer.IsKeyword(selectedToken.Type)) { tokens.Clear(); tokens.Add(selectedToken); return(tokens); } break; } // When we are not on a Keyword then we need to walk back in the tokenlist to see // if we can evaluate the expression // This could be: // System.String.Compare() // static method cal or method call // SomeVar:MethodCall() // method call // Left(...) // function call // SomeId // local, global etc // SomeType.Id // Static property or normal property // SomeVar:Id // Instance field or property // If the token list contains with a RCURLY, RBRKT or RPAREN // Then strip everything until the matching LCURLY, LBRKT or LPAREN is found var list = new XSharpTokenList(tokens); tokens = new List <XSharpToken>(); while (!list.Eoi()) { var token = list.ConsumeAndGet(); switch (token.Type) { case XSharpLexer.LCURLY: tokens.Add(token); if (list.Contains(XSharpLexer.RCURLY)) { // this may return false when the RCURLY belongs to another LCURLY if (list.ConsumeUntilEndToken(XSharpLexer.RCURLY, out var endToken)) { tokens.Add(endToken); } } break; case XSharpLexer.LPAREN: tokens.Add(token); if (list.Contains(XSharpLexer.RPAREN)) { // this may return false when the RPAREN belongs to another LPAREN if (list.ConsumeUntilEndToken(XSharpLexer.RPAREN, out var endToken)) { tokens.Add(endToken); } } break; case XSharpLexer.LBRKT: tokens.Add(token); if (list.Contains(XSharpLexer.RBRKT)) { // this may return false when the RBRKT belongs to another LBRKT if (list.ConsumeUntilEndToken(XSharpLexer.RBRKT, out var endToken)) { tokens.Add(endToken); } } break; case XSharpLexer.DOT: case XSharpLexer.COLON: case XSharpLexer.SELF: case XSharpLexer.SUPER: tokens.Add(token); break; default: tokens.Add(token); if (XSharpLexer.IsOperator(token.Type)) { done = true; } if (token.Type == XSharpLexer.VAR) { done = true; } else if (XSharpLexer.IsKeyword(token.Type) && !XSharpLexer.IsPositionalKeyword(token.Type) ) { done = true; } break; } } // now result has the list of tokens starting with the cursor // we only keep: // ID, DOT, COLON, LPAREN, LBRKT, RBRKT // when we detect another token we truncate the list there if (tokens.Count > 0) { var lastType = tokens[0].Type; for (int i = tokenUnderCursor + 1; i < tokens.Count && !done; i++) { var token = tokens[i]; switch (token.Type) { case XSharpLexer.ID: case XSharpLexer.DOT: case XSharpLexer.COLON: case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: case XSharpLexer.LBRKT: lastType = tokens[i].Type; break; case XSharpLexer.LT: int gtPos = findTokenInList(tokens, i + 1, XSharpLexer.GT); if (lastType == XSharpLexer.ID && gtPos > 0) { gtPos += 1; tokens.RemoveRange(gtPos, tokens.Count - gtPos); done = true; break; } else { goto default; } default: tokens.RemoveRange(i, tokens.Count - i); done = true; break; } } } } // check for extra lparen, lcurly at the end int count = tokens.Count; if (count > 2 && count < tokens.Count - 2) { if (tokens[count - 2].Type == XSharpLexer.LPAREN) { switch (tokens[count - 1].Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: tokens.RemoveAt(count - 1); break; } } } return(tokens); }
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); }
/// <summary> /// Retrieve the locals for a particular member /// </summary> /// <param name="member"></param> /// <param name="snapshot"></param> /// <param name="iCurrentLine"></param> /// <returns></returns> internal static IList <XSourceVariableSymbol> GetLocals(this XSourceMemberSymbol member, XSharpSearchLocation location) { var iCurrentLine = Math.Min(location.Snapshot.LineCount - 1, location.LineNumber); // create a walker with just the contents of the current member // use a new file object so we will not destroy the types in the existing object var walker = new SourceWalker(new XFile(member.File.FullPath, member.File.Project), false); var start = member.Interval.Start; var end = member.Interval.Width; if (start + end > location.Snapshot.Length) { end = location.Snapshot.Length - start; } var memberSource = location.Snapshot.GetText(start, end); var locals = walker.ParseLocals(memberSource, member); // Add the normal locals for class members foreach (var local in locals) { // assign the current member so we will have the proper Parent as well local.Parent = member; local.File = member.File; } if (member.Kind.IsClassMember(location.Dialect) && !member.Modifiers.HasFlag(Modifiers.Static)) { var XVar = new XSourceVariableSymbol(member, "SELF", member.Range, member.Interval, member.ParentName); XVar.File = walker.File; locals.Add(XVar); if (!String.IsNullOrEmpty(member.ParentType.BaseTypeName)) { XVar = new XSourceVariableSymbol(member, "SUPER", member.Range, member.Interval, member.ParentType.BaseTypeName); XVar.File = walker.File; locals.Add(XVar); } } return(locals); }
internal void AddGenericFunctionsAssemblies(XCompletionList compList, XSharpSearchLocation location, string startWith, bool onlyProject) { var found = location.Project.FindFunctionsInAssemblyReferences(startWith); FillMembers(location, compList, null, found, Modifiers.Public, false); }
internal XSharpSignatureProperties(XSharpSearchLocation location) { Location = location; }
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(); } } } } }