none
Intellisense force update RRS feed

  • Question

  • I have issues with my add-in for Visual Studio 2005. I add-in helps insert some kind of function and variables into Visual C++ projects.  I need to retrieve classes of project. Firstly, my add-in was developped for Visual Studio 2003 and it works fine there. However almost same code for enumerating classes is not working for Visual Studio 2005. I think the problem is that Intellisense does not update project in time. After switching to class view and expanding classes tree everything is fine, classes are found and parssed.
    I wonder if any way to force Intellisense to update its database from my add-in? I found one new method in CodeModel2 class comparing CodeModel. It is "Synchronize", but it description is not very clear for me.

    Code which fill array of classes is following. There is only one public method (GetClasses). CSmartAtlArray is public child of CAtlArray.

    HRESULT CConnect::AddClassToVector(EnvDTE::CodeElementPtr pItem, CSmartAtlArray<VSClass*>& Classes, VSClass* pParentClass /*  = NULL */)
    {
        VSClass* pClass = new VSClass;
        pClass->pElement = pItem;
        pClass->pCodeModel = m_pCodeModel;
        pClass->RetriveName(true);
        if (pParentClass)
        {
            pParentClass->NestedClasses.Add(pClass);
        }
        Classes.Add(pClass);
        VCCodeModelLibrary::VCCodeClassPtr pVCClass = pItem;
        if (pVCClass != NULL)
        {
            EnvDTE::CodeElementsPtr pNestedClasses = pVCClass->Classes;
            long NestedCount;
            pNestedClasses->get_Count(&NestedCount);
            for (long j = 1; j <= NestedCount; j++ )
            {
                EnvDTE::CodeElementPtr pNestedClass;
                pNestedClasses->Item(_variant_t(j), &pNestedClass);
                AddClassToVector(pNestedClass, Classes, pClass);
            }
        }
        return S_OK;
    }

    HRESULT CConnect::AddNamespaceToVector(EnvDTE::CodeElementPtr pItem, CSmartAtlArray<VSClass*>& Classes)
    {
        VCCodeModelLibrary::VCCodeNamespacePtr pNamespace = pItem;
        if (pNamespace != NULL)
        {
            EnvDTE::CodeElementsPtr pClasses, pNamespaces;
            pClasses = pNamespace->Classes;
            long Count;
            pClasses->get_Count(&Count);
            for (long i = 1; i <= Count; i++)
            {
                EnvDTE::CodeElementPtr pElem;
                pClasses->Item(_variant_t(i), &pElem);
                AddClassToVector(pElem, Classes);
            }
            pNamespaces = pNamespace->Namespaces;
            pNamespaces->get_Count(&Count);
            for (long i = 1; i <= Count; i++)
            {
                EnvDTE::CodeElementPtr pElem;
                pNamespaces->Item(_variant_t(i), &pElem);
                AddNamespaceToVector(pElem, Classes);
            }
        }
        return S_OK;
    }

    HRESULT CConnect::GetClasses(EnvDTE::ProjectPtr pProj, CSmartAtlArray<VSClass*>& Classes)
    {
        EnvDTE::CodeElementsPtr pElements = NULL;
        EnvDTE::CodeElementPtr pItem;

        if (pProj == NULL)
        {
            return E_FAIL;
        }

        if (FAILED(pProj->get_CodeModel(&m_pCodeModel)))
        {
            return E_FAIL;
        }

        if (FAILED(m_pCodeModel->get_CodeElements(&pElements)))
        {
            return E_FAIL;
        }

        long Count;
        pElements->get_Count(&Count);
        for (long i = 1; i <= Count; i++)
        {
            _variant_t vt = i;
            if (FAILED(pElements->Item(vt, &pItem)) || (pItem == NULL))
            {
                return E_FAIL;
            }

            EnvDTE::vsCMElement type;
            pItem->get_Kind(&type);
            if (type == EnvDTE::vsCMElementClass)
            {
                AddClassToVector(pItem, Classes);
            }
            if (type == EnvDTE::vsCMElementNamespace)
            {
                AddNamespaceToVector(pItem, Classes);
            }
        }

        return S_OK;
    }

    Friday, February 24, 2006 8:56 AM

Answers