public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic);
            ImageSource        variableGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic);

            string variableName = context.Session.TextView.GetVariableNameBeforeCaret();

            VariablesProvider.Initialize();
            int memberCount = VariablesProvider.GetMemberCount(variableName);
            IReadOnlyCollection <INamedItemInfo> members = VariablesProvider.GetMembers(variableName, 200);

            // Get list of functions in the package
            foreach (var v in members)
            {
                Debug.Assert(v != null);
                if (v.Name.Length > 0 && v.Name[0] != '[')
                {
                    ImageSource glyph      = v.ItemType == NamedItemType.Variable ? variableGlyph : functionGlyph;
                    var         completion = new RCompletion(v.Name, CompletionUtilities.BacktickName(v.Name), v.Description, glyph);
                    completions.Add(completion);
                }
            }

            return(completions);
        }
Exemple #2
0
        private void UpdateListContainer(ListViewItem item, Character c)
        {
            item.Height = PrintModel.GlyphSize;
            Grid g = (Grid)item.ContentTemplateRoot;

            g.ColumnDefinitions[0].Width = new GridLength(PrintModel.GlyphSize);

            TextBlock t = (TextBlock)g.Children[0];

            t.Height = t.Width = PrintModel.GlyphSize;

            TextBlock unicodeId = ((TextBlock)((StackPanel)g.Children[1]).Children[0]);

            unicodeId.SetVisible(PrintModel.Annotation != GlyphAnnotation.None);
            unicodeId.Text = c.GetAnnotation(PrintModel.Annotation);

            TextBlock description = ((TextBlock)((StackPanel)g.Children[1]).Children[1]);

            try
            {
                description.Text = GlyphService.GetCharacterDescription(c.UnicodeIndex, PrintModel.Font);
            }
            catch { }

            IXamlDirectObject o = _xamlDirect.GetXamlDirectObject(t);

            CharacterGridView.SetGlyphProperties(_xamlDirect, o, PrintModel.GetTemplateSettings(), c);

            foreach (var r in g.GetFirstLevelDescendantsOfType <Rectangle>())
            {
                r.SetVisible(PrintModel.ShowBorders);
            }
        }
Exemple #3
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();

            if (!context.IsInNameSpace())
            {
                var         infoSource   = _snippetInformationSource?.InformationSource;
                ImageSource keyWordGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphKeyword, StandardGlyphItem.GlyphItemPublic, _shell);

                foreach (string keyword in Keywords.KeywordList)
                {
                    bool?isSnippet = infoSource?.IsSnippet(keyword);
                    if (!isSnippet.HasValue || !isSnippet.Value)
                    {
                        completions.Add(new RCompletion(keyword, keyword, string.Empty, keyWordGlyph));
                    }
                }

                ImageSource buildInGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupIntrinsic, StandardGlyphItem.GlyphItemPublic, _shell);
                foreach (string s in Builtins.BuiltinList)
                {
                    completions.Add(new RCompletion(s, s, string.Empty, buildInGlyph));
                }
            }

            return(completions);
        }
Exemple #4
0
 private void SetIcon(string browserName)
 {
     if (browserName.Contains("internet explorer"))
     {
         _icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/Browsers/ie.png", UriKind.RelativeOrAbsolute));
     }
     else if (browserName.Contains("firefox"))
     {
         _icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/Browsers/ff.png", UriKind.RelativeOrAbsolute));
     }
     else if (browserName.Contains("opera"))
     {
         _icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/Browsers/o.png", UriKind.RelativeOrAbsolute));
     }
     else if (browserName.Contains("chrome"))
     {
         _icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/Browsers/c.png", UriKind.RelativeOrAbsolute));
     }
     else if (browserName.Contains("safari"))
     {
         _icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/Browsers/s.png", UriKind.RelativeOrAbsolute));
     }
     else if (browserName.Contains("microsoft edge"))
     {
         _icon = BitmapFrame.Create(new Uri("pack://application:,,,/WebEssentials2015;component/Resources/Images/Browsers/e.png", UriKind.RelativeOrAbsolute));
     }
     else
     {
         _icon = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupEnumMember, StandardGlyphItem.GlyphItemPublic);
     }
 }
