Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AiClassifier"/> class.
        /// </summary>
        /// <param name="registry">Classification registry.</param>
        internal AiClassifier(ITextBuffer textBuffer, IClassificationTypeRegistryService classificationTypeRegistry)
        {
            // Save needed parameters
            _classificationTypeRegistry = classificationTypeRegistry;

            // Create parser object
            _aiParser = new AiParser();
        }
        /// <summary>
        /// Creates a new completion source.
        /// </summary>
        /// <param name="sourceProvider">The overall completion source provider (used to obtain other references).</param>
        /// <param name="textBuffer">The current text buffer.</param>
        public AiCompletionSource(AiCompletionSourceProvider sourceProvider, ITextBuffer textBuffer)
        {
            // Store parameters
            _sourceProvider = sourceProvider;
            _textBuffer     = textBuffer;

            // Create parser object
            _aiParser = new AiParser();

            // Initialize top level keyword completions
            ImageSource keywordCompletionIcon = _sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupClass, StandardGlyphItem.GlyphItemPublic);

            _aiTopLevelKeywordCompletions = new[]
            {
                new Microsoft.VisualStudio.Language.Intellisense.Completion("defconst", "defconst", "Constant", keywordCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("defrule", "defrule", "Rule", keywordCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("load", "load", "Load file", keywordCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("load-random", "load-random", "Load file with chance", keywordCompletionIcon, null),
            }.OrderBy(c => c.DisplayText);

            // Initialize fact completions
            ImageSource keywordFactCompletionIcon = _sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupField, StandardGlyphItem.GlyphItemPublic);
            ImageSource factCompletionIcon        = _sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic);
            var         keywordFactCompletions    = new[]
            {
                new Microsoft.VisualStudio.Language.Intellisense.Completion("or", "or", "Boolean OR operation", keywordFactCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("and", "and", "Boolean AND operation", keywordFactCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("xor", "xor", "Boolean XOR operation", keywordFactCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("nor", "nor", "Boolean NOR operation", keywordFactCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("nand", "nand", "Boolean NAND operation", keywordFactCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("xnor", "xnor", "Boolean XNOR operation", keywordFactCompletionIcon, null),
                new Microsoft.VisualStudio.Language.Intellisense.Completion("not", "not", "Boolean NOT operation", keywordFactCompletionIcon, null),
            };

            _aiFactCompletions = Constants.AiRuleFacts.Select
                                 (
                rf => new Microsoft.VisualStudio.Language.Intellisense.Completion(rf.Key, rf.Key, rf.Value.Description, factCompletionIcon, null)
                                 ).Union(keywordFactCompletions).OrderBy(c => c.DisplayText);

            // Initialize action completions
            ImageSource actionCompletionIcon = _sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic);

            _aiActionCompletions = Constants.AiRuleActions.Select
                                   (
                ra => new Microsoft.VisualStudio.Language.Intellisense.Completion(ra.Key, ra.Key, ra.Value.Description, actionCompletionIcon, null)
                                   ).OrderBy(c => c.DisplayText);

            // Initialize parameter completions
            ImageSource commandParameterCompletionIcon = _sourceProvider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupConstant, StandardGlyphItem.GlyphItemPublic);

            _aiCommandParameterCompletions = Constants.AiCommandParameters.ToDictionary
                                             (
                cp => cp.Key,
                cp => cp.Value.PossibleValues.Select(v => new Microsoft.VisualStudio.Language.Intellisense.Completion(v, v, v, commandParameterCompletionIcon, null))
                                             );
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new indentation object.
        /// </summary>
        /// <param name="textView">The current text view.</param>
        public AiSmartIndent(ITextView textView)
        {
            // Save parameters
            _textView = textView;

            // Get indentation options
            _useTabs    = _textView.Options.GetOptionValue(new EditorOptionKey <bool>("Tabs/ConvertTabsToSpaces"));
            _indentSize = _textView.Options.GetOptionValue(new EditorOptionKey <int>("Tabs/IndentSize"));

            // Create parser object
            _aiParser = new AiParser();
        }
        internal AiFormatCommandHandler(IVsTextView textViewAdapter, ITextView textView, AiFormatHandlerProvider provider)
        {
            // Save arguments
            _textView = textView;
            _provider = provider;

            // Create parser object
            _aiParser = new AiParser();

            // Add the command to the command chain
            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
        }