locked
F1 Help (Dynamic Help/Context Sensitive Help) from Custom Language Service - UpdateLanguageContext called twice RRS feed

  • Question

  • Hi

    I want to implement context sensitive help in my language service - very similar to this question: http://social.msdn.microsoft.com/Forums/en/vsx/thread/9c106d0d-3618-4638-8c5d-2958ce29bb9e


    I have implemented IVsLanguageContextProvider interface and my code looks like this:

    public override void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, Microsoft.VisualStudio.Shell.Interop.IVsUserContext context)
    {
        if (hint == LanguageContextHint.LCH_F1_HELP && IsHelpEnabled())
        {
            // Show .chm file with help
            string keyword = null;
            buffer.GetLineText(ptsSelection[0].iStartLine, ptsSelection[0].iStartIndex, ptsSelection[0].iStartLine, ptsSelection[0].iEndIndex, out keyword);
            mChmHelpLibrary.ShowHelpForKeyword(keyword.Trim());
        }
    }


    Everything is working fine, when I press F1 on some word appropriate help page (.chm file) is shown.

    The problem is: this method is called twice.

    First time is LanguageContextHint is equal to LCH_F1_HELP but second time it is always  LCH_DEFAULT.

    When UpdateLanguageContext is called with LCH_DEFAULT dynamic help system opens new tab in my browser and navigate to some page (related to textEditor window) - here I suppose this is because setting of dynamic help in Visual Studio (can be changed to open in internal browser) and it is really annoying.

    How can I disable that second call and show only my .chm help file???



    • Edited by Jane Wang - MSFT Monday, December 16, 2013 5:45 AM "Sensative" should be "Sensitive"
    Wednesday, August 1, 2012 6:05 AM

