Пример #1
0
 public VariableRenamer(ITextView textView, IFunctionInformationProvider funcProvider, IDatabaseInformationProvider dbProvider, IProgramFileProvider progFileProvider, IServiceProvider serviceProvider)
 {
     _view             = textView;
     _funcProvider     = funcProvider;
     _dbProvider       = dbProvider;
     _progFileProvider = progFileProvider;
     _serviceProvider  = serviceProvider;
 }
Пример #2
0
        internal static ExpressionAnalysis GetExpressionAnalysis(this ITextView view, IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider,
                                                                 IProgramFileProvider programFileProvider)
        {
            ITrackingSpan span = GetCaretSpan(view);

            if (span == null)
            {
                return(null);
            }
            // TODO: get the function provider and database provider from EditFilter class.
            return(span.TextBuffer.CurrentSnapshot.AnalyzeExpression(span, false, functionProvider, databaseProvider, programFileProvider));
        }
Пример #3
0
        public static IEnumerable <LocationInfo> GetLocations(ITextView textView, GeneroLanguageVersion languageVersion, GetLocationOptions options = GetLocationOptions.Definitions | GetLocationOptions.References | GetLocationOptions.Values)
        {
            List <LocationInfo> locations = new List <LocationInfo>();

            Genero4glClassifier          classifier;
            IFunctionInformationProvider funcProvider     = null;
            IDatabaseInformationProvider dbProvider       = null;
            IProgramFileProvider         progfileProvider = null;

            if (textView.TextBuffer.Properties.TryGetProperty(typeof(Genero4glClassifier), out classifier))
            {
                funcProvider     = classifier.Provider._PublicFunctionProvider;
                dbProvider       = classifier.Provider._DatabaseInfoProvider;
                progfileProvider = classifier.Provider._ProgramFileProvider;
            }

            var analysis = textView.GetExpressionAnalysis(funcProvider, dbProvider, progfileProvider);

            if (analysis != null)
            {
                Dictionary <LocationInfo, SimpleLocationInfo> references, definitions, values;
                GetDefsRefsAndValues(analysis, languageVersion, out definitions, out references, out values);

                if (options.HasFlag(GetLocationOptions.Values))
                {
                    foreach (var location in values.Keys)
                    {
                        locations.Add(location);
                    }
                }

                if (options.HasFlag(GetLocationOptions.Definitions))
                {
                    foreach (var location in definitions.Keys)
                    {
                        locations.Add(location);
                    }
                }

                if (options.HasFlag(GetLocationOptions.References))
                {
                    foreach (var location in references.Keys)
                    {
                        locations.Add(location);
                    }
                }
            }

            return(locations);
        }
Пример #4
0
        /// <summary>
        /// Evaluates the given expression in at the provided line number and returns the values
        /// that the expression can evaluate to.
        /// </summary>
        /// <param name="exprText">The expression to determine the result of.</param>
        /// <param name="index">The 0-based absolute index into the file where the expression should be evaluated within the module.</param>
        public override IAnalysisResult GetValueByIndex(string exprText, int index, IFunctionInformationProvider functionProvider,
                                                        IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                        bool isFunctionCallOrDefinition, out bool isDeferred,
                                                        out IGeneroProject definingProject, out IProjectEntry projectEntry,
                                                        FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch)
        {
            _functionProvider    = functionProvider;
            _databaseProvider    = databaseProvider;
            _programFileProvider = programFileProvider;

            return(GetValueByIndex(exprText, index, this, out definingProject, out projectEntry, out isDeferred,
                                   searchInFunctionProvider,
                                   isFunctionCallOrDefinition));
        }
Пример #5
0
 internal ExpressionAnalysis(GeneroProjectAnalyzer analyzer, string expression, GeneroAst analysis, int index, ITrackingSpan span, ITextSnapshot snapshot,
                             IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                             bool isFunctionCallOrDefinition)
 {
     _expr                       = expression;
     _analysis                   = analysis;
     _index                      = index;
     _span                       = span;
     _analyzer                   = analyzer;
     _snapshot                   = snapshot;
     _functionProvider           = functionProvider;
     _databaseProvider           = databaseProvider;
     _programFileProvider        = programFileProvider;
     _isFunctionCallOrDefinition = isFunctionCallOrDefinition;
 }
