[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Thank you Toni.

I have tried to use the C_EDITOR_ID but it seems that my cdt does not have the org.eclipse.cdt.ui.testplugin package and so I used the instanceof operator. In addition I read about the startup and since it is mentioned that it's best to avoid automatic initiation I will just make a shortcut to initialize it when the user needs it like it's now.

Anyway the only thing left right now is the preprocessor thing I have posted here:

http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg24522.html

If anyone could help with that.

Thank you again Toni for all the help.

On 11 June 2012 10:43, Leherbauer, Anton (Toni) <Anton.Leherbauer@xxxxxxxxxxxxx> wrote:

One way to make your plugin activate when Eclipse starts is to implement the âorg.eclipse.ui.startupâ extension point.

BTW, you can find such info also by searching the web, eclipse help or general eclipse forums.

In fact this is in the Eclipse FAQ (although a little outdated): http://wiki.eclipse.org/FAQ_Can_I_activate_my_plug-in_when_the_workbench_starts%3F

Â

To determine whether an IEditorPart is a CEditor you can either use instanceof, or better check its ID (avoids discouraged access to internal class):

editorPart.getSite().getId().equals(C_EDITOR_ID)

Â

Toni

Â

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Lambros Petrou
Sent: Sunday, June 10, 2012 14:01


To: CDT General developers list.
Subject: Re: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Â

I found how to get the TextViewer too and it's like you mentioned here. The thing I am asking is that my plugin since it extends the completionProposalComputer extension point gets activated ONLY when the user press CRTL+SPACE anytime while editing his code.Â

Â

But some features I have ( like the auto-closing for some pragmas ) do not require completion proposal and they should work regardless if the the user pressed CRTL+SPACE. And my question was, where is the best place to make myÂinitializationÂfor the AutoEditStrategy ? I could also add some extra features in the future that need to be activated even if Content Assist does not get called. Where should I put this initialization code, or is there a setting to change in my plugin to get that ?

Â

In addition to your previous answer. Since I 'd like to add the AutoEditStrategy only to the C Editors, is there any way to check what kind is the editor instance I get to avoid unnecessary overhead ?Â

Â

Thanks

On 8 June 2012 14:48, Leherbauer, Anton (Toni) <Anton.Leherbauer@xxxxxxxxxxxxx> wrote:

In addition to adding the strategy to all open editors you need to monitor when a new editor opens.

You can register an IPartListener on the ÂIWorkbechWindow for that purpose (actually youâd need to do this for all windows):

Â

ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ window.getPartService().addPartListener(myListener);

Â

To get to the TextViewer of an editor you have to use a little trick as the viewer is not directly accessible:

Â

ÂÂÂÂÂÂÂÂÂÂÂ ÂÂÂ Object target = editor.getAdapter(ITextOperationTarget.class);

ÂÂÂÂÂÂÂÂÂÂÂ ÂÂÂ if (target instanceof ITextViewer) {

ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ÂÂ â

ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }

Â

Lines starting with # are automatically shifted to the left by the CAutoIndentStrategy.

You can disable this behavior in the preferences: C/C++ > Editor > Typing > Automatically indent > New lines and braces.

Alternatively, you could also indent after the #, e.g.

#if cond

#Â pragma x

#else

#Â pragma y

#endif

Â

Toni

Â

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Lambros Petrou
Sent: Thursday, June 07, 2012 12:42


To: CDT General developers list.
Subject: Re: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Â

Thank you Anton your guidance is Awesome and always on topic. I managed to make the auto-closing to work just fine.

At the moment I have the strategy enabled when the first Content-Assist call is made in the editor ( it works along the completionProposal ) but I 'd like to make it work regardless that. I mean I want my Strategy to be registered as soon as the document is opened. I am thinking of moving the registration in the Activator class but I cannot access the TextViewer it should be registered. Is there any way to register it from somewhere else ? I might be missing some steps in the initialization of the plugin and when the classes load.

Also another minor problem is that Eclipse cdt editor when it encounters the # symbol it moves all the line completely left. Therefore when I insert indentation in my closing pragma to follow the opening one ( it's correctly inserted since I tested it manually with System.out ) it automatically moves to the left-most position and any empty spaces are removed. Is there a way to retain the spaces in front of the # ?

Thank you again for all the help.

On 6 June 2012 11:50, Leherbauer, Anton (Toni) <Anton.Leherbauer@xxxxxxxxxxxxx> wrote:

If you register the modified DefaultMultilineCommentAutoEditStrategy for â__c_multiline_commentâ, it wonât be called outside of multi-line comments.

As |* does not introduce a multiline comment, it is not called. You would need to register it for ICDocument.DEFAULT_CONTENT_TYPE.

Â

Yes, ICPartitions.C_PREPROCESSOR is the content-type to use if the strategy is to be called inside #pragma directives.

Â

Cheers,

Toni

Â

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Lambros Petrou
Sent: Tuesday, June 05, 2012 18:06


To: CDT General developers list.
Subject: Re: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Â

Ok I looked at IAutoEditStrategy and the DefaultMultilineCommentAutoEditStrategy. I made some changes to the Default one ( just for testing reasons ) and instead of ' /* ' I am using ' |* ' for my comments and I have used the ' prependAutoEditStrategy() ' method in my context text viewer when my plugin is enabled to load my strategy successfully. I have println() inside so I know when it's called.

The problem is that my strategy does not get called when I type in |* but only in normal comments /*. Is there any other place I should change to enable the custom strategy ?

In addition back to my problem, the contentType I should use is the C_PREPROCESSOR correct ?

On 5 June 2012 16:16, Lambros Petrou <lambrospower@xxxxxxxx> wrote:

Thank you. I am going to look into that. By programmatically you mean what exactly ? I believe like : At the first call of my plugin to get the TextViewer of the editor instance and add my strategy ? ( Is there a special function that adds it ? )

Thanks

Â

On 5 June 2012 14:41, Leherbauer, Anton (Toni) <Anton.Leherbauer@xxxxxxxxxxxxx> wrote:

This sounds like an IAutoEditStrategy. See e.g. DefaultMultilineCommentAutoEditStrategy which closes a multiline comment when pressing enter after /*.

Unfortunately you cannot add such a strategy via plugin.xml. You would need to add it programmatically to the underlying TextViewer of each C/C++ editor instance.

Â

Toni

Â

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Lambros Petrou
Sent: Tuesday, June 05, 2012 13:01


To: CDT General developers list.
Subject: Re: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Â

Ok,

I finally got it and it works quite good. I just extended the DefaultProposalFilter to filter the ditor to just show my proposals and I implemented the ICompletionProposalComputer in order to create a list with the ICompletionProposals.

In this class I just use String manipulation to find the matching proposals to be listed and I do not use anything like the DOM or AST structures. Is there any problem with that later on ? It works for now perfectly.

I want to add another feature now and I cannot find any resource for it apart from templates. Some of the pragmas I have consist of a " starting " command and they have a " closing " command, like the braces in a for loop.

How can I add the possibility, when the pragma is finished and he presses ENTER while being at the end of the " starting " command to leave a blank line and autoinsert the " closing " command ? ( if I can move the cursor in between them it would be good but not required, at the moment ).

The main requirement right now is that Auto-closing when the user presses ENTER and the only way I found is by templates but it wouldn't work here because the " starting " command is not standard so a template with one structure will not have a match. I am going to check which " closing " command should be inserted but I just need that trigger when the ENTER is pressed.

Thank you.

On 22 May 2012 10:11, Leherbauer, Anton (Toni) <Anton.Leherbauer@xxxxxxxxxxxxx> wrote:

One possible trap is that you need to export the package of your class such that it can be instantiated by cdt.ui.

You can do this on the Runtime tab of the plugin manifest editor.

Â

Toni

Â

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Lambros Petrou
Sent: Monday, May 21, 2012 18:49
To: CDT General developers list.
Subject: Re: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Â

Yes, I have been looking atÂÂInclusionProposalComputer since your reply and I have a draft ready but it seems there is a probem. How can I check if my plugin is enabled and i use, because I am trying the pragmas and nothing comes up in the suggestions.

Â

My plugin.xml is like this:

Â

<?xml version="1.0" encoding="UTF-8"?>

<?eclipse version="3.4"?>

<plugin>

Â

<extension

     id="DDMPragmasProposalComputer"

     point="org.eclipse.cdt.ui.completionProposalComputer">

   Â<completionProposalComputer

      ÂcategoryId="org.eclipse.cdt.ui.parserProposalCategory"

      Âclass="ddmcontentassistance.DDMPragmasProposalComputer">

     <partition type="__c_preprocessor"/>

   Â</completionProposalComputer>

  </extension>

Â

</plugin>

Â

Thank you.

Â

On 21 May 2012 09:57, Leherbauer, Anton (Toni) <Anton.Leherbauer@xxxxxxxxxxxxx> wrote:

Hi,

Â

Iâd suggest to look into the extension point âorg.eclipse.cdt.ui.completionProposalComputerâ.

All internal completion proposal computers are in fact implementations of this extension point.

The âInclusionProposalComputerâ class and its plugin.xml extension snippet might provide some boilerplate code to get you started.

Â

HTH

Toni

Â

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Lambros Petrou
Sent: Sunday, May 20, 2012 19:17
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] Extend the C language Content Assist in Eclipse to support custom commands

Â

I am trying to extend the C/C++ language in Eclipse CDT in order to have auto-complete (Content Assist) for some custom commands ( mostly pragmas ).

Let's say I have the command:Â#pragma IAM THE_CUSTOM_COMMANDÂvar1 var2

I' d like to make a plugin in order to have the ability the moment I type inÂ#pragmaÂand then SPACE to show the possible commands I have like when I am using regular functions. And if I press enter on one of the suggestions the whole command should be pasted with the default values in the variables.

I tried reading in the Eclipse FAQ and found many tutorials online but I only found how to make a completely new editor supporting my commands.

I just need to add 20-30 pragmas like this in the CDT editor currently being used in Eclipse.

I read that there is an Extension Point for CDT Language and if I could make an extension for that it would be sufficient but I haven't found a tutorial explaining this.

Is there any way to add these commands to the CDT Editor with the Auto-complete functionality I want without making my own editor ? The language we use is C and we have these pragmas and this feature would be great since we use them a lot.

Thank you all.


Â

--

Lambros Petrou

Â

Â


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Â

--

Lambros Petrou

Â

Â


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--

Lambros Petrou

Â

Â


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--

Lambros Petrou

Â

Â




--

Lambros Petrou

Â

Â


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--

Lambros Petrou

Â

Â


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Â

--

Lambros Petrou

Â

Â


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--
Lambros Petrou

www.lambrospetrou.com
lambrospower@xxxxxxxx