Text Editor Autocomplete

Programming, for all ages and all languages.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Text Editor Autocomplete

Post by Neo »

How do you store the method names if you want to include a auto-complete feature in a text editor?
For e.g. the VC or VB editors provide a drop down menu of the method names as soon as you type in the object name followed by a "." (dot). How is this done? Do they store the methods in a database and read them off at runtime? or dop they just run through a definitions file and parse the method names there? or is it something else altogether?
And what would be an efficient data structure to have them in memory after you read them from disk?
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Text Editor Autocomplete

Post by Neo »

What if the method names are from a Java Source file. In this case there is no separate 'header' file where I could look up methods names, isn't it?
Only Human
AR

Re:Text Editor Autocomplete

Post by AR »

In C++, using Visual Studio. VS generates that list by parsing the header files that are included in the current file. (On the implementation side, VS parses the files when they are first included and stores the map in a parse database in the project folder, this greatly improves performance from having to reparse each time but can be a problem if you modify the headers)

In VB, Visual Basic looks through the objects (Since everything in VB is related to COM in some way) and enumerates the functions by examining the exported COM symbols, it then reads an associated information file to generate descriptions [I don't think the descriptions are included in the object, but I can't remember].

Java is more or less the same as VB, except instead of enumerating symbols, you use the builtin Reflector.

How to implement Intellisense could be any way you want, I imagine that you could simply examine the current line after each key press, if the line ends in '->'/'.'/'::', then try to determine the parent object then create a list control on top of the text area and add the valid sub objects/functions/variables to it. The most efficent way to store it would probably be a tree where highest parent object holds pointers to the subobjects which hold pointers to their subobjects, etc. (The objects would need to be in a linked list with the other objects in their section of the tree in order to cycle around during lookups)
rich_m

Re:Text Editor Autocomplete

Post by rich_m »

in a text editor , isnt the area we type in a normal "text box" or is it some other? like in vb we have the inbuilt-tool textbox is it tht wat is used?
AR

Re:Text Editor Autocomplete

Post by AR »

The code editors on Windows either use a custom designed textbox, or a subclassed standard text box. It's more likely the former, since hacking that much functionality into a normal textbox would probably be more trouble then it's worth.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Text Editor Autocomplete

Post by Neo »

So text-editor apps like notepad, context etc.. just use the normal TextBox (or RichTextBox) for text editing?
Only Human
Warrior

Re:Text Editor Autocomplete

Post by Warrior »

Yes with Intellisense.
AR

Re:Text Editor Autocomplete

Post by AR »

Notepad doesn't have intellisense...

But yes, Notepad is just a Windows standard Textbox, Wordpad is a standard RichTextBox.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Text Editor Autocomplete

Post by Perica »

..
Last edited by Perica on Tue Dec 05, 2006 9:42 pm, edited 1 time in total.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Text Editor Autocomplete

Post by Neo »

You know that nifty feature that lets you complete coding by filling it in.
For e.g. if you have a class called A with methods as shown

Code: Select all

class A{
    public int fn1();
    public char fn2();
   ...
}
when you use the intelli editor if you create a object of this say A obj1;

then when you type obj1. (with the dot) you get a drop down list of methods or attributes to choose from.
Nice isn't it?
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Text Editor Autocomplete

Post by Neo »

Check out the Visual Basic and Visual C++ editors as an example of this.
Only Human
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Text Editor Autocomplete

Post by Candy »

Used it, didn't like it (mainly the incredible slowdown on the full system right before it gives a useless hint). For me it mostly slows my system down when I'm quickly typing a load of code not caring about hints since I know them like the back of my hand.

On the other hand, nice to know it has a name.
Warrior

Re:Text Editor Autocomplete

Post by Warrior »

Oh, didn't see his question. I was answering his first one anyhow. I believe they use a standard text box with the Multiline property enabled. Wordpad uses a RichTextBox .
ark

Re:Text Editor Autocomplete

Post by ark »

Yes -- although "text box" sounds more like Visual Basic or C++ Builder speak -- notepad is nothing more than a Windows edit control that is dynamically resized to fill up its parent window and which has the ES_MULTILINE, ES_AUTOVSCROLL, and (depending on whether word-wrap is enabled) the ES_AUTOHSCROLL styles enabled. This is also why in older versions of Windows you'd get a message saying that a file was "too large for Notepad" and asking if you wanted to use Wordpad instead -- edit controls had a 65535-character limit.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrols.asp
ark

Re:Text Editor Autocomplete

Post by ark »

In fact, the Using Edit Control section in that link basically has the notepad implementation in it.
Post Reply