Exemple #1
0
        // This method is called after the string has been committed to the source buffer.
        /// <summary>
        /// Called after the declaration has been committed to the source file. When implemented in a derived class, it provides a completion character which may itself be a trigger for another round of IntelliSense.
        /// </summary>
        /// <param name="textView">[in] An <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextView"/> object representing the view that displays the source file.</param>
        /// <param name="committedText">[in] A string containing the text that was inserted as part of the completion process.</param>
        /// <param name="commitCharacter">[in] The character that was used to commit the text to the source file.</param>
        /// <param name="index">[in] The index of the item that was committed to the source file.</param>
        /// <returns>
        /// Returns a character to be inserted after the committed text. If nothing is to be inserted, returns 0.
        /// </returns>
        public override char OnAutoComplete(IVsTextView textView,
                                            string committedText,
                                            char commitCharacter,
                                            int index)
        {
/*
 *          // Do not replace when committed with \13 (enter)
 *          if (commitCharacter == 13)
 *              return '\0';
 */
            if (index < 0)
            {
                return('\0');
            }
            Declaration declaration = declarations[index];

            if (declaration != null)
            {
                // In this example, MyDeclaration identifies types with a string.
                // You can choose a different approach.
                if (declaration.DeclarationType == DeclarationType.Snippet)
                {
                    Source source = languageService.GetSource(textView);
                    if (source != null)
                    {
                        ExpansionProvider expansionProvider = source.GetExpansionProvider();
                        if (expansionProvider != null)
                        {
                            string title;
                            string path;
                            int    commitLength = commitSpan.iEndIndex - commitSpan.iStartIndex;
                            if (commitLength < committedText.Length)
                            {
                                // Replace everything that was inserted
                                // so calculate the span of the full
                                // insertion, taking into account what
                                // was inserted when the commitSpan
                                // was obtained in the first place.
                                commitSpan.iEndIndex += (committedText.Length - commitLength);
                            }

                            if (expansionProvider.FindExpansionByShortcut(textView,
                                                                          committedText,
                                                                          commitSpan,
                                                                          true,
                                                                          out title,
                                                                          out path) == 0)
                            {
                                expansionProvider.InsertNamedExpansion(textView,
                                                                       title,
                                                                       path,
                                                                       commitSpan,
                                                                       false);
                            }
                        }
                    }
                }
            }
            return('\0');
        }
Exemple #2
0
        public override bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (Guid.Equals(guidCmdGroup, Microsoft.VisualStudio.Shell.VsMenus.guidStandardCommandSet2K))
            {
                switch ((VSConstants.VSStd2KCmdID)nCmdId)
                {
                case VSStd2KCmdID.INSERTSNIPPET:
                {
                    ExpansionProvider ep = GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, "Insert snippet", type1, false, null, false);
                    }
                    return(true);
                }

                case VSStd2KCmdID.SURROUNDWITH:
                {
                    ExpansionProvider ep = GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, "Surround with", type2, false, null, false);
                    }
                }
                break;

                case VSStd2KCmdID.ECMD_LEFTCLICK:
                    Source.OnCommand(TextView, (VSConstants.VSStd2KCmdID)nCmdId, '\0');
                    break;
                }
            }
            return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut));
        }
        public override bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                if (nCmdId == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
                {
                    ExpansionProvider ep = this.GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(this.TextView, Resources.InsertSnippet, null, false, null, false);
                    }
                    return(true);   // Handled the command.
                }
                else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.SURROUNDWITH)
                {
                    ExpansionProvider ep = this.GetExpansionProvider();
                    if (this.TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(this.TextView, Resources.SurroundWith, null, false, null, false);
                    }
                    return(true);   // Handled the command.
                }
            }

            // Base class handled the command.  Do nothing more here.
            return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut));
        }
Exemple #4
0
 public override ExpansionFunction CreateExpansionFunction(
     ExpansionProvider provider, string functionName)
 {
     if (functionName == "ToCommandCase")
     {
         return(new ToCommandCaseExpansionFunction(provider));
     }
     return(base.CreateExpansionFunction(provider, functionName));
 }
