Пример #1
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            var ctxt = ResolutionContext.Create(Editor, false);

            foreach (var kv in VersionCompletionItems)
            {
                CompletionDataGenerator.AddTextItem(kv.Key, kv.Value);
            }

            CodeCompletion.DoTimeoutableCompletionTask(CompletionDataGenerator, ctxt, () => {
                ctxt.Push(Editor);
                var cs = ctxt.CurrentContext.DeclarationCondititons;
                foreach (var v in cs.GlobalFlags.Versions)
                {
                    if (!VersionCompletionItems.ContainsKey(v))
                    {
                        CompletionDataGenerator.AddTextItem(v, "");
                    }
                }
                foreach (var v in cs.LocalFlags.Versions)
                {
                    if (!VersionCompletionItems.ContainsKey(v))
                    {
                        CompletionDataGenerator.AddTextItem(v, "");
                    }
                }
            });
        }
Пример #2
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
        {
            ed   = Editor;
            ctxt = ResolutionContext.Create(Editor, false);

            AbstractType t = null;

            CodeCompletion.DoTimeoutableCompletionTask(CompletionDataGenerator, ctxt, () =>
            {
                ctxt.Push(Editor);
                if (AccessExpression is IExpression)
                {
                    t = ExpressionTypeEvaluation.EvaluateType(AccessExpression as IExpression, ctxt);
                }
                else if (AccessExpression is ITypeDeclaration)
                {
                    t = TypeDeclarationResolver.ResolveSingle(AccessExpression as ITypeDeclaration, ctxt);
                }
            });

            if (t == null)             //TODO: Add after-space list creation when an unbound . (Dot) was entered which means to access the global scope
            {
                return;
            }

            t.Accept(this);
        }
Пример #3
0
        protected override IEnumerable <Ide.FindInFiles.MemberReference> GetReferences(Tuple <ResolutionContext, DSymbol> tup, System.Threading.CancellationToken token)
        {
            var ctxt = tup.Item1;

            ctxt.CancellationToken = token;
            var mr = tup.Item2;

            var referencedNode = mr.Definition;

            // Slightly hacky: To keep highlighting the id of e.g. a NewExpression, take the ctor's parent node (i.e. the class node)
            if (referencedNode is DMethod && ((DMethod)referencedNode).SpecialType == DMethod.MethodType.Constructor)
            {
                mr = mr.Base as DSymbol;
                if (mr == null)
                {
                    yield break;
                }
                referencedNode = mr.Definition;
            }

            IEnumerable <ISyntaxRegion> refs = null;

            CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () => {
                try {
                    refs = D_Parser.Refactoring.ReferencesFinder.SearchModuleForASTNodeReferences(SyntaxTree, referencedNode, ctxt);
                } catch (Exception ex) {
                    LoggingService.LogInfo("Error during highlighting usages", ex);
                }
            });

            if (refs != null)
            {
                foreach (var sr in refs)
                {
                    CodeLocation loc;
                    int          len;
                    if (sr is INode)
                    {
                        loc = (sr as INode).NameLocation;
                        len = (sr as INode).Name.Length;
                    }
                    else if (sr is TemplateParameter)
                    {
                        loc = (sr as TemplateParameter).NameLocation;
                        len = (sr as TemplateParameter).Name.Length;
                    }
                    else
                    {
                        loc = sr.Location;
                        len = sr.EndLocation.Column - loc.Column;
                    }

                    yield return(new Ide.FindInFiles.MemberReference(sr,
                                                                     new ICSharpCode.NRefactory.TypeSystem.DomRegion(Document.FileName, loc.Line, loc.Column, loc.Line, loc.Column + len),
                                                                     Document.Editor.LocationToOffset(loc.Line, loc.Column), len));
                }
            }
        }
Пример #4
0
 void GenUfcsAndStaticProperties(AbstractType t)
 {
     if (t.NonStaticAccess && CompletionOptions.Instance.ShowUFCSItems)
     {
         CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () =>
         {
             foreach (var ufcsItem in UFCSResolver.TryResolveUFCS(t, 0, ed.CaretLocation, ctxt))
             {
                 CompletionDataGenerator.Add((ufcsItem as DSymbol).Definition);
             }
         });
     }
     StaticProperties.ListProperties(CompletionDataGenerator, ctxt, MemberFilter, t, t.NonStaticAccess);
 }
