private static bool IsExceptionType(MemberResult member)
        {
            if (member.MemberType != Interpreter.JMemberType.Class) {
                return false;
            }

            if (KnownExceptions.Contains(member.Name)) {
                return true;
            }

            if (member.Name.IndexOf("Exception", StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                member.Name.IndexOf("Error", StringComparison.CurrentCultureIgnoreCase) >= 0) {
                return true;
            }

            return false;
        }
示例#2
0
        public DynamicallyVisibleCompletion[] GetModules(IGlyphService glyphService, string text, bool includeMembers = false)
        {
            var analysis = GetAnalysisEntry();
            var path = text.Split('.');
            if (path.Length > 0) {
                // path = path[:-1]
                var newPath = new string[path.Length - 1];
                Array.Copy(path, newPath, path.Length - 1);
                path = newPath;
            }

            IJReplIntellisense pyReplEval = null;
            IReplEvaluator eval;
            if (TextBuffer.Properties.TryGetProperty<IReplEvaluator>(typeof(IReplEvaluator), out eval)) {
                pyReplEval = eval as IJReplIntellisense;
            }
            IEnumerable<KeyValuePair<string, bool>> replScopes = null;
            if (pyReplEval != null) {
                replScopes = pyReplEval.GetAvailableScopesAndKind();
            }

            MemberResult[] modules = new MemberResult[0];
            if (path.Length == 0) {
                if (analysis != null && (pyReplEval == null || !pyReplEval.LiveCompletionsOnly)) {
                    modules = analysis.GetModules(true);
                }
                if (replScopes != null) {
                    HashSet<MemberResult> allModules = new HashSet<MemberResult>(CompletionComparer.UnderscoresLast);
                    allModules.UnionWith(modules);
                    foreach (var scope in replScopes) {
                        // remove an existing scope, add the new one (we take precedence)
                        var newMod = new MemberResult(scope.Key, scope.Value ? JMemberType.Module : JMemberType.Namespace);
                        allModules.Remove(newMod);
                        allModules.Add(newMod);
                    }
                    modules = allModules.ToArray();
                }
            } else {
                if (analysis != null && (pyReplEval == null || !pyReplEval.LiveCompletionsOnly)) {
                    modules = analysis.GetModuleMembers(path, includeMembers);
                }

                if (replScopes != null) {
                    HashSet<MemberResult> allModules = new HashSet<MemberResult>(CompletionComparer.UnderscoresLast);
                    allModules.UnionWith(modules);
                    foreach (var scopeAndKind in replScopes) {
                        var scope = scopeAndKind.Key;
                        var isModule = scopeAndKind.Value;

                        if (scope.StartsWith(text, StringComparison.OrdinalIgnoreCase)) {
                            var split = scope.Split('.');
                            var subPath = new string[split.Length - path.Length];
                            for(int i = 0; i<subPath.Length; i++) {
                                subPath[i] = split[i + path.Length];
                            }

                            // remove an existing scope, add the new one (we take precedence)
                            var newMod = new MemberResult(String.Join(".", subPath), isModule ? JMemberType.Module : JMemberType.Namespace);
                            allModules.Remove(newMod);
                            allModules.Add(newMod);
                        }
                    }
                    modules = allModules.ToArray();
                }
            }

            Array.Sort(modules, CompletionComparer.UnderscoresLast);
            return modules.Select(m => JCompletion(glyphService, m)).ToArray();
        }
示例#3
0
 internal static DynamicallyVisibleCompletion JCompletion(IGlyphService service, MemberResult memberResult)
 {
     return new DynamicallyVisibleCompletion(memberResult.Name,
         memberResult.Completion,
         () => memberResult.Documentation,
         () => service.GetGlyph(memberResult.MemberType.ToGlyphGroup(), StandardGlyphItem.GlyphItemPublic),
         Enum.GetName(typeof(JMemberType), memberResult.MemberType)
     );
 }
示例#4
0
            public MemberResult[] GetMemberNames(string text)
            {
                _completionResultEvent.Reset();
                _memberResults = null;

                using (new SocketLock(this)) {
                    if (!Socket.Connected || !_connected) {
                        return new MemberResult[0];
                    }
                    try {
                        Stream.Write(GetMembersCommandBytes);
                        SendString(text);
                    } catch (IOException) {
                        return new MemberResult[0];
                    } catch (SocketException) {
                        return new MemberResult[0];
                    }
                }

                if (_completionResultEvent.WaitOne(1000) && _memberResults != null) {
                    MemberResult[] res = new MemberResult[_memberResults.TypeMembers.Count + _memberResults.InstanceMembers.Count];
                    int i = 0;
                    foreach (var member in _memberResults.TypeMembers) {
                        res[i++] = CreateMemberResult(member.Key, member.Value);
                    }
                    foreach (var member in _memberResults.InstanceMembers) {
                        res[i++] = CreateMemberResult(member.Key, member.Value);
                    }

                    _memberResults = null;
                    return res;
                }
                return null;
            }