All replies

  • Hi unSigned,

    Can you provide your exemple codes? We want to do some debuging.

    I can't found what causes this issue from your description.

    Thank you for your understanding and support.
     
    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 2, 2012 6:27 AM
  • This is MyLanguageService

    I am using MPF, Visual Studio 2010, base class for LanguageService is from VS 2010 SDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Package.LanguageService.10.0.dll

    using System;
    using Microsoft.VisualStudio;
    using Microsoft.VisualStudio.Package;
    using Microsoft.VisualStudio.TextManager.Interop;
    using unSignedSoftworks.MYProject;
    using System.Diagnostics;
    using System.Windows.Forms;
    using System.Drawing;
    using System.IO;
    using System.Reflection;
    using unSignedSoftworks.MYLanguage.Lexer;
    using unSignedSoftworks.Common;
    using VisualInstaller;
    
    #if VISUAL_STUDIO_2010
    using Microsoft.Build.Evaluation;
    using Microsoft.Build.Execution;
    using System.Runtime.InteropServices;
    #endif
    
    namespace unSignedSoftworks.MYLanguage
    {
        public class LanguageSupportedExtensions
        {
            // MY file extensions
            public const string MY_MY = ".my";
            public const string MY_MYY = ".myy";
        }
    
        [Guid(GuidList.guidMYLanguageService)]
        public class MYLanguageService : LanguageService
        {
            private ColorableItem[] mColorableItems;
            private LanguagePreferences mPreferences;
            // Gather list of declarations based on what the user has typed so far
            MemberDeclarations mMemberDeclarations = null;
    
            // Navigation bars
            NavigationBars mNavigationBars = null;
    
            // QuickInfo
            MyTokenInfo mLastQuickInfo = null;
    
            bool mIsFirstTimeCall = true;
            bool mIsParseCompleted = false;
            bool mModuleEnabled = false;
    
            ChmHelpLibrary mChmHelpLibrary = null;
           
            public MYLanguageService()
            {
                Trace.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
    
                mModuleEnabled = true;
    
                mMemberDeclarations = new MemberDeclarations(this);
    
                if (IsModuleEnabled())
                {
                    // Load declarations
    
                    mColorableItems = new ColorableItem[]
                    {
                        /*1*/ new LanguageColorableItem(Name + " - Keyword",        Name + " - Keyword",        COLORINDEX.CI_BLUE,             COLORINDEX.CI_USERTEXT_BK),
                   };
                    // Parameters /*1*/ to /*X*/ are used in MYScanner.cs
                }
            }
    
            public bool IsModuleEnabled()
            {
                return mModuleEnabled;
            }
    
            public override int GetItemCount(out int count)
            {
                count = mColorableItems.Length;
                return VSConstants.S_OK;
            }
    
            public override int GetColorableItem(int index, out IVsColorableItem item)
            {
                if (index < 1)
                {
                    throw new ArgumentOutOfRangeException("index");
                }
    
                item = mColorableItems[index-1];
                return VSConstants.S_OK;
            }
    
            public override LanguagePreferences GetLanguagePreferences()
            {
                if (mPreferences == null)
                {
                    mPreferences = new LanguagePreferences(this.Site, typeof(MYLanguageService).GUID, this.Name);
                    mPreferences.Init();
                }
                return mPreferences;
            }
    
            public override IScanner GetScanner(IVsTextLines buffer)
            {
                string filePath = FilePathUtilities.GetFilePath(buffer);
                // Return dynamic scanner based on file extension
                return ScannerFactory.GetScanner(filePath);
            }
    
            public override Source CreateSource(IVsTextLines buffer)
            {
                return new LanguageSource(this, buffer, GetColorizer(buffer));
            }
    
            public override AuthoringScope ParseSource(ParseRequest parseRequest)
            {
                MYAuthoringScope authoringScope = new MYAuthoringScope(this);
                
                switch (parseRequest.Reason)
                {
                    case ParseReason.CompleteWord:
                    {                    
                        // User uses CompleteWord feature for a first time 
                        if (mIsFirstTimeCall && IsModuleEnabled())
                        {
                            // Parse all plug-ins (in MY\Plugins dir and in current dir too)
      
                            // Get all *.my files in current directory, "MY\Include" // and "MY\Include\Win" 
                          
                           mIsFirstTimeCall = false;
                        }
                           
                        // Populate the Declarations list in the authoring scope
                        authoringScope.SetDeclaration(ref this.mMemberDeclarations);
                    }
                    break;
    
                    case ParseReason.QuickInfo:
                    {
    
                    }
                    break;
                }
    
                return authoringScope;
            }
          
            public override void OnParseComplete(ParseRequest req)
            {
                if(!mIsParseCompleted && req.Reason == ParseReason.Check && IsModuleEnabled())
                {
                    mIsParseCompleted = true;
                }
                base.OnParseComplete(req);
            }
    
            public override TypeAndMemberDropdownBars CreateDropDownHelper(IVsTextView textView)
            {
                    return null;
            }
    
    
            public override string GetFormatFilterList()
            {
                return string.Empty;
            }
    
            public override string Name
            {
                get { return GuidList.nameMYLanguage; }
            }
    
            public override ImageList GetImageList()
            {
                ImageList imageList = base.GetImageList();
                return imageList;
            }
    
            public override void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, Microsoft.VisualStudio.Shell.Interop.IVsUserContext context)
            {
                if (hint == LanguageContextHint.LCH_F1_HELP && IsModuleEnabled())
                {
                    // Show .chm file with help
                    string keyword = null;
                    buffer.GetLineText(ptsSelection[0].iStartLine, ptsSelection[0].iStartIndex, ptsSelection[0].iStartLine, ptsSelection[0].iEndIndex, out keyword);
                    if (mChmHelpLibrary == null)
                    {
                        // Create help library
                        mChmHelpLibrary = new ChmHelpLibrary("path", false);
                    }
                    mChmHelpLibrary.ShowHelpForKeyword(keyword.Trim());
                }
            }
    
            
            public class MYAuthoringScope : AuthoringScope
            {
                MemberDeclarations mDeclarationsList;
                MYLanguageService mMyLanguageSevice;
    
                public MYAuthoringScope(MYLanguageService MyLanguageSevice)
                {
                    mMyLanguageSevice = MyLanguageSevice;
                }
    
                public override string GetDataTipText(int line, int col, out TextSpan span)
                {
                    span = new TextSpan();
                    string tooltip = string.Empty;
                  
                    return tooltip;
                }
    
                public void SetDeclaration(ref MemberDeclarations declarations)
                {
                    if (mDeclarationsList == null && declarations != null)
                    {
                        mDeclarationsList = declarations;
                    }
                }
    
                public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
                {
                    // mDeclarationsList contains default (predefined) symbols
                    MemberDeclarations declarations = new MemberDeclarations(mMyLanguageSevice);
    
                    // Return everything in one list
                    return declarations;
                }
    
                public override Methods GetMethods(int line, int col, string name)
                {
                    return null;
                }
    
                public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int column, out TextSpan span)
                {
                    span = new TextSpan();
                    string path = null;
                    return path;
                }
            }
        }
    }



    Friday, August 3, 2012 12:12 PM
  • Hi unSigned,

    I couldn't use your codes. I created a new LanguageService and override the fuction of UpdateLanguageContext and use ProvideLanguageServiceAttribute. However I failed to call UpdateLanguageContext.

    If you feel it is a bug, you can submit it to connect:

    http://connect.microsoft.com/visualstudio

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 9, 2012 8:43 AM