Exemple #5
0
        public override ExpansionFunction CreateExpansionFunction(ExpansionProvider provider, string functionName)
        {
            ExpansionFunction function = null;

            if (functionName == "GetName")
            {
                ++classNameCounter;
                function = new PythonGetNameExpansionFunction(provider, classNameCounter);
            }
            return(function);
        }
Exemple #6
0
        // This method is called after the string has been committed to the source buffer.
        public override char OnAutoComplete(IVsTextView textView,
                                            string committedText,
                                            char commitCharacter,
                                            int index)
        {
            LuaDeclarations item = declarations[index] as LuaDeclarations;

            if (item != null)
            {
                // In this example, TestDeclaration identifies types with a string.
                // You can choose a different approach.
                if (item.GetType().Name == "snippet")
                {
                    Source src = languageService.GetSource(textView);
                    if (src != null)
                    {
                        ExpansionProvider ep = src.GetExpansionProvider();
                        if (ep != null)
                        {
                            string title;
                            string path;
                            int    commitLength = commitSpan.iEndIndex - commitSpan.iStartIndex;
                            if (commitLength < committedText.Length)
                            {
                                // Replace everything that was inserted
                                // so calculate the span of the full
                                // insertion, taking into account what
                                // was inserted when the commitSpan
                                // was obtained in the first place.
                                commitSpan.iEndIndex += (committedText.Length - commitLength);
                            }

                            if (ep.FindExpansionByShortcut(textView,
                                                           committedText,
                                                           commitSpan,
                                                           true,
                                                           out title,
                                                           out path) != 0)
                            {
                                ep.InsertNamedExpansion(textView,
                                                        title,
                                                        path,
                                                        commitSpan,
                                                        false);
                            }
                        }
                    }
                }
            }
            return('\0');
        }
Exemple #7
0
        //Source source = GetSource(req.FullName);
        public override ExpansionFunction CreateExpansionFunction(ExpansionProvider provider,
                                                                  string functionName)
        {
            ExpansionFunction function = null;

            if (String.Compare(functionName, "GetClassName", true) == 0)
            {
                function = new MyGetClassNameExpansionFunction(provider);
            }
            else if (String.Compare(functionName, "EnumAccessType", true) == 0)
            {
                function = new MyEnumAccessTypeExpansionFunction(provider);
            }
            return(function);
        }
Exemple #8
0
        // This method is called after the string has been committed to the source buffer.
        public override char OnAutoComplete(IVsTextView textView, string committedText, char commitCharacter, int index)
        {
            const char  defaultReturnValue = '\0';
            Declaration item = declarations[index] as Declaration;

            if (item == null)
            {
                return(defaultReturnValue);
            }
            // In this example, PythonDeclaration identifies types with an enum.
            // You can choose a different approach.
            if (item.Type != Declaration.DeclarationType.Snippet)
            {
                return(defaultReturnValue);
            }
            Source src = languageService.GetSource(textView);

            if (src == null)
            {
                return(defaultReturnValue);
            }
            ExpansionProvider ep = src.GetExpansionProvider();

            if (ep == null)
            {
                return(defaultReturnValue);
            }
            string title;
            string path;
            int    commitLength = commitSpan.iEndIndex - commitSpan.iStartIndex;

            if (commitLength < committedText.Length)
            {
                // Replace everything that was inserted so calculate the span of the full
                // insertion, taking into account what was inserted when the commitSpan
                // was obtained in the first place.
                commitSpan.iEndIndex += (committedText.Length - commitLength);
            }

            if (ep.FindExpansionByShortcut(textView, committedText, commitSpan,
                                           true, out title, out path) >= 0)
            {
                ep.InsertNamedExpansion(textView, title, path, commitSpan, false);
            }
            return(defaultReturnValue);
        }
        public override ExpansionFunction CreateExpansionFunction(ExpansionProvider provider, string functionName)
        {
            ExpansionFunction function = null;

            if (functionName == "ClassName")
            {
                function = new ClassNameExpansionFunction(provider, ++classcounter);
            }
            else if (functionName == "GenerateSwitchCases")
            {
                function = new GenerateSwitchCasesExpansionFunction(provider);
            }
            else if (functionName == "SimpleTypeName")
            {
                function = new SimpleTypeNameExpansionFunction(provider);
            }
            else if (functionName == "InitProcType")
            {
                function = new InitProcTypeExpansionFunction(provider);
            }

            return(function);
        }