Пример #5
0
        public static Dictionary <int, Dictionary <ISyntaxRegion, byte> > Scan(IEditorData ed, List <ISyntaxRegion> invalidConditionalCodeRegions = null, int timeout = int.MinValue)
        {
            if (ed == null || ed.SyntaxTree == null)
            {
                return(new Dictionary <int, Dictionary <ISyntaxRegion, byte> >());
            }

            var ctxt = ResolutionContext.Create(ed, false);

            // Since it's just about enumerating, not checking types, ignore any conditions
            ctxt.ContextIndependentOptions |= ResolutionOptions.IgnoreDeclarationConditions;

            var typeRefFinder = new TypeReferenceFinder(ctxt, invalidConditionalCodeRegions);

            CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () => ed.SyntaxTree.Accept(typeRefFinder), timeout);

            return(typeRefFinder.Matches);
        }
Пример #6
0
        public static AbstractType ResolveType(IEditorData editor, ResolutionContext ctxt = null)
        {
            var o = GetScopedCodeObject(editor);

            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor, false);
            }

            AbstractType ret = null;

            CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () =>
            {
                ctxt.Push(editor);

                var optionBackup = ctxt.CurrentContext.ContextDependentOptions;
                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

                if (o is IExpression)
                {
                    ret = ExpressionTypeEvaluation.EvaluateType((IExpression)o, ctxt, false);
                }
                else if (o is ITypeDeclaration)
                {
                    ret = TypeDeclarationResolver.ResolveSingle((ITypeDeclaration)o, ctxt);
                }
                else if (o is INode)
                {
                    ret = TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt);
                }

                ctxt.CurrentContext.ContextDependentOptions = optionBackup;
            });

            return(ret);
        }
