Exemple #1
0
        public static RepresentativeEx GetRepresentativeContactInfoByUdl(string number, string series)
        {
            var representative = IntellisenseController.GetRepresentativeContactInfoByUdl(number, series);

            if (representative != null)
            {
                // связано с ошибками сериализации через JavaScriptSerializer
                return(new RepresentativeEx(representative));
            }

            return(null);
        }
Exemple #2
0
        public IIntellisenseController TryCreateIntellisenseController(ITextView textView, IList <ITextBuffer> subjectBuffers)
        {
            IntellisenseController controller;

            if (!textView.Properties.TryGetProperty(typeof(IntellisenseController), out controller))
            {
                controller = new IntellisenseController(this, textView, _ServiceProvider);
            }

            var analyzer = textView.GetAnalyzer();

            if (analyzer != null)
            {
                var buffer = subjectBuffers[0];
                if (_PublicFunctionProvider != null)
                {
                    _PublicFunctionProvider.SetFilename(buffer.GetFilePath());
                }
                if (_DatabaseInfoProvider != null)
                {
                    _DatabaseInfoProvider.SetFilename(buffer.GetFilePath());
                }
                if (_ProgramFileProvider != null)
                {
                    if (VSGeneroPackage.Instance.ProgramFileProvider == null)
                    {
                        VSGeneroPackage.Instance.ProgramFileProvider = _ProgramFileProvider;
                    }
                }

                var entry = analyzer.MonitorTextBuffer(textView, buffer);
                _hookedCloseEvents[textView] = Tuple.Create(entry.BufferParser, analyzer);
                textView.Closed += TextView_Closed;

                for (int i = 1; i < subjectBuffers.Count; i++)
                {
                    entry.BufferParser.AddBuffer(subjectBuffers[i]);
                }
                controller.SetBufferParser(entry.BufferParser);
            }
            return(controller);
        }
