Page 1 of 1

Adding ObjectiveC Support

Posted: Tue Nov 20, 2012 2:05 pm
by Rosch
Hi Eran,

For a couple of days now I am using CodeLite and I like it! Great work! I would like to use it here inhouse as an IDE. But there is one big missing feature ObjectiveC support. We do have a large cross platform C/C++/ObjectiveC codebase and so I also will need ObjectiveC syntaxhighlighting and codecompletion in CodeLite in the same quality as the C++ support is done.

I am currently investigating the range of changes necessary to do this before I will start to implement this.
(When I got ObjectiveC support working I would like to contribute it back to CodeLite.) I am writting here in the hope to get some pointers on how to start most efficiently on this...

1. Syntax highlighting
As of now CodeLite uses wxStyledTextControl which in turn uses scintilla. Scintilla yet has no ObjC support so I need to add this here too. Plus at least some language definitions in wxWidgets itself. Right? I have seen that CodeLite itself has a bunch of own yacc and flex grammers/parsers for C++. For which purpose are they used?

2. Code Completion
CodeLite uses ctags/clang for code completion. Clang should be able to handle ObjC. Regarding ctags I have seen that codelite uses ctags 5.6. The official version of ctags is 5.8 which is already some years old. After the official release of ctags 5.8 an Objectice C parser was added to ctags (I believe in 2010) which appears to be mature. So updating ctags in codelite will be necessary. And of course Objective C semantics will be needed to get implemented in the codecompletion area of codelite itself.

Do I miss something here?

Thanks for your help,

Roland

Re: Adding ObjectiveC Support

Posted: Tue Nov 20, 2012 3:33 pm
by eranif
Rosch wrote:As of now CodeLite uses wxStyledTextControl which in turn uses scintilla. Scintilla yet has no ObjC support so I need to add this here too. Plus at least some language definitions in wxWidgets itself. Right? I have seen that CodeLite itself has a bunch of own yacc and flex grammers/parsers for C++. For which purpose are they used?
Adding syntax highlight is an easy task

From the wiki:
http://www.codelite.org/LiteEditor/AddingNewLexer
Rosch wrote:Clang should be able to handle ObjC
clang is the way to go, as it was primary written for ObjectC (well, it was developed by Apple...)
Ignore ctags - you can enforce it within codelite for opbjective C files ( you need to add new ObjectiveCContext class which derives from ContextBase, similar to ContextCpp)
Rosch wrote:The official version of ctags is 5.8 which is already some years old
codelite is not really using ctags, it uses a libctags (a modified version of ctags which can be used as a library and not as an external executable). In addition, it contains many updates I made to ctags (better template handling, better replacements and much more)

In the ObjC context class you handle all the indentation, go to impl/decl, provide a context menu etc.

If you are interested in creating ObjC support, join our IRC channel for better communication (you can ask questions there and either me "eranif" or David "DavidGH" will be able to assist you)

codelite IRC:
#codelite @ irc.freenode.net

Eran

Re: Adding ObjectiveC Support

Posted: Tue Nov 20, 2012 6:49 pm
by Rosch
Hi Eran,
eranif wrote: If you are interested in creating ObjC support, join our IRC channel for better communication (you can ask questions there and either me "eranif" or David "DavidGH" will be able to assist you)
Thanks for you reply. I will first take some more look at the insides of codelite and than I am sure I will pop up at the IRC channel within the next days...

Roland

Re: Adding ObjectiveC Support

Posted: Wed Nov 21, 2012 12:26 pm
by Rosch
Hi Eran...

As the IRC channel seems to be orphaned at present I am writting here...
eranif wrote: Adding syntax highlight is an easy task

From the wiki:
http://www.codelite.org/LiteEditor/AddingNewLexer
I wanted to start out with this, but:
On http://www.codelite.org/LiteEditor/AddingNewLexer it is written that a lexer node needs to have an Id attribute
the Id attribute needs to correspond to a given wxSTC_LEX define from wxwidgets stc.h
but well there I cannot find any id for objective C
as far as I understand it the ids are originating from scintilla