Пример #7
0
        public static AbstractType ResolveTypeLoosely(IEditorData editor, out NodeResolutionAttempt resolutionAttempt, ResolutionContext ctxt = null)
        {
            var o = GetScopedCodeObject(editor);

            if (ctxt == null)
            {
                ctxt = ResolutionContext.Create(editor, false);
            }

            AbstractType          ret        = null;
            NodeResolutionAttempt resAttempt = NodeResolutionAttempt.Normal;

            CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () =>
            {
                ctxt.Push(editor);

                var optionBackup = ctxt.CurrentContext.ContextDependentOptions;
                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly | ResolutionOptions.DontResolveAliases;

                if (o is IExpression)
                {
                    ret = ExpressionTypeEvaluation.EvaluateType((IExpression)o, ctxt, false);
                }
                else if (o is ITypeDeclaration)
                {
                    ret = TypeDeclarationResolver.ResolveSingle((ITypeDeclaration)o, ctxt);
                }
                else if (o is INode)
                {
                    ret = TypeDeclarationResolver.HandleNodeMatch(o as INode, ctxt, null, o);
                }
                else
                {
                    ret = null;
                }

                if (ret == null)
                {
                    resAttempt = NodeResolutionAttempt.NoParameterOrTemplateDeduction;

                    if (o is PostfixExpression_MethodCall)
                    {
                        o = (o as PostfixExpression_MethodCall).PostfixForeExpression;
                    }

                    ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.NoTemplateParameterDeduction | ResolutionOptions.DontResolveAliases;

                    if (o is IdentifierExpression)
                    {
                        ret = AmbiguousType.Get(ExpressionTypeEvaluation.GetOverloads(o as IdentifierExpression, ctxt, deduceParameters: false), o);
                    }
                    else if (o is ITypeDeclaration)
                    {
                        ret = TypeDeclarationResolver.ResolveSingle(o as ITypeDeclaration, ctxt);
                    }
                    else if (o is IExpression)
                    {
                        ret = ExpressionTypeEvaluation.EvaluateType(o as IExpression, ctxt, false);
                    }
                }

                if (ret == null)
                {
                    resAttempt    = NodeResolutionAttempt.RawSymbolLookup;
                    var overloads = TypeDeclarationResolver.HandleNodeMatches(LookupIdRawly(editor, o as ISyntaxRegion), ctxt, null, o);
                    ret           = AmbiguousType.Get(overloads, o);
                }

                ctxt.CurrentContext.ContextDependentOptions = optionBackup;
            });

            resolutionAttempt = resAttempt;

            if (ret != null)
            {
                ret.DeclarationOrExpressionBase = o;
            }

            return(ret);
        }
        public ObjectValue Resolve(ulong offset, string symbolname, string typename, string val, DEW.DebugScopedSymbol parentsymbol)
        {
            DModule module;
            int     codeLine;
            INode   variableNode = null;

            // Search currently scoped module
            string file = "";
            uint   line = 0;

            Engine.Symbols.GetLineByOffset(Engine.CurrentInstructionOffset, out file, out line);
            codeLine = (int)line;

            if (string.IsNullOrWhiteSpace(file))
            {
                return(null);
            }

            AbstractDProject dproj = null;

            module = GetFileSyntaxTree(file, out dproj);

            // If syntax tree built, search the variable location
            if (module != null)
            {
                var ed   = Resolver.DResolverWrapper.CreateEditorData(IdeApp.Workbench.ActiveDocument);
                var ctxt = ResolutionContext.Create(ed, false);

                CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () =>
                {
                    var loc = new CodeLocation(0, codeLine);
                    ctxt.Push(DResolver.SearchBlockAt(module, loc), loc);

                    AbstractType[] res;
                    if (parentsymbol != null)
                    {
                        var parentres = ResolveParentSymbol(parentsymbol, ctxt);
                        res           = TypeDeclarationResolver.ResolveFurtherTypeIdentifier(symbolname, parentres, ctxt, null);
                    }
                    else
                    {
                        res = TypeDeclarationResolver.ResolveIdentifier(symbolname, ctxt, null);
                    }

                    if (res != null && res.Length > 0 && res[0] is DSymbol)
                    {
                        variableNode = (res[0] as DSymbol).Definition;
                    }
                });
            }

            // Set type string
            string _typeString = typename;

            if (variableNode != null)
            {
                var t = variableNode.Type;
                if (t != null)
                {
                    _typeString = t.ToString();
                }
            }

            // Set value string
            string _valueString = val;

            ObjectValueFlags flags = ObjectValueFlags.Variable;

            if (variableNode != null)
            {
                ITypeDeclaration curValueType = variableNode.Type;
                if (curValueType != null)
                {
                    if (!IsBasicType(curValueType))
                    {
                        if (_typeString == "string")                         //TODO: Replace this by searching the alias definition in the cache
                        {
                            curValueType = new ArrayDecl()
                            {
                                InnerDeclaration = new DTokenDeclaration(DTokens.Char)
                            }
                        }
                        ;
                        else if (_typeString == "wstring")
                        {
                            curValueType = new ArrayDecl()
                            {
                                InnerDeclaration = new DTokenDeclaration(DTokens.Wchar)
                            }
                        }
                        ;
                        else if (_typeString == "dstring")
                        {
                            curValueType = new ArrayDecl()
                            {
                                InnerDeclaration = new DTokenDeclaration(DTokens.Dchar)
                            }
                        }
                        ;

                        if (IsArray(curValueType))
                        {
                            flags = ObjectValueFlags.Array;

                            var clampDecl = curValueType as ArrayDecl;
                            var valueType = clampDecl.InnerDeclaration;

                            if (valueType is DTokenDeclaration)
                            {
                                bool IsString = false;
                                uint elsz     = 0;
                                var  realType = DetermineArrayType((valueType as DTokenDeclaration).Token, out elsz, out IsString);

                                var arr = Engine.Symbols.ReadArray(offset, realType, elsz);

                                if (arr != null)
                                {
                                    _valueString = BuildArrayContentString(arr, IsString);
                                }
                            }
                        }
                        else
                        {
                            flags = ObjectValueFlags.Object;
                        }
                    }
                }
            }

            return(ObjectValue.CreatePrimitive(ObjectValueSource, new ObjectPath(symbolname), _typeString, new EvaluationResult(_valueString), flags));
        }