Exemple #3
0
        public override void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (session == null || completionSets == null)
            {
                return;
            }

            ITrackingPoint triggerPoint = session.GetTriggerPoint(TextBuffer);

            if (triggerPoint != null)
            {
                IntellisenseController controller     = GetControllerForView(session.TextView);
                CompletionInfo         completionInfo = controller.CompletionInfo;
                ITextSnapshot          snapshot       = triggerPoint.TextBuffer.CurrentSnapshot;
                SnapshotPoint          point          = triggerPoint.GetPoint(snapshot);
                bool extendLeft = false;
                bool extend     = true;

                // labels includes both implicit and explicit labels
                var labels = FindLabelsInScope(point);

                IntellisenseInvocationType invocationType = completionInfo.InvocationType;
                CompletionInfoType         infoType       = completionInfo.InfoType;

                switch (invocationType)
                {
                case IntellisenseInvocationType.Default:
                    extend = infoType == CompletionInfoType.GlobalInfo;
                    break;

                case IntellisenseInvocationType.BackspaceDeleteOrBackTab:
                case IntellisenseInvocationType.IdentifierChar:
                case IntellisenseInvocationType.Sharp:
                case IntellisenseInvocationType.Space:
                case IntellisenseInvocationType.ShowMemberList:
                    break;

                default:
                    extendLeft = true;
                    break;
                }

                TextExtent extentOfWord = default(TextExtent);
                if (extend)
                {
                    ITextBuffer             textBuffer      = TextBuffer;
                    ITextStructureNavigator navigator       = TextStructureNavigatorSelectorService.CreateTextStructureNavigator(textBuffer, textBuffer.ContentType);
                    SnapshotPoint           currentPosition = new SnapshotPoint(snapshot, triggerPoint.GetPosition(snapshot));
                    extentOfWord = navigator.GetExtentOfWord(currentPosition);
                    if (extentOfWord.Span.Start == point)
                    {
                        TextExtent extentOfPreviousWord = navigator.GetExtentOfWord(currentPosition - 1);
                        if (extentOfPreviousWord.IsSignificant && extentOfPreviousWord.Span.End == point && IsCompletionPrefix(extentOfPreviousWord))
                        {
                            extentOfWord = extentOfPreviousWord;
                        }
                        else
                        {
                            extend = false;
                        }
                    }
                }

                if (!extend || !extentOfWord.IsSignificant)
                {
                    SnapshotSpan span = new SnapshotSpan(point, 0);
                    extentOfWord = new TextExtent(span, false);
                }

                if (invocationType == IntellisenseInvocationType.BackspaceDeleteOrBackTab && extentOfWord.Span.Length > 0)
                {
                    string str3 = snapshot.GetText(extentOfWord.Span);
                    if (!string.IsNullOrWhiteSpace(str3))
                    {
                        while (CommitCharacters.IndexOf(str3[0]) > 0)
                        {
                            SnapshotSpan span2 = extentOfWord.Span;
                            SnapshotSpan span3 = new SnapshotSpan(snapshot, span2.Start + 1, span2.Length - 1);
                            extentOfWord = new TextExtent(span3, false);
                            str3         = snapshot.GetText(extentOfWord.Span);
                            if (string.IsNullOrEmpty(str3))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        SnapshotSpan span4 = new SnapshotSpan(snapshot, extentOfWord.Span.End, 0);
                        extentOfWord = new TextExtent(span4, false);
                        completionInfo.InvocationType = IntellisenseInvocationType.Default;
                    }
                }

                if (completionInfo.InfoType == CompletionInfoType.AutoListMemberInfo && extentOfWord.Span.GetText().StartsWith("$") && labels.Count == 0)
                {
                    session.Dismiss();
                    return;
                }

                ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extentOfWord.Span, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
                if (extendLeft)
                {
                    SnapshotSpan textSoFarSpan = new SnapshotSpan(snapshot, extentOfWord.Span.Start, triggerPoint.GetPoint(snapshot));
                    string       textSoFar     = textSoFarSpan.GetText();
                    applicableTo = snapshot.CreateTrackingSpan(point.Position - textSoFar.Length, textSoFar.Length, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
                }

                IEnumerable <Completion> context          = GetContextCompletions(triggerPoint.GetPoint(snapshot), (AntlrIntellisenseController)controller, session);
                IEnumerable <Completion> keywords         = GetKeywordCompletions();
                IEnumerable <Completion> snippets         = GetSnippetCompletions();
                IEnumerable <Completion> labelCompletions = GetLabelCompletions(labels);
                //SnapshotSpan? Provider.IntellisenseCache.GetExpressionSpan(triggerPoint.GetPoint(snapshot));

                IEnumerable <Completion> completions        = context.Concat(keywords).Concat(snippets).Concat(labelCompletions);
                IEnumerable <Completion> orderedCompletions = completions.Distinct(CompletionDisplayNameComparer.CurrentCulture).OrderBy(i => i.DisplayText, StringComparer.CurrentCultureIgnoreCase);

                CompletionSet completionSet = new CompletionSet("AntlrCompletions", "Antlr Completions", applicableTo, orderedCompletions, EmptyCompletions);
                completionSets.Add(completionSet);
            }
        }
        public override void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (session == null || completionSets == null)
            {
                return;
            }

            ITrackingPoint triggerPoint = session.GetTriggerPoint(TextBuffer);

            if (triggerPoint != null)
            {
                IntellisenseController controller     = null;
                CompletionInfo         completionInfo = controller.CompletionInfo;
                ITextSnapshot          snapshot       = triggerPoint.TextBuffer.CurrentSnapshot;
                SnapshotPoint          point          = triggerPoint.GetPoint(snapshot);
                bool extendLeft = false;
                bool extend     = true;

                switch (completionInfo.InvocationType)
                {
                case IntellisenseInvocationType.Default:
                    extend = completionInfo.InfoType == CompletionInfoType.GlobalInfo;
                    break;

                case IntellisenseInvocationType.BackspaceDeleteOrBackTab:
                case IntellisenseInvocationType.IdentifierChar:
                case IntellisenseInvocationType.Sharp:
                case IntellisenseInvocationType.Space:
                case IntellisenseInvocationType.ShowMemberList:
                    break;

                default:
                    extendLeft = true;
                    break;
                }

                TextExtent extentOfWord = default(TextExtent);
                if (extend)
                {
                    ITextBuffer             textBuffer      = TextBuffer;
                    ITextStructureNavigator navigator       = TextStructureNavigatorSelectorService.CreateTextStructureNavigator(textBuffer, textBuffer.ContentType);
                    SnapshotPoint           currentPosition = new SnapshotPoint(snapshot, triggerPoint.GetPosition(snapshot));
                    extentOfWord = navigator.GetExtentOfWord(currentPosition);
                    if (extentOfWord.Span.Start == point)
                    {
                        TextExtent extentOfPreviousWord = navigator.GetExtentOfWord(currentPosition - 1);
                        if (extentOfPreviousWord.IsSignificant && extentOfPreviousWord.Span.End == point && IsCompletionPrefix(extentOfPreviousWord))
                        {
                            extentOfWord = extentOfPreviousWord;
                        }
                        else
                        {
                            extend = false;
                        }
                    }
                }

                if (!extend || !extentOfWord.IsSignificant)
                {
                    SnapshotSpan span = new SnapshotSpan(point, 0);
                    extentOfWord = new TextExtent(span, false);
                }

                if (completionInfo.InvocationType == IntellisenseInvocationType.BackspaceDeleteOrBackTab && extentOfWord.Span.Length > 0)
                {
                    string str3 = snapshot.GetText(extentOfWord.Span);
                    if (!string.IsNullOrWhiteSpace(str3))
                    {
                        while (CommitCharacters.IndexOf(str3[0]) > 0)
                        {
                            SnapshotSpan span2 = extentOfWord.Span;
                            SnapshotSpan span3 = new SnapshotSpan(snapshot, span2.Start + 1, span2.Length - 1);
                            extentOfWord = new TextExtent(span3, false);
                            str3         = snapshot.GetText(extentOfWord.Span);
                            if (string.IsNullOrEmpty(str3))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        SnapshotSpan span4 = new SnapshotSpan(snapshot, extentOfWord.Span.End, 0);
                        extentOfWord = new TextExtent(span4, false);
                        completionInfo.InvocationType = IntellisenseInvocationType.Default;
                    }
                }

                ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(extentOfWord.Span, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
                if (extendLeft)
                {
                    SnapshotSpan textSoFarSpan = new SnapshotSpan(snapshot, extentOfWord.Span.Start, triggerPoint.GetPoint(snapshot));
                    string       textSoFar     = textSoFarSpan.GetText();
                    applicableTo = snapshot.CreateTrackingSpan(point.Position - textSoFar.Length, textSoFar.Length, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
                }

                /* Context Tree
                 *
                 *  - Global
                 *    - Options
                 *    - Tokens
                 *    - AttributeScope
                 *      - ACTION
                 *    - Named Action
                 *      - ACTION
                 *    - Rule
                 *      - Arguments
                 *        - ARG_ACTION
                 *      - AttributeScope
                 *        - ACTION
                 *      - Named Action
                 *        - ACTION
                 *      - Options
                 *      - Alternative
                 *        - Alternative*
                 *        - Rewrite
                 *        - ACTION
                 */

                List <Completion> completions        = new List <Completion>();
                List <Completion> completionBuilders = new List <Completion>();

                List <IntellisenseContext> intellisenseContexts = GetIntellisenseContexts(triggerPoint);
                foreach (var context in intellisenseContexts)
                {
                    context.AugmentCompletionSession(session, completions, completionBuilders);
                }

                string        moniker       = "AntlrCompletions";
                string        displayName   = "ANTLR Completions";
                CompletionSet completionSet = new CompletionSet(moniker, displayName, applicableTo, completions, completionBuilders);
                completionSets.Add(completionSet);
            }
        }
Exemple #5
0
        /// <summary>
        /// Called from VS when we should handle a command or pass it on.
        /// </summary>
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (IntellisenseControllerProvider.Instance != null &&
                IntellisenseControllerProvider.Instance.GeneroCommandTarget != null &&
                pguidCmdGroup == IntellisenseControllerProvider.Instance.GeneroCommandTarget.PackageGuid)
            {
                if (_textView != null && _textView.TextBuffer != null)
                {
                    string path = _textView.TextBuffer.GetFilePath();
                    if (IntellisenseControllerProvider.Instance.GeneroCommandTarget.Exec(path, nCmdID))
                    {
                        return(VSConstants.S_OK);
                    }
                }
            }

            // preprocessing
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                switch ((VSConstants.VSStd97CmdID)nCmdID)
                {
                case VSConstants.VSStd97CmdID.Paste:
                    //PythonReplEvaluator eval;
                    //if (_textView.Properties.TryGetProperty(typeof(PythonReplEvaluator), out eval))
                    //{
                    //    string pasting = eval.FormatClipboard() ?? Clipboard.GetText();
                    //    if (pasting != null)
                    //    {
                    //        PasteReplCode(eval, pasting);

                    //        return VSConstants.S_OK;
                    //    }
                    //}
                    //else
                    //{
                    //    string updated = RemoveReplPrompts(_textView.Options.GetNewLineCharacter());
                    //    if (updated != null)
                    //    {
                    //        _editorOps.ReplaceSelection(updated);
                    //        return VSConstants.S_OK;
                    //    }
                    //}
                    break;

                case VSConstants.VSStd97CmdID.GotoDefn: return(GotoDefinition());

                case VSConstants.VSStd97CmdID.FindReferences: return(FindAllReferences());
                }
            }
            else if (pguidCmdGroup == VSGeneroConstants.Std2KCmdGroupGuid)
            {
                OutliningTaggerProvider.OutliningTagger tagger;
                IntellisenseController controller = null;

                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case (VSConstants.VSStd2KCmdID) 147:    // ECMD_SMARTTASKS  defined in stdidcmd.h, but not in MPF
                    // if the user is typing to fast for us to update the smart tags on the idle event
                    // then we want to update them before VS pops them up.
                    UpdateSmartTags();
                    break;

                //case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
                //    FormatCode(new SnapshotSpan(_textView.TextBuffer.CurrentSnapshot, 0, _textView.TextBuffer.CurrentSnapshot.Length), false);
                //    return VSConstants.S_OK;
                case VSConstants.VSStd2KCmdID.FORMATSELECTION:
                    if (_textView != null)
                    {
                        FormatCode(_textView.Selection.StreamSelectionSpan.SnapshotSpan, true);
                    }
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                    if (_textView != null)
                    {
                        controller =
                            _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));

                        if (controller != null)
                        {
                            IntellisenseController.ForceCompletions = true;
                            try
                            {
                                controller.TriggerCompletionSession((VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.COMPLETEWORD,
                                                                    (VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.SHOWMEMBERLIST);
                            }
                            finally
                            {
                                IntellisenseController.ForceCompletions = false;
                            }
                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd2KCmdID.QUICKINFO:
                    if (_textView != null)
                    {
                        controller =
                            _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                        if (controller != null)
                        {
                            controller.TriggerQuickInfo();
                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd2KCmdID.PARAMINFO:
                    if (_textView != null)
                    {
                        controller =
                            _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                        if (controller != null)
                        {
                            controller.TriggerSignatureHelp();
                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL:
                    tagger = _textView.GetOutliningTagger();
                    tagger?.Disable();
                    // let VS get the event as well
                    break;

                case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING:
                    tagger = _textView.GetOutliningTagger();
                    tagger?.Enable();
                    // let VS get the event as well
                    break;

                case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                    if (VSGenero.EditorExtensions.EditorExtensions.CommentOrUncommentBlock(_textView, comment: true))
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                    if (VSGenero.EditorExtensions.EditorExtensions.CommentOrUncommentBlock(_textView, comment: false))
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.EXTRACTMETHOD:
                    ExtractMethod();
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.RENAME:
                    RefactorRename();
                    return(VSConstants.S_OK);
                }
            }

            try
            {
                return(_next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            catch (Exception ex)
            {
                return(VSConstants.S_FALSE);
            }
        }
Exemple #6
0
 public static List <string> GetMiddleNameAutoComplete(string prefixText, int count, string contextKey)
 {
     return(IntellisenseController.GetMiddleNameAutoComplete(prefixText, count, contextKey));
 }
Exemple #7
0
 public static List <string> GetKladrList(string prefixText, int count, string contextKey)
 {
     return(IntellisenseController.GetKladrList(prefixText, count, contextKey));
 }
Exemple #8
0
 public static List <string> GetFirstNameAutoComplete(string prefixText, int count)
 {
     return(IntellisenseController.GetFirstNameAutoComplete(prefixText, count));
 }