Exemple #5
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.Name.Text != "\"$ref\"" || member.JSONDocument.Children.Count == 0)
            {
                yield break;
            }

            var visitor = new JSONItemCollector <JSONMember>(false);

            member.JSONDocument.Children[0].Accept(visitor);

            var definition = visitor.Items.FirstOrDefault(prop => prop.Name != null && prop.Name.Text == "\"definitions\"");

            if (definition == null || definition.Children.Count < 3)
            {
                yield break;
            }

            var block = definition.Children[2] as JSONBlockItem;

            var visitor2 = new JSONItemCollector <JSONMember>(false);

            block.Accept(visitor2);

            foreach (var prop in visitor2.Items)
            {
                string text = "#/definitions/" + prop.Name.Text.Trim('"');

                yield return(new JSONCompletionEntry(text, "\"" + text + "\"", null,
                                                     GlyphService.GetGlyph(StandardGlyphGroup.GlyphReference, StandardGlyphItem.GlyphItemPublic),
                                                     "iconAutomationText", true, context.Session as ICompletionSession));
            }
        }
Exemple #6
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic);
            ImageSource        variableGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic);

            var ast = context.AstRoot;
            // First try simple scope like in 'for(x in 1:10) x|'
            IScope scope = ast.GetNodeOfTypeFromPosition <SimpleScope>(context.Position, includeEnd: true);

            // If not found, look for the regular scope
            scope = scope ?? ast.GetNodeOfTypeFromPosition <IScope>(context.Position);

            var variables = scope.GetApplicableVariables(context.Position);

            foreach (var v in variables)
            {
                RCompletion completion;
                RFunction   f = v.Value as RFunction;
                completion = new RCompletion(v.Name, CompletionUtilities.BacktickName(v.Name), string.Empty, f != null ? functionGlyph : variableGlyph);
                completions.Add(completion);
            }

            return(completions);
        }
Exemple #7
0
        private void ShapeSelectionForm_Load(object sender, EventArgs e)
        {
            var extensibility = ObjectFactory.GetInstance <IExtensibility>( );

            extensibility.ShapeProviders.ForEach(
                sp => uiShapeList.Items.Add(
                    new ListViewItem(sp.Name)
            {
                Tag = sp
            }));

            uiShapeList.View = View.List;

            uiShapePropertyGrid.PropertyValueChanged += (s, args) => _whenShapeChanges(_currentShape.Vertices);

            var site = new SimpleSite
            {
                Name      = "GridSite",
                Component = uiShapePropertyGrid,
            };

            _glyphService = new GlyphService( );

            _glyphService.QueryPropertyUIValueItems += verifyDataErrorInfo;

            site.AddService <IPropertyValueUIService>(_glyphService);

            uiShapePropertyGrid.Site = site;

            uiShapeList.SelectedItems.Clear(  );
            uiShapeList.MultiSelect       = false;
            uiShapeList.Items[0].Selected = true;
        }