Exemple #10
0
 public NameSpaceExpansionFunction(ExpansionProvider provider)
     : base(provider)
 {
 }
Exemple #11
0
 public MyEnumAccessTypeExpansionFunction(ExpansionProvider provider)
     : base(provider)
 {
 }
Exemple #12
0
 public MyGetClassNameExpansionFunction(ExpansionProvider provider)
     : base(provider)
 {
 }
Exemple #13
0
 internal ClassNameExpansionFunction(ExpansionProvider provider, int counter) : base(provider)
 {
     nameCount = counter;
 }
Exemple #14
0
 public virtual ExpansionFunction CreateExpansionFunction(ExpansionProvider provider, string functionName);
Exemple #15
0
 public PythonGetNameExpansionFunction(ExpansionProvider provider, int counter)
     : base(provider)
 {
     nameCount = counter;
 }
Exemple #16
0
 internal SimpleTypeNameExpansionFunction(ExpansionProvider provider) : base(provider)
 {
 }
Exemple #17
0
 public ToCommandCaseExpansionFunction(ExpansionProvider provider)
     : base(provider)
 {
 }
Exemple #18
0
 internal InitProcTypeExpansionFunction(ExpansionProvider provider) : base(provider)
 {
 }
Exemple #19
0
 internal GenerateSwitchCasesExpansionFunction(ExpansionProvider provider) : base(provider)
 {
 }
Exemple #20
0
        public override bool HandlePreExec(
            ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var cmd = (VsCommands2K)nCmdId;

            //// we're goona to erase some symbol from existence.
            //// In some cases we need to know what it was (auto-deletion of paired token)
            //if (cmd == VsCommands2K.BACKSPACE)
            //  Source.RememberCharBeforeCaret(TextView);
            //else
            //  Source.ClearRememberedChar();

            _startLine = -1;

            if (guidCmdGroup == VSConstants.VSStd2K)
            {
                if (Source.MethodData.IsDisplayed)
                {
                    TextView.GetCaretPos(out _startLine, out _startPos);
                }



                switch (cmd)
                {
                case VsCommands2K.COMPLETEWORD:
                {
                    int lintIndex;
                    int columnInxex;
                    ErrorHandler.ThrowOnFailure(TextView.GetCaretPos(out lintIndex, out columnInxex));
                    Source.Completion(TextView, lintIndex, columnInxex, false);
                    return(true);
                }

                case VsCommands2K.FORMATSELECTION:
                    ReformatSelection();
                    return(true);

                case VsCommands2K.INSERTSNIPPET:
                {
                    ExpansionProvider ep = GetExpansionProvider();

                    if (TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, Resources.InsertSnippet, null, false, null, false);
                    }

                    return(true);                                    // Handled the command.
                }

                case VsCommands2K.SURROUNDWITH:
                {
                    ExpansionProvider ep = GetExpansionProvider();

                    if (TextView != null && ep != null)
                    {
                        ep.DisplayExpansionBrowser(TextView, Resources.SurroundWith, null, false, null, false);
                    }

                    return(true);                                    // Handled the command.
                }

                case VsCommands2K.UP:
                    if (Source.MethodData.IsDisplayed && Source.MethodData.GetCurMethod() == 0)
                    {
                        int count = Source.MethodData.GetOverloadCount();

                        if (count > 1)
                        {
                            while (Source.MethodData.NextMethod() < count - 1)
                            {
                                Source.MethodData.UpdateView();
                            }

                            return(true);
                        }
                    }

                    break;

                case VsCommands2K.DOWN:
                    if (Source.MethodData.IsDisplayed)
                    {
                        int count = Source.MethodData.GetOverloadCount();

                        if (count > 1 && Source.MethodData.GetCurMethod() == count - 1)
                        {
                            while (Source.MethodData.PrevMethod() > 0)
                            {
                                Source.MethodData.UpdateView();
                            }

                            return(true);
                        }
                    }

                    break;
                }
            }

            // Base class handled the command.  Do nothing more here.
            //
            return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut));
        }
