Eclipse Custom Content Assist Based on Default Java Content Assist results - eclipse

I'm in the process of implementing a task tool. As a part of this I'm making an Eclipse plug-in to reflect certain code level issues.
In the Eclipse plug-in my aim is to attach some visual aids to different Java elements according to their host task's status. I've been successful in adding multi-colored markers to the vertical ruler of the default Java editor as well as the resource icons displayed by the Overview. However, I have not been able to change the icons in the Java content assist.
At first I thought that by using the extension point org.eclipse.ui.decorators and having its enablement set as org.eclipse.jdt.core.IJavaElement, the content assistant would also be affected, as this was the case with element icons in the Overview. I've tried several other enablement classes ranging all the way to ICompletionProposal.
Since this approach, a bunch of others and extending the default Java content assist, won't work. I've decided to implement my own content assist.
The idea now is to somehow take the default Java content assist's results and run some checks on the proposed elements and in case of a match change the icon displayed in the content assist, to reflect the associated task's level.
I've tried to look through the source for Eclipse's default Java editor and the Mylyn project, but I can't understand how they provide their Java content assists and how to access / redo them.
The end result I'm looking to get: LINK
The actual question
When providing a new content assist (category) for the default Java editor in Eclipse, how does one get a list of proposals that the default Java content assistant would produce for that point?
My first question and certainly a long intro, please let me know if I should edit this in any way and most importantly thanks for all the help in advance!
-J3lly

Take a look at the following extension point : org.eclipse.jdt.ui.javaCompletionProposalComputer
To implement your own Content Assist you have to write a class that implements org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer. In your case, since you want to modify the behavior of the default Java Content Assist, you should override one of the internal implementations org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer, org.eclipse.jdt.internal.ui.text.java.JavaAllCompletionProposalComputer or any other implementation depending on which Content Assist you want to modify.
Now all you have to do is override the method computeCompletionProposals which returns the list of completion proposals. The overridden method should call super.computeCompletionProposals(...) to get the default completion proposals, then you can modify them according to your needs.

Related

Associate file type to my vscode extension like a project file

I'd like to do something like a project file. When the user opens it, the webview of my extension would welcome the user instead of the default VSCode editor.
I know I can workaround it by adding extra context menu items or buttons, but in this case I'm curious if it's possible to override that it by default tries to open in the editor.
Is this possible either manually or automatically?
What you're after sounds exactly like what the upcoming webview / custom editor API hopes to accomplish.
The custom editor API aims to allow extensions to create fully customizable read/write editors that are used in place of VS Code's standard text editor for specific resources. These editors will be based on webviews. We will support editors for both binary and text resources.
See the following issue for more info and further links to the proposed API, example extensions etc:
Custom webview editor API (#77131)
Note that it usually takes a while for new APIs to make it into stable releases after being made available as "proposed APIs".

Supporting toggle between new file-types in eclipse or eclipse CDT

I would like to extend the source/header toggle functionality of eclipse CDT for custom file types. I work with *.cppml and *.hppml file extensions (C++ with some functional language syntax-extension), and I would like eclipse to understand that there is a source/header relationship between these two file types and toggle between them upon request.
The current CDT does not support this exactly, but it is pretty close, it needs an update to SourceHeaderPartnerFinder.
That class has a method, getPartnerFileFromFilename, which calculates the partner when you do a Header/Source toggle (Ctrl+Tab by default, or available from Navigate -> Toggle Source/Header)
That method strips off the extension of the file you started in, and then tries the partner type extensions (as derived from getPartnerContentTypes).
What needs to be done is update getPartnerFileFromFilename to create new header/source partnerships. Perhaps you could even edit the File Types property pages to allow users to explicitly define such associations.
If this feature is of value to you, raising it in CDT's Bugzilla would be a good start.

Eclipse content assist (for PHP or anything) not using active working set

The Eclipse content assist for PHP (and I'm assuming for other types as well) isn't using the currently active working set - it's searching ALL files in the project. How do I change it to only use the active working set?
When doing a Ctrl+Shift+R search, it was also looking for all files in the project (not what I wanted), until I clicked the small black triangle in that window and selected the working set I wanted it to use. Now it successfully only shows the files that match my search string in the working set. However, this doesn't change anything in the autocomplete content assist feature (i.e. doing a Ctrl+Space to complete the name of a function or variable). Is there any way to accomplish this?
I'm using Eclipse Indigo release, so it's very recent.
I'm afraid it's not possible the way you put it. Eclipse Working Sets just give you a way to organize your projects.
However you may want to take a look at Mylyn, which is fully integrated with Eclipse platform. Here and here is a nice overview of what you can do with Mylyn. But briefly, what it allows you to do is to create a task and maintain a context associated with it. This way, only the relevant files will be displayed in Project Explorer and autocomplete would suggest you only task-focused options.

how modify the already installed content-assist?

First of, how can I see what plugin manages the CTRL + SPACE content-assist? And how can I modify it in other to add my own stuff. Any help/idea is gladly welcome.
Thanks.
I think you're looking for "Templates". Assuming you're using Java, this is in the Windows -> Preferences menu, then Java->Editor->Templates. For example, the screenshot below shows the CTRL-SPACE content assist when you type "sysout".
If i would have this task, I would go to preferences. Look for content assist settings. Write down some specific text you see in dialog box. Then go to plugins folder, and start to search inside archives. When match is present, open the plugin.xml of that plugin, and you will see the extension points of the plugin. Based on its name, I am pretty sure you will find the appropiate one. Then you can either google it, or look for plugins extending the extension point. Using JDGui or fetching source code of the extension example plugin will help you in disassembling. Eclipse usually not well documented as for extension points, so i do it this way.

How does Eclipse do code completion specific to third-party frameworks?

How does the Eclipse editor work to enable code completion? For example, within the XML editor for Hibernate property files, if I ctrl-space within a tag, a list of possible value relevant to hibernate will show up.
I understand that the XML editor is pre-configured to understand xml tag, but how about tag specific to a particular framework? How does Eclipse know about that?
I believe that the eclipse XML editor gets the content assist information from any referenced DTDs, or XMLSchema information it associates with the XML file. Try this experiment: Remove the DOCTYPE entry at the beginning of the file and see if content assist still works.
If you're interested in writing your own content assistants, you may want to start by reading the following:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_contentassist.htm
In a nutshell, like most things in Eclipse, this is a platform hook. When you press the button, it queries all the registered assistants (I'm simplifying here), and they provide suggestions based on the current element or even the current content.
When writing a source editor or viewer for a particular language or document type, it is common to provide at least some rudimentary content assistants.
Removed the DOCTYPE entry at the beginning of the file and im now able to see the commands while typing ctrl+space...
To add to Uri's answer, you can define your own editor for your own language with XText as long as you have a simple EBNF grammar language for your DSL (domain specific language).
You will have:
syntax coloring,
model navigation (F3, etc.),
code completion,
outline view, and
code templates.
Here is a solution you can work. Actually I was facing a same problem with struts.xml file. I was not able to produce tags by cntrl+space
what i did was...
go to Preferences...Java...Editor...Content Assist...Advanced
check all the check-boxes ON and press OK.
sometimes the problem persists due to some false alarming in eclipse. If it happens, just delete your xml file and create a new one in same location.
I hope it will help.
I had the same issue while using the struts.xml file.
I got fix when I tried below...
Go to “Preferences>Java>Editor>Content Assist>Advanced“. Make sure “Java Non Types Proposals” are ticked on both the places as shown in the image below then click Apply and OK button:-