Exemple #8
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            ImageSource glyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphLibrary, StandardGlyphItem.GlyphItemPublic, _shell);

            return(_packageIndex.Packages
                   .Select(p => new RCompletion(p.Name, p.Name, p.Description, glyph))
                   .ToList());
        }
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupValueType, StandardGlyphItem.GlyphItemPublic);

            // Safety checks
            FunctionCall funcCall = context.AstRoot.GetNodeOfTypeFromPosition <FunctionCall>(context.Position);

            if (funcCall == null || funcCall.OpenBrace == null || funcCall.Arguments == null)
            {
                return(completions);
            }

            if (context.Position < funcCall.OpenBrace.End || context.Position >= funcCall.SignatureEnd)
            {
                return(completions);
            }

            // Retrieve parameter positions from the current text buffer snapshot
            ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(context.AstRoot, context.TextBuffer.CurrentSnapshot, context.Position);

            if (parametersInfo == null)
            {
                return(completions);
            }

            // Get collection of function signatures from documentation (parsed RD file)
            IFunctionInfo functionInfo = FunctionIndex.GetFunctionInfo(parametersInfo.FunctionName, o => { }, context.Session.TextView);

            if (functionInfo == null)
            {
                return(completions);
            }

            // Collect parameter names from all signatures
            IEnumerable <KeyValuePair <string, IArgumentInfo> > arguments = new Dictionary <string, IArgumentInfo>();

            foreach (ISignatureInfo signature in functionInfo.Signatures)
            {
                var args = signature.Arguments.ToDictionary(x => x.Name);
                arguments = arguments.Union(args);
            }

            // Add names of arguments that  are not yet specified to the completion
            // list with '=' sign so user can tell them from function names.
            IEnumerable <string> declaredArguments = funcCall.Arguments.Where(x => x is NamedArgument).Select(x => ((NamedArgument)x).Name);
            IEnumerable <KeyValuePair <string, IArgumentInfo> > possibleArguments = arguments.Where(x => x.Key != "..." && !declaredArguments.Contains(x.Key));

            foreach (KeyValuePair <string, IArgumentInfo> arg in possibleArguments)
            {
                string displayText   = arg.Key + " =";
                string insertionText = arg.Key + " = ";
                completions.Add(new RCompletion(displayText, insertionText, arg.Value.Description, functionGlyph));
            }

            return(completions);
        }
        public IList <HtmlCompletion> GetEntries(HtmlCompletionContext context)
        {
            var list  = new HashSet <string>();
            var glyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic);

            context.Document.HtmlEditorTree.RootNode.Accept(this, list);

            return(list.Select(s => new HtmlCompletion(s, s, s, glyph, HtmlIconAutomationText.AttributeIconText, null)).ToList());
        }
        private static string GetFileName(
            InstalledFont selectedFont,
            FontVariant selectedVariant,
            Character selectedChar,
            string ext)
        {
            var chr = GlyphService.GetCharacterDescription(selectedChar.UnicodeIndex, selectedVariant) ?? selectedChar.UnicodeString;

            return($"{selectedFont.Name} {selectedVariant.PreferredName} - {chr}.{ext}");
        }
        public string GetDescription(Character c)
        {
            if (SearchMap == null ||
                !SearchMap.TryGetValue(c, out string mapping) ||
                string.IsNullOrWhiteSpace(mapping))
            {
                return(GlyphService.GetCharacterDescription(c.UnicodeIndex, this));
            }

            return(GlyphService.TryGetAGLFNName(mapping));
        }
Exemple #13
0
        private ImageSource CreateGlyph(uint key)
        {
            var         group  = (StandardGlyphGroup)(key >> 16);
            var         item   = (StandardGlyphItem)(key & 0xFFFF);
            ImageSource source = null;

            // create the glyph on the UI thread
            var dispatcher = Dispatcher;

            dispatcher?.Invoke(() => source = GlyphService.GetGlyph(group, item));
            return(source);
        }
Exemple #14
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        folderGlyph   = GlyphService.GetGlyph(StandardGlyphGroup.GlyphClosedFolder, StandardGlyphItem.GlyphItemPublic);
            string             directory     = null;
            string             userDirectory = null;

            if (_userDirectoryFetchingTask != null)
            {
                _userDirectoryFetchingTask.Wait(500);
                userDirectory = _userDirectoryFetchingTask.IsCompleted ? _userDirectoryFetchingTask.Result : null;
                userDirectory = userDirectory ?? _cachedUserDirectory;
            }

            try {
                if (!string.IsNullOrEmpty(userDirectory))
                {
                    _cachedUserDirectory = userDirectory;
                    directory            = Path.Combine(userDirectory, _directory);
                }
                else
                {
                    directory = Path.Combine(RToolsSettings.Current.WorkingDirectory, _directory);
                }

                if (Directory.Exists(directory))
                {
                    foreach (string dir in Directory.GetDirectories(directory))
                    {
                        DirectoryInfo di = new DirectoryInfo(dir);
                        if (!di.Attributes.HasFlag(FileAttributes.Hidden) && !di.Attributes.HasFlag(FileAttributes.System))
                        {
                            string dirName = Path.GetFileName(dir);
                            completions.Add(new RCompletion(dirName, dirName + "/", string.Empty, folderGlyph));
                        }
                    }

                    foreach (string file in Directory.GetFiles(directory))
                    {
                        FileInfo di = new FileInfo(file);
                        if (!di.Attributes.HasFlag(FileAttributes.Hidden) && !di.Attributes.HasFlag(FileAttributes.System))
                        {
                            ImageSource fileGlyph = ImagesProvider?.GetFileIcon(file);
                            string      fileName  = Path.GetFileName(file);
                            completions.Add(new RCompletion(fileName, fileName, string.Empty, fileGlyph));
                        }
                    }
                }
            } catch (IOException) { } catch (UnauthorizedAccessException) { }

            return(completions);
        }
