locked
Filtering COMPLETEWORD command in IOleCommandTarget RRS feed

  • Question

  • Hi,

     I am working on providing intellisense support in VS2010 for a custom extension file. I use ICompletionSource to provide intellisense (as specified in the msdn walkthrough example). However in my IOleCommandTarget interface implementation in method Exec, I am not able to receive the COMPLETEWORD command when Ctrl + space is typed. Instead I end up receiving TYPECHAR and the character itself is space. Am I missing something here? Shouldn't the Exec method be able to intercept all commands?

    Thanks much

    -Karthik

    Friday, July 30, 2010 9:52 PM

Answers

  • I think its a problem with your QueryStatus code. I actually went to go make sure my code that handles this worked and it didnt, in my case it was because i wasnt handling querystatus commands correctly ( some poorly tested refactoring of mine broke this, it was working a few days ago). anyway code will speak more clearly so here is mine.

     

    public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
    {
    	for(int i = 0; i < cCmds;i++)
    	{
    		var status = QueryStatusImpl(pguidCmdGroup, prgCmds[i]);
    		if (status == VSConstants.E_FAIL)
    			return _nextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
    		else
    			prgCmds[i].cmdf = (uint)status;
    	}
    	return VSConstants.S_OK;
    }
    private int QueryStatusImpl(Guid pguidCmdGroup, OLECMD cmd)
    {
    	if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID)
    	{
    		switch ((VSConstants.VSStd2KCmdID)cmd.cmdID)
    		{
    			case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
    			case VSConstants.VSStd2KCmdID.COMPLETEWORD:
    			case VSConstants.VSStd2KCmdID.PARAMINFO:
    			case VSConstants.VSStd2KCmdID.QUICKINFO:
    				return (int)OLECMDF.OLECMDF_ENABLED | (int)OLECMDF.OLECMDF_SUPPORTED;
    		}
    	}
    	return VSConstants.E_FAIL;
    }
    

    • Marked as answer by karthik_raman Saturday, July 31, 2010 4:16 AM
    Friday, July 30, 2010 11:01 PM

All replies

  • I think its a problem with your QueryStatus code. I actually went to go make sure my code that handles this worked and it didnt, in my case it was because i wasnt handling querystatus commands correctly ( some poorly tested refactoring of mine broke this, it was working a few days ago). anyway code will speak more clearly so here is mine.

     

    public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
    {
    	for(int i = 0; i < cCmds;i++)
    	{
    		var status = QueryStatusImpl(pguidCmdGroup, prgCmds[i]);
    		if (status == VSConstants.E_FAIL)
    			return _nextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
    		else
    			prgCmds[i].cmdf = (uint)status;
    	}
    	return VSConstants.S_OK;
    }
    private int QueryStatusImpl(Guid pguidCmdGroup, OLECMD cmd)
    {
    	if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID)
    	{
    		switch ((VSConstants.VSStd2KCmdID)cmd.cmdID)
    		{
    			case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
    			case VSConstants.VSStd2KCmdID.COMPLETEWORD:
    			case VSConstants.VSStd2KCmdID.PARAMINFO:
    			case VSConstants.VSStd2KCmdID.QUICKINFO:
    				return (int)OLECMDF.OLECMDF_ENABLED | (int)OLECMDF.OLECMDF_SUPPORTED;
    		}
    	}
    	return VSConstants.E_FAIL;
    }
    

    • Marked as answer by karthik_raman Saturday, July 31, 2010 4:16 AM
    Friday, July 30, 2010 11:01 PM
  • Thanks a lot. That helped. 
    Saturday, July 31, 2010 4:17 AM