Пример #6
0
        public EditFilter(ITextView textView, IEditorOperations editorOps, System.IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
            _textView        = textView;
            _editorOps       = editorOps;

            Genero4glClassifier classifier;

            if (_textView.TextBuffer.Properties.TryGetProperty(typeof(Genero4glClassifier), out classifier))
            {
                _functionProvider    = classifier.Provider._PublicFunctionProvider;
                _databaseProvider    = classifier.Provider._DatabaseInfoProvider;
                _programFileProvider = classifier.Provider._ProgramFileProvider;
            }

            BraceMatcher.WatchBraceHighlights(textView, VSGeneroPackage.ComponentModel);
        }
Пример #7
0
        internal static GeneroLanguageVersion GetLanguageVersion(string filePath, IProgramFileProvider fileProvider = null)
        {
            if (fileProvider == null && VSGeneroPackage.Instance != null)
            {
                if (VSGeneroPackage.Instance.ProgramFileProvider == null)
                {
                    return(GeneroLanguageVersion.None);
                }
                else
                {
                    fileProvider = VSGeneroPackage.Instance.ProgramFileProvider;
                }
            }

            if (fileProvider != null)
            {
                return(fileProvider.GetLanguageVersion(filePath));
            }
            return(GeneroLanguageVersion.None);
        }
        public override IEnumerable <MemberResult> GetContextMembers(int index, IReverseTokenizer revTokenizer, IFunctionInformationProvider functionProvider,
                                                                     IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                                     bool isMemberAccess,
                                                                     out bool includePublicFunctions, out bool includeDatabaseTables, string contextStr,
                                                                     GetMemberOptions options = GetMemberOptions.IntersectMultipleResults)
        {
            _instance               = this;
            _functionProvider       = functionProvider;
            _databaseProvider       = databaseProvider;
            _programFileProvider    = programFileProvider;
            _includePublicFunctions = includePublicFunctions = false;    // this is a flag that the context determination logic sets if public functions should eventually be included in the set
            _includeDatabaseTables  = includeDatabaseTables = false;
            _contextString          = contextStr;

            List <MemberResult> members = new List <MemberResult>();

            // First see if we have a member completion
            if (TryMemberAccess(index, revTokenizer, out members))
            {
                _includePublicFunctions = false;
                _includeDatabaseTables  = false;
                return(members);
            }

            if (!DetermineContext(index, revTokenizer, members) && members.Count == 0)
            {
                // TODO: do we want to put in the statement keywords?
                members.AddRange(GetStatementStartKeywords(index));
            }

            includePublicFunctions  = _includePublicFunctions;
            includeDatabaseTables   = _includeDatabaseTables;
            _includePublicFunctions = false;    // reset the flag
            _includeDatabaseTables  = false;
            _contextString          = null;
            return(members);
        }
Пример #9
0
 public abstract IAnalysisResult GetValueByIndex(string exprText, int index, IFunctionInformationProvider functionProvider,
                                                 IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                 bool isFunctionCallOrDefinition, out bool isDeferred,
                                                 out IGeneroProject definingProject, out IProjectEntry projectEntry,
                                                 FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch);
Пример #10
0
 public override IEnumerable <IAnalysisVariable> GetVariablesByIndex(string exprText, int index, IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider, bool isFunctionCallOrDefinition)
 {
     return(new IAnalysisVariable[0]);
 }
Пример #11
0
        internal static GeneroLanguageVersion GetLanguageVersion(this ITextView textView, IProgramFileProvider fileProvider = null)
        {
            if (fileProvider == null)
            {
                if (VSGeneroPackage.Instance.ProgramFileProvider == null)
                {
                    return(GeneroLanguageVersion.None);
                }
                else
                {
                    fileProvider = VSGeneroPackage.Instance.ProgramFileProvider;
                }
            }

            var path = textView.GetFilePath();

            if (path == null)
            {
                return(GeneroLanguageVersion.None);
            }

            if (fileProvider != null)
            {
                return(fileProvider.GetLanguageVersion(path));
            }
            return(GeneroLanguageVersion.None);
        }