Exemple #15
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();
            ImageSource        glyph       = GlyphService.GetGlyph(StandardGlyphGroup.GlyphLibrary, StandardGlyphItem.GlyphItemPublic);

            IEnumerable <IPackageInfo> packages = PackageIndex.Packages;

            foreach (var packageInfo in packages)
            {
                completions.Add(new RCompletion(packageInfo.Name, packageInfo.Name, packageInfo.Description, glyph));
            }

            return(completions);
        }
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.Name.Text != "\"$schema\"")
            {
                yield break;
            }

            string value = "http://json-schema.org/draft-04/schema#";

            yield return(new JSONCompletionEntry(value, "\"" + value + "\"", "JSON hyper-schema draft v4",
                                                 GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic),
                                                 "iconAutomationText", true, context.Session as ICompletionSession));
        }
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();
            var infoSource = _snippetInformationSource?.InformationSource;

            if (!context.IsInNameSpace() && infoSource != null)
            {
                ImageSource snippetGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic, _shell);
                foreach (ISnippetInfo info in infoSource.Snippets)
                {
                    completions.Add(new RCompletion(info.Name, info.Name, info.Description, snippetGlyph));
                }
            }
            return(completions);
        }
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();
            var infoSource = SnippetInformationSource?.InformationSource;

            if (!context.IsInNameSpace() && infoSource != null)
            {
                ImageSource snippetGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic);
                foreach (string name in infoSource.SnippetNames)
                {
                    completions.Add(new RCompletion(name, name, string.Empty, snippetGlyph));
                }
            }
            return(completions);
        }
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || !member.Name.Text.Trim('"').StartsWith("$"))
            {
                yield break;
            }

            foreach (string prop in _props.Keys)
            {
                yield return(new JSONCompletionEntry(prop, "\"" + prop + "\"", _props[prop],
                                                     GlyphService.GetGlyph(StandardGlyphGroup.GlyphReference, StandardGlyphItem.GlyphItemPublic),
                                                     "iconAutomationText", true, context.Session as ICompletionSession));
            }
        }
        public IList <HtmlCompletion> GetEntries(HtmlCompletionContext context)
        {
            var result = new List <HtmlCompletion>();
            var list   = new List <string>();
            var glyph  = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic);

            context.Document.HtmlEditorTree.RootNode.Accept(this, list);

            foreach (var item in list)
            {
                var completion = new HtmlCompletion(item, item, item, glyph, HtmlIconAutomationText.AttributeIconText);
                result.Add(completion);
            }

            return(result);
        }
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.Name.Text != "\"$schema\"")
            {
                yield break;
            }

            foreach (var schema in VsJSONSchemaStore.SchemaStore.SchemaCache.Entries)
            {
                yield return(new JSONCompletionEntry(schema.OriginalPath, "\"" + schema.OriginalPath + "\"", null,
                                                     GlyphService.GetGlyph(StandardGlyphGroup.GlyphReference, StandardGlyphItem.GlyphItemPublic),
                                                     "iconAutomationText", true, context.Session as ICompletionSession));
            }
        }
