Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » type hierarchy and code completion
type hierarchy and code completion [message #25134] |
Mon, 09 June 2008 12:54  |
Eclipse User |
|
|
|
I now see how your code uses a visitor class to build your model of each
source file/module/script.
This is equivalent but independent of the AST tree:
SourceModule (implements ISourceModule)
SourceType (implements IType)
SourceMethod (implements IMethod)
SourceField (implements IField)
I noticed that IType declares two codeComplete methods.
Those methods are implemented as dummy/no-op methods.
Instead, it appears that (only?) ICompletionEngine.complete is used.
This appears to add a completion proposal for
a) any keyword
b) any named element within the source module (type, field, method)
My questions are:
a) Should everything in the language be part of the model?
If so, must I create
i) new model classes which extend the existing model classes
ii) new visitor classes to instantiate my my model classes (instead
of yours)
b) How do you envision referencing external modules/types/classes and
doing code completion of those (rather than limiting yourself to the current
source module)?
Thanks,
Chuck
|
|
| | | |
Re: type hierarchy and code completion [message #25655 is a reply to message #25299] |
Thu, 12 June 2008 18:02   |
Eclipse User |
|
|
|
Unfortunately, this doesn't work since ISourceModule passed to
ICompletionEngine.complete is not the same as ISourceModule passed to
SourceParserUtil.getModuleDeclaration.
I'm not sure why there are two ISourceModule interfaces.
package org.eclipse.dltk.core;
/**
* Represents an entire source module (source file). Module elements need to
be opened before they can be navigated or manipulated. The children
* appear in the order in which they are declared in the source. If a file
cannot be parsed, its structure remains unknown. Use
* {@link IModelElement#isStructureKnown} to determine whether this is the
case.
* <p>
* This interface is not intended to be implemented by clients.
* </p>
*/
public interface ISourceModule extends IModule,
ISourceReference,ISourceManipulation,ICodeAssist
----------------------------
package org.eclipse.dltk.compiler.env;
/**
* This interface denotes a compilation unit, providing its name and content.
*/
public interface ISourceModule extends IDependent {
"Chuck Doucette" <cdoucette@vaultus.com> wrote in message
news:g2kgmo$551$1@build.eclipse.org...
> Apparently, given the an ISourceModule I can get the corresponding
> ModuleDeclaration by calling:
>
> package org.eclipse.dltk.core;
> public class SourceParserUtil {
>
> public static ModuleDeclaration getModuleDeclaration(ISourceModule module,
>
> IProblemReporter reporter, int flags) {
>
> If it is already parsed, it will return the cached copy of the AST tree.
>
> If not, it will parse it (and thus it needs the IProblemReporter argument
> etc.)
>
> Is this an appropriate way to proceed?
>
> Thanks,
>
> Chuck
>
>
>
>
|
|
|
Re: type hierarchy and code completion [message #25847 is a reply to message #25134] |
Mon, 16 June 2008 01:03   |
Eclipse User |
|
|
|
Hi Chuck,
AST tree and Structure model are two different models.
AST is used to represent language internal strucures. Also AST are used to do completion, selection etc.
Structure model are used to represent only top level elements.
This model represent projects, folders, files, classes, methods, field.
Structure model are fixed and could not be extended by DLTK users.
Language implementor could map some langauge elements to structure model elements.
Using of structure model gives some free features like Script Explorer, outline, basic search.
Some time ago we thinked about a way to show custom content fromd all generic DLTK views.
Then will be possibly to display any kind of information.
>I noticed that IType declares two codeComplete methods.
>Those methods are implemented as dummy/no-op methods.
This is JDT lagacy code, which is not realy used from anythere in DLTK.
How to get AST from ICompletionEngine.complete()
Original idea is to parse content with some advanced completion parser and build some completion model.
For example in Tcl we use Tcl AST tree but with some additional processing, required for completion only.
Two ISourceModule interfaces are also JDT legacy.
JDT guys use similar class then they need completion for some code parts, then no real ISourceModule are exists.
In DLTK we also could use this classes in same context, but not do it yet.
For example completion from wizards, breakpoint configuration view, etc.
>b) How does one make use of declarations from another module, i.e. Java import?
You could obtain ISourceModule from search, or using some other way. For example for python it will be eacy to get
current ISourceModule
parent and check for imported module name. etc.
For examples of how to use search please look to SearchTests class from org.eclipse.dltk.tcl.core.tests project,
and AbstractDLTKSearchTests class from org.eclipse.dltk.core.tests project.
Mixins:
Some of scripting lanuages could have declarations from more then one file.
For example Tcl namespace could be declared from any set of files.
Same thing is for Ruby classes, modules.
Example:
file1.rb:
class MyClass
def myMethod()
end
end
file2.rb:
class MyClass
def myMethod2()
end
end
In runtime Ruby will see both methods.
Mixin model is intended to handle search in such langauges.
Mixin model in two words:
1) From Script Builder for each type, method, field we report special keys.
Key represent path to element decoded as string, and could contain subkeys.
Example of keys for previous Ruby code:
file1.rb:
MyClass
MyClass{myMethod
file2.rb:
MyClass{
MyClass{myMethod2
In this example MyClass{myMethod2 is subkey for MyClass
2) MixinModel user could ask for elements by key. Mixin will search for all subkeys, and build tree of elements.
For example if we ask for MyClass we wil recieve easy way to iterate all it's children.
Also language mixin parser could report some object instances, and we could do correct completion, selection, without
additional searchs.
Best regards,
Andrei Sobolev.
|
|
|
Re: type hierarchy and code completion [message #26052 is a reply to message #25847] |
Mon, 16 June 2008 19:05  |
Eclipse User |
|
|
|
Thanks very much for your response.
I am currently casting: org.eclipse.dltk.compiler.env.ISourceModule as
org.eclipse.dltk.internal.core.SourceModule since it also implements
org.eclipse.dltk.core.ISourceModule.
I need the latter type of ISourceModule interface in order to call
SourceParserUtil.getModuleDeclaration.
The information I capture in my AST tree (and some associated structures) is
used to implement my complete method rather than depending solely on the
internal structure model which your example used to implement completion.
I wasn't sure how to implement import (as in Java). You have given me some
ideas on how to do that.
I thought maybe mixin was involved which is why I asked about it.
Apparently, it is not, but thanks for providing insight into it anyhow.
Chuck
"Andrei Sobolev" <haiodo@xored.com> wrote in message
news:g34s7g$ggg$1@build.eclipse.org...
> Hi Chuck,
>
> AST tree and Structure model are two different models.
> AST is used to represent language internal strucures. Also AST are used to
> do completion, selection etc.
>
> Structure model are used to represent only top level elements.
> This model represent projects, folders, files, classes, methods, field.
>
> Structure model are fixed and could not be extended by DLTK users.
> Language implementor could map some langauge elements to structure model
> elements.
> Using of structure model gives some free features like Script Explorer,
> outline, basic search.
>
> Some time ago we thinked about a way to show custom content fromd all
> generic DLTK views.
> Then will be possibly to display any kind of information.
>
> >I noticed that IType declares two codeComplete methods.
> >Those methods are implemented as dummy/no-op methods.
> This is JDT lagacy code, which is not realy used from anythere in DLTK.
>
> How to get AST from ICompletionEngine.complete()
> Original idea is to parse content with some advanced completion parser and
> build some completion model.
> For example in Tcl we use Tcl AST tree but with some additional
> processing, required for completion only.
>
> Two ISourceModule interfaces are also JDT legacy.
> JDT guys use similar class then they need completion for some code parts,
> then no real ISourceModule are exists.
> In DLTK we also could use this classes in same context, but not do it yet.
> For example completion from wizards, breakpoint configuration view, etc.
>
> >b) How does one make use of declarations from another module, i.e.
> >Java import?
> You could obtain ISourceModule from search, or using some other way. For
> example for python it will be eacy to get current ISourceModule
> parent and check for imported module name. etc.
>
> For examples of how to use search please look to SearchTests class from
> org.eclipse.dltk.tcl.core.tests project,
> and AbstractDLTKSearchTests class from org.eclipse.dltk.core.tests
> project.
>
> Mixins:
> Some of scripting lanuages could have declarations from more then one
> file.
> For example Tcl namespace could be declared from any set of files.
> Same thing is for Ruby classes, modules.
>
> Example:
> file1.rb:
> class MyClass
> def myMethod()
> end
> end
>
> file2.rb:
> class MyClass
> def myMethod2()
> end
> end
> In runtime Ruby will see both methods.
>
> Mixin model is intended to handle search in such langauges.
> Mixin model in two words:
> 1) From Script Builder for each type, method, field we report special
> keys.
> Key represent path to element decoded as string, and could contain
> subkeys.
> Example of keys for previous Ruby code:
>
> file1.rb:
> MyClass
> MyClass{myMethod
>
> file2.rb:
> MyClass{
> MyClass{myMethod2
>
> In this example MyClass{myMethod2 is subkey for MyClass
>
> 2) MixinModel user could ask for elements by key. Mixin will search for
> all subkeys, and build tree of elements.
> For example if we ask for MyClass we wil recieve easy way to iterate all
> it's children.
> Also language mixin parser could report some object instances, and we
> could do correct completion, selection, without additional searchs.
>
> Best regards,
> Andrei Sobolev.
|
|
|
Goto Forum:
Current Time: Wed Mar 19 19:54:14 EDT 2025
Powered by FUDForum. Page generated in 0.08305 seconds
|