Roland


so I need to start with adding ObjC support to Scintilla and wxWidgets first?

Re: Adding ObjectiveC Support

Posted: Wed Nov 21, 2012 7:10 pm
by eranif
From what I can see, the ObjC should be handled by the C++ lexer
So you can copy the C++ lexer definition.

You should only modify the "<Extensions>" element content

FYI:
wxStyledTextCtrl is just a bridge to scintilla http://scintilla.org - so if anything is missing it should be added to scintilla first
As the IRC channel seems to be orphaned at present I am writting here...
post your question and keep your session logged in - eventually someone will reply

Eran

Re: Adding ObjectiveC Support

Posted: Fri Nov 23, 2012 6:02 pm
by Rosch
So...

After being blocked with other things the last days I have spent now some time on this.
Just a brief summary before I have to leave my desk for the weekend...

1. Syntax highlight
As suggested I gave the lexers xml a chance and added my stuff there. I added a new section for ObjectiveC using Id=3 (as it is done for C++ and Java) and tweaked it a little bit. Especially the keyword sections. It works quite well for files with suffix .m (as they are used for the implementations of ObjectiveC classes). ObjC declares its classes (like C++) in headerfiles where it comes to a problem now. The suffix .h is already registered as extension for C++ so the header files get syntax highlighted by the definitions for C++. Not the result I would like to have. My suggestion as a solution for this problem would be to merge the ObjectiveC syntaxhighlight style into the C++ style which is possible. I tried it and it does not seem to have a bad impact on C++ files (as far as I have checked it up to now).

So my suggestion would be to turn the "C++" Syntax highlighter into a "C/C++/ObjectiveC" highlighter. What do you think about it?

2. General integration
Also I started out integrating Objective C as a language in general which means:
- pixeled a 16x16 ObjC fileicon and added it to both icon sets.
- added .m to the fileextensionmanager
- added the icon to the bitmap loader, the file tree view, the newitem dialog and some other places
So ObjectiveC files are now clearly visible as being ObjectiveC in CodeLite.

How do you want my changes backmerged (if you want to have them)?
In one big block or is it more comfortable for you to get them in smaller packages for easier review?

Roland

Re: Adding ObjectiveC Support

Posted: Mon Nov 26, 2012 10:31 am
by eranif
Rosch wrote:So my suggestion would be to turn the "C++" Syntax highlighter into a "C/C++/ObjectiveC" highlighter. What do you think about it?
Good idea
Rosch wrote:How do you want my changes backmerged (if you want to have them)?
Improvements are always welcomed. Please send them as a single patch

HOW TO SUBMIT A PATCH

Eran

Re: Adding ObjectiveC Support

Posted: Wed Nov 28, 2012 2:16 pm
by Rosch
Hi Eran,
eranif wrote:
Rosch wrote:So my suggestion would be to turn the "C++" Syntax highlighter into a "C/C++/ObjectiveC" highlighter. What do you think about it?
Good idea
Here comes the patch for doing this.
I mainly changed the lexers name to "C/C++/ObjectiveC" and added a bunch of keywords for ObjC internals (keywords0), ObjC Foundation base classnames (keywords1) and ObjC protocols (keywords3). I also made some names for the individual highlighters a little more generic.

I could not find any negative effects in highlighting C++ files with the changed lexers, yet.

And well I got a suggestion to make merging back lexers maybe a little easier:
The lexers default files in Runtime/lexers appear to be handcrafted. When CodeLite loads them and stores them to the .codelite or AppData folder it reformats them. The lexers are sorted, reindented and XML attributes get moved around. I would suggest to keep the default lexer files in SVN already in the form codelite itself saves them. This would make generating patches for the lexers and merging them back easier. The patch for the C++ lexer is already in the "CodeLite-cooked" form.

Roland