Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Problem with adding entries to language settings provider in CDT plugin
  • From: "Waterlander, Erwin" <erwin.waterlander@xxxxxxxxx>
  • Date: Wed, 15 Jul 2020 15:19:56 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ykmwdB3ISEi7gsZUW0MnkHgv6Nuk8b8svrBfj+gA9lI=; b=D1F5MbLan/MpOIGjTnBJ9FofcW4xoIWd589MhuhE9OrvDyC0T2gqk6XYR8MhKRaRGsmojxE6WeomY6j5JYwp0jf78pMC3mVshyPx8yvxQOqjvBX8kpsh2Dcfh68tsnK2ZBHOWBZH9XaPcVZ/Yt2PLBzskow5DfnNd5RNXPzWoYBJb9LovY2Q6lPm2lZkZZSN9u2pRghQiPYuze/wWgq9wabhbyYOajCO7eIm1JgYFsGXmarIGnfNVb/QLb1KIVKMsZ1G5cwicj0YBdbsSOY2jJ630piuD8+lIF+f95DAT+9P/XkWEFV2LDDHA6fHwEzoWqzuDlyTMCEDwsPltsSYPg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LIhT12Pj0eZGmkARhvO6PtCGPA6Dm0rETehylVHyFzLbV5mUiDBtaMnI9/0jtzFVcbGtW0fTvbGqOYZ5Q1o+Q3ZXRyfVpyD69JwEaIY/Ob9wa8n0k0uIa2gGcd3H8wLJGvLYxrMaJhCsmze072LdK208xX6Kql56U7CFxb1qV8jsOm6w/3pDBxVvtRGfz6azOzmTjPjo7oBTYS4Scye35kwAIpgSG/ozXaRmyW6c42og1c7dYnXZtXUgF4pR+l18918uSS6cXrGc4SN3VaU0SlSVjZY4GEr+/N8XoiUEsTRPQ2gdBbEMjNdt/X/AdOIqfN5EGbV4y/ePDf8obZ0kxA==
  • Delivered-to: cdt-dev@xxxxxxxxxxx
  • Dlp-product: dlpe-windows
  • Dlp-reaction: no-action
  • Dlp-version: 11.2.0.6
  • Ironport-sdr: cmwO27LXMU+KFC5Z0ti0djfSgA2EHdl2Uc4LPrsLeAY3C57HQuUCALJvjmVqhlqG8uqBI0eOqz B0tJNvpP1bjg==
  • Ironport-sdr: t9sgnjahonAoJitLf6OWkQzL+evL1UierGHq3N1Cn7ZTEVFEsZAHSof//0uk3DPhR+GV5MWY7w iAIxWBqAydRA==
  • List-archive: <https://www.eclipse.org/mailman/private/cdt-dev>
  • List-help: <mailto:cdt-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AdZZKT5RftkmtXh4SRePpdUd/cCJjgAC+LsAAFrEuIA=
  • Thread-topic: [cdt-dev] Problem with adding entries to language settings provider in CDT plugin

Hi,

Thanks a lot for your answer.
There are two things I had to change to make the example work.

First the provider class has to be an own class. I just made a copy of LanguageSettingsGenericProvider.

   <extension
         point="org.eclipse.cdt.core.LanguageSettingsProvider">
      <provider
            class="org.eclipse.cdt.example.toolchain.MyLanguageProvider"
            id="org.eclipse.cdt.example.toolchain.provider1"
            name="Example Provider"
            prefer-non-shared="true">
         <entry
               kind="includePath"
               name="/project/include">
         </entry>
         <entry
               kind="macro"
               name="MYMACRO"
               value="3">
         </entry>
      </provider>
   </extension>
   <extension
         point="org.eclipse.cdt.ui.LanguageSettingsProviderAssociation">
      <id-association
            id="org.eclipse.cdt.example.toolchain.provider1"
            ui-edit-entries="true">
      </id-association>
   </extension>

