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

Hi,

It sounds like there's an enhancement to be made. It would make sense to me that the entries in plugin.xml get added to config-specific providers too.

I thought it could be generalized a bit: when the provider is created for the config it could copy over all entries from the shared one. But that might not work well for providers that are not user entries, like compiler built-ins. I’m not sure if the user would have to clear the entries manually in order to get the new ones from the config-specific compiler.

You can probably achieve your goal by hard-coding the entries in your provider class instead of plugin.xml though.

Marc-André

On Jul 15, 2020, at 11:19 AM, Waterlander, Erwin <erwin.waterlander@xxxxxxxxx> wrote:

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.
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev


Back to the top