Пример #12
0
 /// <summary>
 /// Gets a ExpressionAnalysis for the expression at the provided span.  If the span is in
 /// part of an identifier then the expression is extended to complete the identifier.
 /// </summary>
 public static ExpressionAnalysis AnalyzeExpression(this ITextSnapshot snapshot, ITrackingSpan span, bool forCompletion,
                                                    IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider,
                                                    IProgramFileProvider programFileProvider)
 {
     return(GeneroProjectAnalyzer.AnalyzeExpression(snapshot, span, functionProvider, databaseProvider, programFileProvider, forCompletion));
 }
Пример #13
0
 /// <summary>
 /// Gets a CompletionAnalysis providing a list of possible members the user can dot through.
 /// </summary>
 public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, ITrackingSpan span, ITrackingPoint point, CompletionOptions options,
                                                 IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider,
                                                 IProgramFileProvider programFileProvider)
 {
     return(GeneroProjectAnalyzer.GetCompletions(snapshot, span, point, options, functionProvider, databaseProvider, programFileProvider));
 }
Пример #14
0
 public abstract IEnumerable <IAnalysisVariable> GetVariablesByIndex(string exprText, int index, IFunctionInformationProvider functionProvider,
                                                                     IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                                     bool isFunctionCallOrDefinition);