Secondly the I had to use your touchProjectDes() method to make the project description dirty.
The configuration description was already writable, and I did not need a Workspace Job.

    public void addEntries(IProject project) throws CoreException {
        ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);

        ICConfigurationDescription configs[] = projectDescription.getConfigurations();

        ICConfigurationDescription cfgDescription = null;

        for (ICConfigurationDescription config : configs) {
            if (config.getId().contains("example")) {
                cfgDescription = config;
                break;
            }
        }

        System.out.println("cfgDescription id: " + cfgDescription.getId());
        if (cfgDescription.isReadOnly()) {
            System.out.println("cfgDescription read only");
        }
        if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) {
            System.out.println("no writable");
        }

        MyLanguageProvider provider = null;

        List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription)
                .getLanguageSettingProviders();

        for (ILanguageSettingsProvider p : providers) {
            if (p.getId().contains("example")) {
                provider = (MyLanguageProvider) p;
                break;
            }
        }

        if (provider == null)
            return;

        System.out.println("provider id: " + provider.getId());


        List<ICLanguageSettingEntry> entries;
        List<String> languageScope = new ArrayList<String>();
        languageScope.add("org.eclipse.cdt.core.gcc");

        // Entries from plugin.xml are added to the global workspace provider instance.
        ILanguageSettingsProvider globalProvider = null;
        globalProvider = LanguageSettingsManager.getWorkspaceProvider("org.eclipse.cdt.example.toolchain.provider1");
        entries = globalProvider.getSettingEntries(null, null, null);

        // Get existing entries from configuration provider, otherwise create new entries.
        entries = provider.getSettingEntries(cfgDescription, project, "org.eclipse.cdt.core.gcc");
        if (entries == null)
            entries = new ArrayList<ICLanguageSettingEntry>();

        // Add include path
        CIncludePathEntry entry;
        entry = CDataUtil.createCIncludePathEntry("/home/project/include", ICSettingEntry.NONE);
        entries.add(entry);

        provider.setLanguageScope(languageScope);
        provider.setSettingEntries(cfgDescription, project, "org.eclipse.cdt.core.gcc", entries);

        touchProjectDes(projectDescription);
        CoreModel.getDefault().setProjectDescription(project, projectDescription);

    }

    private void touchProjectDes(ICProjectDescription desc) {
        // Make sure the project description is marked as modified so that language
        // settings serialization kicks in.
        // We need to let the setProjectDescription do the serialization because we
        // cannot do it on a writable description
        // and we need a writable description because we need to call setSourceEntries!
        final QualifiedName TOUCH_PROPERTY = new QualifiedName(CCorePlugin.PLUGIN_ID, "touch-project"); //$NON-NLS-1$
        desc.setSessionProperty(TOUCH_PROPERTY, ""); //$NON-NLS-1$
        desc.setSessionProperty(TOUCH_PROPERTY, null);
    }


The entries I add in the plugin.xml are only added to the global workspace provider instance. Not to the configuration provider instance.

I see them in the GUI when I enable checkbox "Use global provider shared between projects".
And programmatically:

        globalProvider = LanguageSettingsManager.getWorkspaceProvider("org.eclipse.cdt.example.toolchain.provider1");
        entries = globalProvider.getSettingEntries(null, null, null);

When the checkbox in the GUI is unchecked the configuration entries are gone.

-- 
Erwin 

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> On Behalf Of Marc-Andre Laperle
Sent: Monday, July 13, 2020 18:46
To: CDT General developers list. <cdt-dev@xxxxxxxxxxx>
Subject: Re: [cdt-dev] Problem with adding entries to language settings provider in CDT plugin

Hi Erwin!

I did go through some pains trying to add entries programatically somewhat recently.
You can see the hurdles in CompilationDatabaseParser class.
I would double check that you have a writable ICConfigurationDescription. If not, I think you have to get a writable description and set it within a WorkspaceJob. Also make sure you get the correct language settings provider from this writable description. See CompilationDatabaseParser.scheduleOnWritableCfgDescription for example.
I also remember the description was not seen as dirty just by changing language settings. I did a hack by setting a “session property” on the project description. See CompilationDatabaseParser.touchProjectDes.

