Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Semantic highlight
mistar:
--- Quote from: perento on May 15, 2012, 07:36:37 am ---Hello mistar, may i ask what functions the plugin will be offered?
--- End quote ---
Basically, it should highlight the c++ syntax in a semantic way.
For example, in highlighting based on lexers, all identifiers have the same color.
In semantic highlight on the other hand, variables, types, functions, etc. are highlighted in different ways.
If you work for some time with semantic highlight and then switch back to the usual, lexer-based highlight,
you notice the difference as if you switch from lexer-based highlight to no highlight at all ;).
Some tools provide semantic highlight, eg. Eclipse CDT or KDevelop, but they lack a support for the new C++11 standard.
Also, both have internal parsers that are not developed to support the new standard.
Since libclang (see http://clang.llvm.org; nb. version 3.1 is about to be released) has the best support for the new standard
and it provides parser API, it is relatively easy to write a plugin for C::B.
So far I have written a very simple tool that highlights a source in a semantic way (so it can be done using manual styling in Scintilla).
Now I'm working on retrieving compiler options (include directories, defines, etc.) so that all declarations are accessible to the libclang parser
(otherwise it highlights fragments of code as invalid).
Since some options are given implicitly (eg. via `wx-config --cxxflags`) I'm using wxExecute to retrieve the options, but it messes up the C::B user interface
on C::B sturtup (it seems that wxAuiManager and wxExecute interfere in some way)... any ideas how to do this in another way?
(The output of C::B on stdout contains "caching results from `wx-config --cxxflags`", so maybe I can use this cache?)
I've tried also to do this in a separate thread but the thread freezes (perhaps wxExecute in not thread-safe).
@MortenMacFly: Thanks, I'll have a look.
perento:
Nice nice, i was looking for something to highlight user functions, classes, structures etc. and i was leaded to you thread.
Would like to see that plugin how it works, keep the work please :)
MortenMacFly:
--- Quote from: mistar on May 15, 2012, 11:03:03 am ---(it seems that wxAuiManager and wxExecute interfere in some way)...
--- End quote ---
They have nothing to do with each other.
--- Quote from: mistar on May 15, 2012, 11:03:03 am ---any ideas how to do this in another way?
--- End quote ---
Have a look at other plugins that run external tools (e.g. CppCheck, CScope or alike), you can see how its done there.
--- Quote from: mistar on May 15, 2012, 11:03:03 am ---(The output of C::B on stdout contains "caching results from `wx-config --cxxflags`", so maybe I can use this cache?)
--- End quote ---
This information is not available via a public interface.
--- Quote from: mistar on May 15, 2012, 11:03:03 am ---I've tried also to do this in a separate thread but the thread freezes (perhaps wxExecute in not thread-safe).
--- End quote ---
We use threads a lot in C::B if yours freezes then you did something wrong. You can even use the thread abstractions available via the SDK for such purposes. Again: Have a look how other plugins do it (i.e. ThreadSearch).
mistar:
Hi guys!
Before my work on SemanticHighlight plugin goes on, let me introduce simple SHTool plugin I've just written
to demonstrate what can be achieved. The sources are attached.
This is a very simple tool plugin that colorize the syntax in a semantic way using hardcoded styles that I like
(see the sources).
To revert the styles to original ones just reopen the file.
I've tested it with C::B 10.05 and with latest svn version (with change of sdk version in manifest.xml to 1.13.2).
The plugin works best with project files (with all compiler options and search directories set up correctly).
The plugin links against libclang.so so you have to install clang first.
Also note that parsing a file from scratch takes some time (when editing a file there are some optimizations
so in the final version it should take no more than a second).
Have fun!
oBFusCATed:
--- Quote from: mistar on May 16, 2012, 08:11:45 pm ---Also note that parsing a file from scratch takes some time (when editing a file there are some optimizations
so in the final version it should take no more than a second).
--- End quote ---
A second for every key press? :)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version