Exemple #22
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.Name.Text != "\"@context\"")
            {
                yield break;
            }

            var vocabularies = VocabularyFactory.GetAllVocabularies();

            foreach (IVocabulary vocabulary in vocabularies)
            {
                yield return(new JSONCompletionEntry(vocabulary.DisplayName, "\"" + vocabulary.DisplayName + "\"", null,
                                                     GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic),
                                                     "iconAutomationText", true, context.Session as ICompletionSession));
            }
        }
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();
            FunctionCall       funcCall;
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupValueType, StandardGlyphItem.GlyphItemPublic, _shell);

            // Safety checks
            if (!ShouldProvideCompletions(context, out funcCall))
            {
                return(completions);
            }

            // Get collection of function signatures from documentation (parsed RD file)
            IFunctionInfo functionInfo = GetFunctionInfo(context);

            if (functionInfo == null)
            {
                return(completions);
            }

            // Collect parameter names from all signatures
            IEnumerable <KeyValuePair <string, IArgumentInfo> > arguments = new Dictionary <string, IArgumentInfo>();

            foreach (ISignatureInfo signature in functionInfo.Signatures)
            {
                var args = signature.Arguments.ToDictionary(x => x.Name);
                arguments = arguments.Union(args);
            }

            // Add names of arguments that  are not yet specified to the completion
            // list with '=' sign so user can tell them from function names.
            IEnumerable <string> declaredArguments = funcCall.Arguments.Where(x => x is NamedArgument).Select(x => ((NamedArgument)x).Name);
            var possibleArguments = arguments.Where(x => !x.Key.EqualsOrdinal("...") && !declaredArguments.Contains(x.Key, StringComparer.OrdinalIgnoreCase));

            foreach (var arg in possibleArguments)
            {
                string displayText   = arg.Key + " =";
                string insertionText = arg.Key + " = ";
                completions.Add(new RCompletion(displayText, insertionText, arg.Value.Description, functionGlyph));
            }

            return(completions);
        }
Exemple #24
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();
            ImageSource        folderGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphClosedFolder, StandardGlyphItem.GlyphItemPublic);
            string             currentDir  = RToolsSettings.Current.WorkingDirectory;
            string             directory   = null;

            try {
                string dir = Path.Combine(currentDir, _directory);
                if (Directory.Exists(dir))
                {
                    directory = dir;
                }
            } catch (IOException) { } catch (UnauthorizedAccessException) { } catch (ArgumentException) { }

            if (directory != null)
            {
                try {
                    foreach (string dir in Directory.GetDirectories(directory))
                    {
                        DirectoryInfo di = new DirectoryInfo(dir);
                        if (!di.Attributes.HasFlag(FileAttributes.Hidden) && !di.Attributes.HasFlag(FileAttributes.System))
                        {
                            string dirName = Path.GetFileName(dir);
                            completions.Add(new RCompletion(dirName, dirName + "/", string.Empty, folderGlyph));
                        }
                    }

                    foreach (string file in Directory.GetFiles(directory))
                    {
                        FileInfo di = new FileInfo(file);
                        if (!di.Attributes.HasFlag(FileAttributes.Hidden) && !di.Attributes.HasFlag(FileAttributes.System))
                        {
                            ImageSource fileGlyph = ImagesProvider?.GetFileIcon(file);
                            string      fileName  = Path.GetFileName(file);
                            completions.Add(new RCompletion(fileName, fileName, string.Empty, fileGlyph));
                        }
                    }
                } catch (IOException) { } catch (UnauthorizedAccessException) { }
            }

            return(completions);
        }
Exemple #25
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.Name.Text != "\"@type\"")
            {
                yield break;
            }


            foreach (IVocabulary vocabulary in VocabularyFactory.GetVocabularies(member))
            {
                foreach (string key in vocabulary.Cache.Keys)
                {
                    yield return(new JSONCompletionEntry(key, "\"" + key + "\"", null,
                                                         GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic),
                                                         "iconAutomationText", true, context.Session as ICompletionSession));
                }
            }
        }
Exemple #26
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic, _shell);
            ImageSource        constantGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupConstant, StandardGlyphItem.GlyphItemPublic, _shell);
            ImageSource        snippetGlyph  = GlyphService.GetGlyph(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic, _shell);
            var infoSource = _snippetInformationSource?.InformationSource;

            // TODO: this is different in the console window where
            // packages may have been loaded from the command line.
            // We need an extensibility point here.
            IEnumerable <IPackageInfo> packages = GetPackages(context);

            // Get list of functions in the package
            foreach (IPackageInfo pkg in packages)
            {
                Debug.Assert(pkg != null);

                IEnumerable <INamedItemInfo> functions = pkg.Functions;
                if (functions != null)
                {
                    foreach (INamedItemInfo function in functions)
                    {
                        bool isSnippet = false;
                        // Snippets are suppressed if user typed namespace
                        if (!context.IsInNameSpace() && infoSource != null)
                        {
                            isSnippet = infoSource.IsSnippet(function.Name);
                        }
                        if (!isSnippet)
                        {
                            ImageSource glyph      = function.ItemType == NamedItemType.Constant ? constantGlyph : functionGlyph;
                            var         completion = new RFunctionCompletion(function.Name, CompletionUtilities.BacktickName(function.Name), function.Description, glyph, _functionIndex, context.Session);
                            completions.Add(completion);
                        }
                    }
                }
            }

            return(completions);
        }
