Zitat von Bernd Kreuss <[email protected]>:

Mattias Gaertner wrote:

I wrote an example in codebrowser.pas:
function TCodeBrowserView.GetCodeHelp

Thank you for this example. Now you effectively implemented almost all
the things I wanted to do.

Sometimes it is easier to implement than to explain it in English. And I think in this case the implementation explains it better.


My latest (not working) version before I read your answer was using
Tool.BuildSubTreeAndFindDeepestNodeAtPos() and
Tool.MoveCursorToProcName() and Tool.MoveCursorToPropName() and *almost*
worked (worked in some cases but not always), sometimes the node that it
returned was correct, sometimes it did not make any sense at all and
began and ended at some completely wrong positions and had a completely
wrong Desc.

Maybe you had edited in the source editor and not updated the code browser.
The code browser is meant to search hundreds of units which takes some time to scan. It would slow down the IDE quite a bit if it would update constantly.


(btw: what is a "clean" position and what is the difference
between just the absolute position and the clean position? Is this
important or is there no difference at all? At one Point I tried a
method that looked like it was supposed to convert column and line to a
"cleanpos" but it returned a number three times as large as the entire
file size)

See here
http://wiki.lazarus.freepascal.org/Codetools#How_the_codetools_parses_sources.2C_difference_to_a_compiler


Please don't remove your comments in this example again, although they
might seem obvious to anybody who knows the codetools, they are very
helpful and explain things about the codetools that are not obvious from
looking at the code alone. I would have for example never found the
method CodeToolBoss.Explore() or known that I needed to call it (I have
seen some of the examples but I didn't notice this method call before,
probably because it is implicitely called by something else)

Every function has its pros and cons. Explore is great for the code explorer, but is often too much for simple tools. Doing too much means more things can go wrong. For example it can stop on syntax errors, that might be irrelevant for the intended function. And of course it can be too slow, for example when invoking it on every compiler hint/error/warning.


and also I
don't know what exactly LazarusIDE.BeginCodeTools() does.

It does some basic checks and commits the changes of the source editor to the codetools file caches.


Because I felt that the reason for BuildSubTreeAndFindDeepestNodeAtPos()
sometimes but not always returning anything useful was that the tool
itself was not properly initialized, I was looking for something that
would tell the tool to properly initialize itself and parse the whole
file but I looked for a method of the codetool class and not a method of
the codetoolboss. I tried Tool.BuildTree() but it didn't seem to help.

BuildTree is often enough.
CodeToolBoss is the next level and handles multiple units.
For example it checks if the main source has changed.


The understanding of the codetools seems to be essential for doing any
non-trivial thing inside the IDE. We need a document that describes the
architecture of the codetools, the lifespan of such a tool, when and how
to create it or where to find an instance of an already initialized
tool, how to properly initialize it, what does happen internally when
initializing it, generally what is going on inside these tool objects,
what is needed for them to operate, what should be avoided, what can go
wrong when using them, what is the codetoolboss and what is its role in
this whole thing (I have now seen at least 3 or 4 ways of how and from
where to get such a codetool instance and they all look slightly
different), what steps are done by the boss and what steps are done by
the tool, How does the whole containment hierarchy of these objects that
are found "inside" (or belong to) other objects look like (maybe
visualize it with a diagram), etc.

Another day.

Mattias




--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to