Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Disabling Go To Definition, Go To Declaration and Go To Reference in a LanguageService Implementation

$
0
0

Hi,

I am working on creating a basic language service extension

The Below is the code

    [ComVisible(true)]
    [Guid("5CE7002C-0B61-47AB-9B99-EA0F62E0CE42")]
    class CustomLanguageService : LanguageService
    {
        public const string LanguageName = "Custom Language";
        public const string LanguageExtension = ".kav";
        private LanguagePreferences _preferences;
        public override string Name
        {
            get
            {
                return LanguageName;
            }
        }

        public override LanguagePreferences GetLanguagePreferences()
        {
            if (this._preferences == null)
            {
                this._preferences = new LanguagePreferences(this.Site, typeof(CustomLanguageService).GUID, this.Name);
                this._preferences.Init();

                this._preferences.EnableCommenting = true;
            }

            return this._preferences;
        }

        public override IScanner GetScanner(IVsTextLines buffer)
        {
            return null;
        }

        public override AuthoringScope ParseSource(ParseRequest req)
        {
            return null;
        }

        public override string GetFormatFilterList()
        {
            return "Custom Language (*.kav)\n*.kav";
        }

        public override Source CreateSource(IVsTextLines buffer)
        {
            return new CustomLanguageSource(this, buffer, this.GetColorizer(buffer));
        }
    }


I have also updated my Package to support this language service, and it appears properly in the editor.

Under the right click menu of the editor, the menus "Go To Definition", "Go To Declaration" and "Go To Reference' are visible.

Editor Right Click Options

As I am not implementing these right now I don't want these options.

I tried disabling the menus by using the IOleCommandTarget.QueryStatus and IOleCommandTarget.Exec functions, the "Go To Definition" and "Go To Declaration" menus get hidden but the "Go To Reference" stays visible. I am using the following code to hide them:

int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
    if (Microsoft.VisualStudio.Project.VsMenus.guidStandardCommandSet97 == pguidCmdGroup)
    {
        switch ((uint)prgCmds[0].cmdID)
        {
            case (uint)VsCommands.GotoDecl:
            case (uint)VsCommands.GotoDefn:
            case (uint)VsCommands.GotoRef:            
                prgCmds[0].cmdID |= (uint)QueryStatusResult.NOTSUPPORTED | (uint)QueryStatusResult.INVISIBLE;
                return VSConstants.S_OK;
        }
    }

    return _commandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
}




Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>