Пример #15
0
        /// <summary>
        /// Gets the variables the given expression evaluates to.  Variables include parameters, locals, and fields assigned on classes, modules and instances.
        ///
        /// Variables are classified as either definitions or references.  Only parameters have unique definition points - all other types of variables
        /// have only one or more references.
        ///
        /// index is a 0-based absolute index into the file.
        /// </summary>
        public override IEnumerable <IAnalysisVariable> GetVariablesByIndex(string exprText, int index, IFunctionInformationProvider functionProvider,
                                                                            IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                                            bool isFunctionCallOrDefinition)
        {
            _functionProvider    = functionProvider;
            _databaseProvider    = databaseProvider;
            _programFileProvider = programFileProvider;

            List <IAnalysisVariable> vars = new List <IAnalysisVariable>();

            _body.SetNamespace(null);
            AstNode containingNode = GetContainingNode(_body, index);

            if (containingNode != null)
            {
                if (!isFunctionCallOrDefinition)
                {
                    if (containingNode is IFunctionResult)
                    {
                        // Check for local vars, types, and constants
                        IFunctionResult func = containingNode as IFunctionResult;
                        IAnalysisResult res;

                        if (func.Variables.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (func.Types.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (func.Constants.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        List <Tuple <IAnalysisResult, IndexSpan> > limitedScopeVars;
                        if (func.LimitedScopeVariables.TryGetValue(exprText, out limitedScopeVars))
                        {
                            foreach (var item in limitedScopeVars)
                            {
                                if (item.Item2.IsInSpan(index))
                                {
                                    vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Reference));
                                }
                            }
                        }
                    }
                }

                if (_body is IModuleResult)
                {
                    // check for module vars, types, and constants (and globals defined in this module)
                    IModuleResult   mod = _body as IModuleResult;
                    IAnalysisResult res;

                    if (!isFunctionCallOrDefinition)
                    {
                        if (mod.Variables.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (mod.Types.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (mod.Constants.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (mod.GlobalVariables.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (mod.GlobalTypes.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        if (mod.GlobalConstants.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }

                        // check for cursors in this module
                        if (mod.Cursors.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(res), VariableType.Definition));
                        }
                    }
                    else
                    {
                        // check for module functions
                        IFunctionResult funcRes;
                        if (mod.Functions.TryGetValue(exprText, out funcRes))
                        {
                            vars.Add(new AnalysisVariable(this.ResolveLocation(funcRes), VariableType.Definition, funcRes.Name, 1));
                        }
                    }
                }
            }

            // TODO: this could probably be done more efficiently by having each GeneroAst load globals and functions into
            // dictionaries stored on the IGeneroProject, instead of in each project entry.
            // However, this does required more upkeep when changes occur. Will look into it...
            if (_projEntry != null && _projEntry is IGeneroProjectEntry)
            {
                IGeneroProjectEntry genProj = _projEntry as IGeneroProjectEntry;
                if (genProj.ParentProject != null &&
                    !genProj.FilePath.ToLower().EndsWith(".inc"))
                {
                    foreach (var projEntry in genProj.ParentProject.ProjectEntries.Where(x => x.Value != genProj))
                    {
                        if (projEntry.Value.Analysis != null &&
                            projEntry.Value.Analysis.Body != null)
                        {
                            projEntry.Value.Analysis.Body.SetNamespace(null);
                            IModuleResult modRes = projEntry.Value.Analysis.Body as IModuleResult;
                            if (modRes != null)
                            {
                                if (!isFunctionCallOrDefinition)
                                {
                                    // check global vars, types, and constants
                                    // TODO: need to introduce option to enable/disable legacy linking
                                    IAnalysisResult res;
                                    if (modRes.GlobalVariables.TryGetValue(exprText, out res) || modRes.Variables.TryGetValue(exprText, out res))
                                    {
                                        vars.Add(new AnalysisVariable(projEntry.Value.Analysis.ResolveLocation(res), VariableType.Definition));
                                    }

                                    if (modRes.GlobalTypes.TryGetValue(exprText, out res) || modRes.Types.TryGetValue(exprText, out res))
                                    {
                                        vars.Add(new AnalysisVariable(projEntry.Value.Analysis.ResolveLocation(res), VariableType.Definition));
                                    }

                                    if (modRes.GlobalConstants.TryGetValue(exprText, out res) || modRes.Constants.TryGetValue(exprText, out res))
                                    {
                                        vars.Add(new AnalysisVariable(projEntry.Value.Analysis.ResolveLocation(res), VariableType.Definition));
                                    }

                                    // check for cursors in this module
                                    if (modRes.Cursors.TryGetValue(exprText, out res))
                                    {
                                        vars.Add(new AnalysisVariable(projEntry.Value.Analysis.ResolveLocation(res), VariableType.Definition));
                                    }
                                }
                                else
                                {
                                    // check for module functions
                                    IFunctionResult funcRes;
                                    if (modRes.Functions.TryGetValue(exprText, out funcRes))
                                    {
                                        vars.Add(new AnalysisVariable(projEntry.Value.Analysis.ResolveLocation(funcRes), VariableType.Definition, funcRes.Name, 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            /* TODO:
             * Need to check for:
             * 1) Temp tables
             * 2) DB Tables and columns
             * 3) Record fields
             */

            if (isFunctionCallOrDefinition && _functionProvider != null)
            {
                var funcRes = _functionProvider.GetFunction(exprText);
                if (funcRes != null)
                {
                    vars.AddRange(funcRes.Select(x => new AnalysisVariable(x.Location, VariableType.Definition, x.Name, 2)));
                }

                IFunctionResult funcResult;
                if (SystemFunctions.TryGetValue(exprText, out funcResult))
                {
                    vars.Add(new AnalysisVariable(funcResult.Location, VariableType.Definition, funcResult.Name, 2));
                }
            }

            // try an imported module
            if (Body is IModuleResult && ProjectEntry != null)
            {
                if ((Body as IModuleResult).FglImports.Contains(exprText))
                {
                    // need to get the ast for the other project entry
                    var refProjKVP = (ProjectEntry as IGeneroProjectEntry).ParentProject.ReferencedProjects.Values.FirstOrDefault(
                        x =>
                    {
                        var fn = Path.GetFileNameWithoutExtension(x.Directory);
                        return(fn?.Equals(exprText, StringComparison.OrdinalIgnoreCase) ?? false);
                    });
                    if (refProjKVP is IAnalysisResult)
                    {
                        IGeneroProject definingProject = refProjKVP;
                        vars.Add(new AnalysisVariable(new LocationInfo(definingProject.Directory, 1), VariableType.Definition));
                    }
                }
            }

            if (exprText.Contains('.') && vars.Count == 0)
            {
                IGeneroProject  definingProj;
                IProjectEntry   projEntry;
                bool            dummyDef;
                IAnalysisResult res = GetValueByIndex(exprText, index, functionProvider, databaseProvider, _programFileProvider, isFunctionCallOrDefinition, out dummyDef, out definingProj, out projEntry);
                if (res != null)
                {
                    LocationInfo locInfo = null;
                    if (definingProj != null || projEntry != null)
                    {
                        locInfo = ResolveLocationInternal(definingProj, projEntry, res);
                    }
                    else
                    {
                        locInfo = this.ResolveLocation(res);
                    }
                    if (locInfo != null &&
                        (
                            (locInfo.Index > 0 || (locInfo.Line > 0 && locInfo.Column > 0)) ||
                            !string.IsNullOrWhiteSpace(locInfo.DefinitionURL)
                        )
                        )
                    {
                        vars.Add(new AnalysisVariable(locInfo, VariableType.Definition));
                    }
                }
            }

            if (_body is IModuleResult &&
                _projEntry is IGeneroProjectEntry)
            {
                string   dotPiece  = exprText;
                string[] dotPieces = exprText.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (dotPieces.Length > 1)
                {
                    dotPiece = dotPieces[0];
                }
                if ((_body as IModuleResult).FglImports.Contains(dotPiece))
                {
                    // need to get the ast for the other project entry
                    var refProjKVP = (_projEntry as IGeneroProjectEntry).ParentProject.ReferencedProjects.Values.FirstOrDefault(
                        x =>
                    {
                        var fn = Path.GetFileName(x.Directory);
                        return(fn?.Equals(dotPiece, StringComparison.OrdinalIgnoreCase) ?? false);
                    });
                    if (refProjKVP is IAnalysisResult)
                    {
                        IProjectEntry   dummyEntry;
                        bool            dummyDef;
                        IAnalysisResult res = GetValueByIndex(exprText, index, functionProvider, databaseProvider, _programFileProvider, isFunctionCallOrDefinition, out dummyDef, out refProjKVP, out dummyEntry);
                        if (res != null)
                        {
                            LocationInfo locInfo = null;
                            locInfo = refProjKVP != null?ResolveLocationInternal(refProjKVP, dummyEntry, res) : this.ResolveLocation(res);

                            if (locInfo != null && (locInfo.Index > 0 || (locInfo.Line > 0 && locInfo.Column > 0)))
                            {
                                vars.Add(new AnalysisVariable(locInfo, VariableType.Definition));
                            }
                        }
                    }
                }
            }

            if (!isFunctionCallOrDefinition)
            {
                foreach (var includeFile in this.ProjectEntry.GetIncludedFiles())
                {
                    IAnalysisResult res;
                    if (includeFile.Analysis != null &&
                        includeFile.Analysis.Body is IModuleResult)
                    {
                        includeFile.Analysis.Body.SetNamespace(null);
                        var mod = includeFile.Analysis.Body as IModuleResult;
                        if (mod.Types.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(ResolveLocationInternal(null, includeFile, res), VariableType.Definition));
                        }
                        if (mod.Constants.TryGetValue(exprText, out res))
                        {
                            vars.Add(new AnalysisVariable(ResolveLocationInternal(null, includeFile, res), VariableType.Definition));
                        }
                    }
                }
            }

            return(vars);
        }
Пример #16
0
 public abstract IEnumerable <MemberResult> GetContextMembers(int index, IReverseTokenizer revTokenizer, IFunctionInformationProvider functionProvider,
                                                              IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                              bool isMemberAccess,
                                                              out bool includePublicFunctions, out bool includeDatabaseTables, string contextStr,
                                                              GetMemberOptions options = GetMemberOptions.IntersectMultipleResults);
Пример #17
0
 public override IEnumerable <MemberResult> GetContextMembers(int index, IReverseTokenizer revTokenizer, IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider, out bool includePublicFunctions, out bool includeDatabaseTables, string contextStr, GetMemberOptions options = GetMemberOptions.IntersectMultipleResults)
 {
     includePublicFunctions = false;
     includeDatabaseTables  = false;
     return(new MemberResult[0]);
 }