Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Identify caller of formatter(How can I determine in a plugin who called the formatter and for which file?)
Identify caller of formatter [message #1681366] Tue, 17 March 2015 09:30 Go to next message
Martin SchulzeFriend
Messages: 2
Registered: March 2015
Junior Member
I am working on a formatter plugin that integrates clang-format with Eclipse CDT (clang_format_eclipsecdt on github (I cannot post links to other sites right now)).
Unfortunately, the fundamental models of these two are somewhat different.

The formatter in Eclipse (CDT) only knows the source string and the sections to format while clang-format works with files and sections thereof.
This means clang-format expects a path to the file which is used to find the .clang-format file which contains the formatter settings (tabs vs spaces, indent width, ...) which is not available to the formatter.

I was able to work around this for the basic usecase of formatting the currently edited file.
However, the formatter is used in more cases which gives me some trouble:

When selecting clang-format as formatter in the settings, the example code has no corresponding file which does not allow for finding the corresponding .clang-format file.

When using refactoring tools the situation gets worse as the formatter exceptions disable the refactoring.

I like the interface of the Formatter but it does not integrate well with the task at hand. I doubt that this interface will be changed so I ask for your help in working around it.

As hard as it might be, my plan is to detect all different usages of the formatter and supply sensible results.

This means I not only have to sense the calling function of the formatter but also find the appropriate file path to pass to clang-format.

This is where this forum comes into play:
Do you know of any (reliable) way to detect when the formatter is called

- from the editor,
- from the refactoring tools,
- from the settings example code, or
- from other locations?

Currently I am able to retrieve the file's path for the first case but I have no idea how
can I find the path of the file the refactoring tool is about to insert code into.
I also need to find the path to the workspace and the project for the code example when the formatter is selected in the settings and project properties but I assume this is easier.

Any help or pointers would be greatly appreciated.

[Updated on: Wed, 18 March 2015 11:30]

Report message to a moderator

Re: Identify caller of formatter [message #1684343 is a reply to message #1681366] Wed, 18 March 2015 11:38 Go to previous message
Martin SchulzeFriend
Messages: 2
Registered: March 2015
Junior Member
In the CCodeFormatter source of CDT I found the function getTranslationUnit which gets the path to the currently formatted translation unit from the formatter options.
As far as files are used, this solves the problem of identifying the file path.

However, this does not work with the code example in the C/++ formatter selection page.
So these questions remain:
How do I detect whether the formatter has been called for this example from workspace settings or from project properties?
Are there more instances where the formatter does not get fed a file path?
Previous Topic:requiring build all before run and debugger not working
Next Topic:include search path confusion
Goto Forum:
  


Current Time: Fri Apr 19 00:45:04 GMT 2024

Powered by FUDForum. Page generated in 0.01549 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top