Esempio n. 1
0
 /// <summary>
 /// Called before character type is passed down to the core editor
 /// along the controll chain. Gives language-specific controller
 /// a chance to initiate different action and potentially 'eat'
 /// the character. For example, in R typing 'abc[TAB] should bring
 /// up intellisense list rather than actually insert the tab character.
 /// </summary>
 /// <returns>
 /// True if character was handled and should not be
 /// passed down to core editor or false otherwise.
 /// </returns>
 public override bool OnPreTypeChar(char typedCharacter)
 {
     // Allow tab to bring intellisense if
     //  a) REditorSettings.ShowCompletionOnTab true
     //  b) Position is at the end of a string so we bring completion for files
     //  c) There is no selection
     if (typedCharacter == '\t' && !HasActiveCompletionSession && TextView.Selection.StreamSelectionSpan.Length == 0)
     {
         // if previous character is identifier character, bring completion list
         SnapshotPoint?position = REditorDocument.MapCaretPositionFromView(TextView);
         if (position.HasValue)
         {
             int pos = position.Value;
             if (pos > 0 && pos <= position.Value.Snapshot.Length)
             {
                 bool endOfIdentifier = RTokenizer.IsIdentifierCharacter(position.Value.Snapshot[pos - 1]);
                 bool showCompletion  = endOfIdentifier && REditorSettings.ShowCompletionOnTab;
                 if (!showCompletion)
                 {
                     var    document = REditorDocument.FromTextBuffer(position.Value.Snapshot.TextBuffer);
                     string directory;
                     showCompletion = RCompletionEngine.CanShowFileCompletion(document.EditorTree.AstRoot, pos, out directory);
                 }
                 if (showCompletion)
                 {
                     ShowCompletion(autoShownCompletion: false);
                     return(true); // eat the character
                 }
             }
         }
     }
     return(base.OnPreTypeChar(typedCharacter));
 }
Esempio n. 2
0
        /// <summary>
        /// Populates R completion list for a given position
        /// </summary>
        /// <param name="position">Position in R text buffer</param>
        /// <param name="session">Completion session</param>
        /// <param name="completionSets">Completion sets to add to</param>
        /// <param name="ast">Document abstract syntax tree</param>
        internal void PopulateCompletionList(int position, ICompletionSession session, IList <CompletionSet> completionSets, AstRoot ast)
        {
            RCompletionContext context = new RCompletionContext(session, _textBuffer, ast, position);

            bool autoShownCompletion = true;

            if (session.TextView.Properties.ContainsProperty(CompletionController.AutoShownCompletion))
            {
                autoShownCompletion = session.TextView.Properties.GetProperty <bool>(CompletionController.AutoShownCompletion);
            }

            IReadOnlyCollection <IRCompletionListProvider> providers =
                RCompletionEngine.GetCompletionForLocation(context, autoShownCompletion);

            // Position is in R as is the applicable spa, so no need to map down
            Span?applicableSpan = GetApplicableSpan(position, session);

            if (applicableSpan.HasValue)
            {
                ITrackingSpan      trackingSpan = context.TextBuffer.CurrentSnapshot.CreateTrackingSpan(applicableSpan.Value, SpanTrackingMode.EdgeInclusive);
                List <RCompletion> completions  = new List <RCompletion>();
                bool sort = true;

                foreach (IRCompletionListProvider provider in providers)
                {
                    IReadOnlyCollection <RCompletion> entries = provider.GetEntries(context);
                    Debug.Assert(entries != null);

                    if (entries.Count > 0)
                    {
                        completions.AddRange(entries);
                    }
                    sort &= provider.AllowSorting;
                }

                if (sort)
                {
                    completions.Sort(RCompletion.Compare);
                    completions.RemoveDuplicates();
                }

                CompletionSet completionSet = new RCompletionSet(session.TextView.TextBuffer, trackingSpan, completions);
                completionSets.Add(completionSet);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Called before character type is passed down to the core editor
        /// along the controll chain. Gives language-specific controller
        /// a chance to initiate different action and potentially 'eat'
        /// the character. For example, in R typing 'abc[TAB] should bring
        /// up intellisense list rather than actually insert the tab character.
        /// </summary>
        /// <returns>
        /// True if character was handled and should not be
        /// passed down to core editor or false otherwise.
        /// </returns>
        public override bool OnPreTypeChar(char typedCharacter)
        {
            // Allow tab to bring intellisense if
            //  a) REditorSettings.ShowCompletionOnTab true
            //  b) Position is at the end of a string so we bring completion for files
            //  c) There is no selection
            if (typedCharacter == '\t' && !HasActiveCompletionSession && TextView.Selection.StreamSelectionSpan.Length == 0)
            {
                // if previous character is identifier character, bring completion list
                var position = TextView.GetCaretPosition(_textBuffer);
                if (position.HasValue)
                {
                    int pos      = position.Value;
                    var document = position.Value.Snapshot.TextBuffer.GetEditorDocument <IREditorDocument>();
                    if (!document.IsPositionInComment(pos))
                    {
                        if (pos > 0 && pos <= position.Value.Snapshot.Length)
                        {
                            var endOfIdentifier = RTokenizer.IsIdentifierCharacter(position.Value.Snapshot[pos - 1]);
                            var showCompletion  = endOfIdentifier && _settings.ShowCompletionOnTab;
                            if (!showCompletion)
                            {
                                showCompletion = RCompletionEngine.CanShowFileCompletion(document.EditorTree.AstRoot, pos, out string directory);
                            }
                            if (showCompletion)
                            {
                                ShowCompletion(autoShownCompletion: false);
                                return(true); // eat the character
                            }
                        }
                    }
                }
            }
            else if (typedCharacter == '#')
            {
                if (TryInsertRoxygenBlock())
                {
                    return(true);
                }
            }

            return(base.OnPreTypeChar(typedCharacter));
        }
Esempio n. 4
0
        public REditorDocument(ITextBuffer textBuffer)
        {
            _textDocumentFactoryService = EditorShell.Current.ExportProvider.GetExportedValue <ITextDocumentFactoryService>();
            _textDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            this.TextBuffer = textBuffer;
            IsClosed        = false;

            ServiceManager.AddService <REditorDocument>(this, TextBuffer);

            _editorTree = new EditorTree(textBuffer);
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(this.EditorTree);
            }

            _editorTree.Build();
            RCompletionEngine.Initialize();
        }
Esempio n. 5
0
        public REditorDocument(ITextBuffer textBuffer)
        {
            EditorShell.Current.CompositionService.SatisfyImportsOnce(this);

            this.TextBuffer = textBuffer;

            IsClosed = false;
            TextDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            ServiceManager.AddService <REditorDocument>(this, TextBuffer);

            _editorTree = new EditorTree(textBuffer);
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(this.EditorTree);
            }

            _editorTree.Build();

            RCompletionEngine.Initialize();
        }
Esempio n. 6
0
 public CompletionManager(IServiceContainer services)
 {
     _services         = services;
     _completionEngine = new RCompletionEngine(services);
 }
Esempio n. 7
0
 public RCompletionSource(ITextBuffer textBuffer, IServiceContainer services)
 {
     _textBuffer       = textBuffer;
     _services         = services;
     _completionEngine = new RCompletionEngine(services);
 }