I don’t really master any of these parts but maybe one of those suggestions will help you.

Marc-André


> On Jul 13, 2020, at 11:21 AM, Waterlander, Erwin <erwin.waterlander@xxxxxxxxx> wrote:
> 
> Hi,
> 
> When I add an editable language settings provider via the plugin.xml to a CDT plugin per configuration, the entries added in the plugin.xml are not there.
> And when I add entries programmatically to the provider they are also not there.
> What am I doing wrong?
> 
> I took the example from the CDT plugin developers guide and added this to the plugin.xml:
> 
>   <extension
>         point="org.eclipse.cdt.core.LanguageSettingsProvider">
>      <provider
>            class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider"
>            id="org.eclipse.cdt.example.toolchain.provider1"
>            name="Example Provider"
>            prefer-non-shared="true">
>         <entry
>               kind="includePath"
>               name="org.eclipse.cdt.example.toolchain.entry2"
>               value="/project/include">
>         </entry>
>      </provider>
>   </extension>
>   <extension
>         point="org.eclipse.cdt.ui.LanguageSettingsProviderAssociation">
>      <id-association
>            id="org.eclipse.cdt.example.toolchain.provider1"
>            ui-edit-entries="true">
>      </id-association>
>   </extension>
> 
> 
>         <configuration
>               id="org.eclipse.cdt.example.toolchain.configuration1"
>               languageSettingsProviders="org.eclipse.cdt.example.toolchain.provider1;org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider;org.eclipse.cdt.ui.UserLanguageSettingsProvider"
>               name="Test Release">
>               .....
>         </configuration>
> 
> 
> Adding entries programmatically:
> 
> 
>        LanguageSettingsGenericProvider provider = null;
> 
>        List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgDescription)
>                .getLanguageSettingProviders();
>        for (ILanguageSettingsProvider p : providers) {
>            if (p.getId().contains("example")) {
>                provider = (LanguageSettingsGenericProvider) p;
>                break;
>            }
>        }
> 
>        System.out.println("provider id: " + provider.getId());        
>        // Output: provider id: org.eclipse.cdt.example.toolchain.provider1
>        // No number suffix (?)
> 
>        // Get existing entries (from plugin.xml).
>        List<ICLanguageSettingEntry> entries = provider.getSettingEntries(cfgDescription, project,
>                "org.eclipse.cdt.core.cSource");
> 
>       // entries appears to be null. I would expect to see the include path from plugin.xml.
> 
>        if (entries == null)
>            entries = new ArrayList<ICLanguageSettingEntry>();
> 
>        // Add extra include path
>        CIncludePathEntry entry;
>        entry = CDataUtil.createCIncludePathEntry("/project/include/extra", ICSettingEntry.NONE);
>        entries.add(entry);
> 
>        provider.setSettingEntries(cfgDescription, project, 
> "org.eclipse.cdt.core.cSource", entries);
> 
>        CoreModel.getDefault().setProjectDescription(project, 
> projectDescription);
> 
> 
> regards,
> 
> --
> Erwin
> 
> ---------------------------------------------------------------------
> Intel Benelux B.V.
> Registered in The Netherlands under number 24134020 Statutory seat: 
> Rotterdam Registered address: Capronilaan 37, 1119NG Schiphol-Rijk
> 
> This e-mail and any attachments may contain confidential material for 
> the sole use of the intended recipient(s). Any review or distribution 
> by others is strictly prohibited. If you are not the intended 
> recipient, please contact the sender and delete all copies.
> 
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit 
> https://www.eclipse.org/mailman/listinfo/cdt-dev


---------------------------------------------------------------------
Intel Benelux B.V.
Registered in The Netherlands under number 24134020
Statutory seat: Rotterdam
Registered address: Capronilaan 37, 1119NG Schiphol-Rijk

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

Back to the top