Exemple #21
0
 public override bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId,
                                    uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (guidCmdGroup == VSConstants.VSStd2K)
     {
         if (nCmdId == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
         {
             // Handle the Insert Snippet command by showing the UI to insert a snippet.
             ExpansionProvider ep = GetExpansionProvider();
             if (ep != null && TextView != null)
             {
                 ep.DisplayExpansionBrowser(TextView, CMakeStrings.CMakeSnippet, null,
                                            false, null, false);
             }
             return(true);
         }
         else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.OPENFILE)
         {
             // Handle the Open File by opening the file specified by the current
             // token.
             string extraSearchPath;
             string fileName = GetCurrentTokenFileName(out extraSearchPath);
             if (fileName == null)
             {
                 return(false);
             }
             string curFileDir = Path.GetDirectoryName(Source.GetFilePath());
             string filePath   = Path.Combine(curFileDir, fileName);
             if (!File.Exists(filePath))
             {
                 filePath = null;
                 if (extraSearchPath != null)
                 {
                     filePath = Path.Combine(extraSearchPath, fileName);
                     if (!File.Exists(filePath))
                     {
                         filePath = null;
                     }
                 }
             }
             if (filePath != null)
             {
                 VsShellUtilities.OpenDocument(ServiceProvider.GlobalProvider,
                                               filePath);
             }
             else
             {
                 MessageBox.Show(string.Format(CMakeStrings.FileNotFound,
                                               fileName), CMakeStrings.MessageBoxTitle,
                                 MessageBoxButtons.OK, MessageBoxIcon.Stop);
             }
             return(true);
         }
         else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.TAB)
         {
             // Handle the tab key when the caret is positioned immediately after
             // the name of a snippet by inserting that snippet.
             ExpansionProvider ep = GetExpansionProvider();
             if (ep == null || TextView == null || ep.InTemplateEditingMode)
             {
                 return(false);
             }
             int line;
             int col;
             if (TextView.GetCaretPos(out line, out col) != VSConstants.S_OK)
             {
                 return(false);
             }
             TokenInfo tokenInfo = Source.GetTokenInfo(line, col);
             if (tokenInfo.StartIndex == tokenInfo.EndIndex)
             {
                 return(false);
             }
             TextSpan span     = tokenInfo.ToTextSpan(line);
             string   shortcut = Source.GetText(span);
             if (string.IsNullOrEmpty(shortcut))
             {
                 return(false);
             }
             string title;
             string path;
             if (ep.FindExpansionByShortcut(TextView, shortcut, span, true,
                                            out title, out path) != VSConstants.S_OK)
             {
                 return(false);
             }
             return(ep.InsertNamedExpansion(TextView, title, path, span, false));
         }
         else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.RETURN)
         {
             // Dismiss method tips when the user presses enter.  They interfere
             // with the proper functioning of smart indentation.
             if (Source.IsCompletorActive && !Source.CompletionSet.IsDisplayed)
             {
                 Source.DismissCompletor();
             }
         }
     }
     else if (guidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
     {
         if (nCmdId == (uint)VSConstants.VSStd97CmdID.F1Help)
         {
             DoContextHelp();
             return(true);
         }
     }
     return(base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn,
                               pvaOut));
 }
Exemple #22
0
 public virtual ExpansionFunction CreateExpansionFunction(ExpansionProvider provider, string functionName);
Exemple #23
0
 public ComposeStarGetNameExpansionFunction(ExpansionProvider provider, int counter)
     : base(provider)
 {
     nameCount = counter;
 }