Exemple #27
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic);
            ImageSource        variableGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic);

            var ast   = context.AstRoot;
            var scope = ast.GetNodeOfTypeFromPosition <IScope>(context.Position);

            var variables = scope.GetApplicableVariables(context.Position);

            foreach (var v in variables)
            {
                RCompletion completion;
                RFunction   f = v.Value as RFunction;
                completion = new RCompletion(v.Name, CompletionUtilities.BacktickName(v.Name), string.Empty, f != null ? functionGlyph : variableGlyph);
                completions.Add(completion);
            }

            return(completions);
        }
Exemple #28
0
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic);
            ImageSource        variableGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic);
            Selector           selector      = Selector.Dollar;

            string variableName = RCompletionContext.GetVariableName(context.Session.TextView, context.TextBuffer.CurrentSnapshot);

            if (variableName.IndexOfAny(new char[] { '$', '@' }) < 0)
            {
                variableName = string.Empty;
                selector     = Selector.None;
            }
            else if (variableName.EndsWith("@", StringComparison.Ordinal))
            {
                selector = Selector.At;
            }

            VariablesProvider.Initialize();
            int memberCount = VariablesProvider.GetMemberCount(variableName);
            IReadOnlyCollection <INamedItemInfo> members = VariablesProvider.GetMembers(variableName, 200);
            var filteredList = FilterList(members, selector);

            // Get list of functions in the package
            foreach (INamedItemInfo v in filteredList)
            {
                Debug.Assert(v != null);

                if (v.Name.Length > 0 && v.Name[0] != '[')
                {
                    ImageSource glyph      = v.ItemType == NamedItemType.Variable ? variableGlyph : functionGlyph;
                    var         completion = new RCompletion(v.Name, CompletionUtilities.BacktickName(v.Name), v.Description, glyph);
                    completions.Add(completion);
                }
            }

            return(completions);
        }
Exemple #29
0
        public async Task R_SnippetsCompletion01()
        {
            using (var script = await _editorHost.StartScript(_exportProvider, RContentTypeDefinition.ContentType)) {
                script.DoIdle(100);
                script.Type("whil");
                script.DoIdle(300);

                UIThreadHelper.Instance.Invoke(() => {
                    var session = script.GetCompletionSession();
                    session.Should().NotBeNull();

                    var infoSourceProvider = _exportProvider.GetExportedValue <ISnippetInformationSourceProvider>();
                    var infoSource         = infoSourceProvider.InformationSource;
                    var completion         = session.SelectedCompletionSet.SelectionStatus.Completion;

                    bool isSnippet = infoSource.IsSnippet(completion.DisplayText);
                    isSnippet.Should().BeTrue();

                    var glyph        = completion.IconSource;
                    var snippetGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic, _exportProvider.GetExportedValue <ICoreShell>());
                    glyph.Should().Be(snippetGlyph);
                });
            }
        }
Exemple #30
0
        public void R_SnippetsCompletion01()
        {
            using (var script = new TestScript(RContentTypeDefinition.ContentType)) {
                script.DoIdle(100);
                script.Type("whil");
                script.DoIdle(300);

                EditorShell.Current.DispatchOnUIThread(() => {
                    var session = script.GetCompletionSession();
                    session.Should().NotBeNull();

                    var infoSourceProvider = EditorShell.Current.ExportProvider.GetExportedValue <ISnippetInformationSourceProvider>();
                    var infoSource         = infoSourceProvider.InformationSource;
                    var completion         = session.SelectedCompletionSet.SelectionStatus.Completion;

                    bool isSnippet = infoSource.IsSnippet(completion.DisplayText);
                    isSnippet.Should().BeTrue();

                    var glyph        = completion.IconSource;
                    var snippetGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic);
                    glyph.Should().Be(snippetGlyph);
                });
            }
        }