Code Completion/Intellisense

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Code Completion/Intellisense

Post by pwdiener »

I'd like to explore the possibility of getting intellisense working for a COBOL program or project. I think it would be helpful, but COBOL does not lend itself to this very well.

First question - I know that intellisense is triggered by a '.' or '->'. Is this configurable? Neither of this would be especially natural to a COBOL programmer. This isn't a big deal, but would be nice to know.

For COBOL, it seems like what might be useful is a way to autocomplete variables or procedure (paragraph) names. I'm considering using V. or P. to trigger this. What would I have to do with tags to get this to the point where I could try it out and see how well it flows for me? I can get the appropriate tags generated, but which ones and set up how?

Another question - does autocomplete work with templates at all?

What would really be cool is to be able to participate via a macro in the intellisense process. For instance, if I trigger a procedure name lookup with P., I'd like to be able to get rid of the P. after I select one, or, if I keep typing until there is no possible existing procedure name that matches, get a chance to go add such a procedure and then come back to the original point of entry. The latter, at least, seems like it might be generally useful, not just for COBOL. Is there any way to do this?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

First question - I know that intellisense is triggered by a '.' or '->'.

That is correct. The :: characters also triggers intellisense.
Is this configurable?

No. These triggers are common for all the languages for which the intellisense works and are hard coded into the engine.
Neither of this would be especially natural to a COBOL programmer. This isn't a big deal, but would be nice to know.

Any suitable trigger can be used for intellisense. It will be hard coded into the engine, but any character(s) can be used.
For COBOL, it seems like what might be useful is a way to autocomplete variables or procedure (paragraph) names.
You do realise there already exists the TagsCompleteEx function. It will autocomplete variables/procedures from the tags database.

For example consider this code where | is the cursor:

Code: Select all

A|
The TagsCompleteEx function will display all tags that start with A .
I'm considering using V. or P. to trigger this. What would I have to do with tags to get this to the point where I could try it out and see how well it flows for me?

This would have to be coded into the intellisensing engine. So are you suggesting that V. displays all variable tags and P. displays all procedure tags.

Then when the user selects a variable of procedure from the autocomplete list the V., P. is replaced by the selected item.

Which tags do you define as variables and which ones are procedures :?:

I would say it should be possible to implement something like this into the engine.
Another question - does autocomplete work with templates at all?

The TemplateComplete function will autocomplete the templates.
What would really be cool is to be able to participate via a macro in the intellisense process. For instance, if I trigger a procedure name lookup with P., I'd like to be able to get rid of the P. after I select one,
I would see the intellisense doing exactly that.
or, if I keep typing until there is no possible existing procedure name that matches, get a chance to go add such a procedure and then come back to the original point of entry. The latter, at least, seems like it might be generally useful, not just for COBOL. Is there any way to do this?
This should also be possible since the macro just runs the TagsCompleteEx function. Then based on the return value of this function you can tell if the user selected an item or just cancelled the autocomplete, because the function was not in the list.

Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Jussi,

What I was trying to get at is a way to experiment with intellisense/code completion WITHOUT having you change anything. I'm able to manipulate how tags are generated, and it was my thought to create classes called V and P, with members as appropriate. Once I figure out if this is worth pursuing, then I might ask you to consider some changes, but right now I'd just like to experiment and get a feel for how these features might be made to work in COBOL.

What types of tags are considered for intellisense/code completion? I'm assuming that the . or -> trigger a look at what is in front of it, tries to find a tag of a particular type that matches, and then will show related elements like class properties/data/methods or structure members. Is this correct?

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Bill,
What I was trying to get at is a way to experiment with intellisense/code completion WITHOUT having you change anything.

The process of intellisensing is fairly complex so in most cases it is not really possible to implement without making a change to the core code :(
What types of tags are considered for intellisense/code completion? I'm assuming that the . or -> trigger a look at what is in front of it, tries to find a tag of a particular type that matches, and then will show related elements like class properties/data/methods or structure members. Is this correct?

This is where the complexity begins ;)

Consider a simple C/C++ intellisensing for example.

If the user types in . or a -> the word before the dot is the key.

Now Zeus knows for these characters the word must be a class or a variable so it goes looking for a class or variable tag with that name in the tag database.

If the user types in a ( then Zeus knows the word is a fucntion so it goes looking for a function or method tag with that name in the tag database.

Things get more complicated when the user types in something like function()->a->b->c. which could well be valid C/C++ code.
Once I figure out if this is worth pursuing, then I might ask you to consider some changes
I have been toying with the idea of adding a display_tags function to the scripting engine :?

The idea would be this function would allow the user to display the intellisense listbox for a given set of tags from within a script.

So for example you could write a script to display the COBOL V tags and another to display the COBOL P tags and then bind both scripts to different keyboard keys or the menu.

The display_tags scripting function would also take an optional name filter argument. For example the script could written to check for the previous word. So for example if the user typed in AA and then ran the V tags script all tags starting in AA would be displayed.

What do you think :?:

Would that sort of functionality be of any use :?:

Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Jussi,

So Tag_Class and Tag_Variable are used for data type references? So the word before must be a class or variable (structure?), and then the list of associated tags is shown?

COBOL programs effectively define all data as global to the program, and all PERFORMed procedures as global too. It seems to me that if I arranged to have a class of V, and each variable in the program associated with the class V, I might get what I want.

The potential issue would be scoping - the names should only be known in the program that defines them. Is there any convenient way to get Zeus to only look at the current program? That's not perfect because it's common to COPY hunks of definitions or code from "include" files. I'm not sure what the best way to deal with that would be - I could possibly deal with it in the tagger, but I'd have to think that one through.

The display_tags function sounds very interesting and potentially useful. I can envision how I might use that to accomplish things that sound like they might be useful. I'm assuming that the function would accept a tag type to be displayed. I'd be interested in beta testing this if/when you decide to do it.

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Bill,
So the word before must be a class or variable (structure?)
In fact the word could be a class, structure, variable, enumeration or interface tag.
and then the list of associated tags is shown?
The intellisense does the search and returns the first tag found, but what gets displayed depends on what tag was is found.

For example if the tag found is a function of a variable, only a tooltip is displayed (i.e. there is no more information available for these tags).

If the tag found is a class, structure, interface or enumeration then the listbox is displayed (i.e. these tags can have any number of methods and/or variables and this is what gets displayed in the listbox).

To better understand how this all works, I suggest creating a new empty Zeus workspace and adding this test.cpp file to that workspace:

Code: Select all

int MyVariable;

int MyFunction(int argument1, int argument2);

enum MyEnum { one, two, three };

class MyClass
{
public:
  int value;

public:
  MyClass();
  virtual ~MyClass()

  int method() { return 1 }
};

class MyStructure
{
public:
  int value;

public:
  MyStructure();
  virtual ~MyStructure()

  int method() { return 1 }
};
Now open the test.cpp file, use the File, New menu to create a new cpp file and paste in the following code:

Code: Select all

MyClass a;

a.

MyStructure b;

b.

MyEnum.

MyVariable.

MyFunction(
If you overtype the . and ( in the code above you will see the intellisense fire and get a better idea of how it all works.

This is what I mean when I say the intellisense behaviour is hard coded into Zeus. Certain tags work in certain ways and that behaviour is fixed.
It seems to me that if I arranged to have a class of V, and each variable in the program associated with the class V, I might get what I want.
If look at the class browser for the workspace above you will see how the ctags.exe tagged the C++ code.

It should be clear from the class browser why the class, enumerator, and structure tags display in a listbox while the others get displayed as a tooltip.

If your new COBOL tags also create tag data that is similar to this and display in class browser in a similar fashion then if the new macro function is added, similar behaviour should be possible.
Is there any convenient way to get Zeus to only look at the current program?
If you look at the class browser for the example above there is a node named Project Files, test.cpp and you will notice the browser knows exactly which tags belong to which file.

I suspect it should be possible to design this new macro script function to use this knowledge and limit the search to just tags within the current file.
The display_tags function sounds very interesting and potentially useful. I can envision how I might use that to accomplish things that sound like they might be useful.

I think adding the macro function would be the easiest way to implement the intellisense for COBOL.

I see this function as doing nothing more than allowing searches to be done against the data shown in the class browser and depending of the results, displaying the data in a listbox or as a tooltip.

But since it has been decades since I wrote any COBOL I am really not sure if this sort of functionality would be usesful. It really depends on what information is being extracted by the ctags.exe and how it is stored in the class browser.

For it to have any chance of working the COBOL ctags data has to be in a similar format to what is shown in the class browser for the example above.
I'm assuming that the function would accept a tag type to be displayed. I'd be interested in beta testing this if/when you decide to do it.

I think two functions something like this should do the trick:

Code: Select all

search_tag(tag_type, [optional string filter]

Code: Select all

search_tag_file(string file name, tag_type, [optional string filter]
These functions would then do different things depending on the results.

If nothing was found a message is displayed in the status bar.

If one tag item is found either a listbox or tooltip will be displayed depending on the type of tag found.

If more than one tag is found a listbox will be displayed containing the names of all the tags found.

Cheers Jussi
pwdiener
Posts: 134
Joined: Wed Jul 11, 2007 3:45 pm

Post by pwdiener »

Jussi,

I can get started with that.l I'll work on the tagger - that should be fairly straightforward.

The search_tags functions sound like it would be quite useful. I await it eagerly.

Even though I've written lots of COBOL, I'm also not sure if intellisense will be useful or just a pain. The IDE that others are using here has a lame attempt at implementing it, but most people turn it off because it is so lame. I like the intellisense in VS, and what I've seen in my limited testing in Zeus looks like it would be very useful. One of the keys is speed, so it will be interesting to see if a program with hundreds or thousands of variables will hold up.

Does intellisense make any attempt to track the entry of function parameters like VS?

BTW, I think I found a bug in the code completion. If you select one of the entries in the list box using the cursor without typing any character, then press tab, only a tab is put in the code. Is this intended?

Bill
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Bill,
The search_tags functions sound like it would be quite useful. I await it eagerly.

I have made some progress on adding this function to the scripting engine and based on some very limited testing it seems to work well :)

I will send you an e-mail with a link to a beta version for you to play with.
The IDE that others are using here has a lame attempt at implementing it, but most people turn it off because it is so lame.
When the intellisense gets in the way it can be really annoying.
I like the intellisense in VS, and what I've seen in my limited testing in Zeus looks like it would be very useful.
The intellisense in VS is intellisense on steroids.
One of the keys is speed, so it will be interesting to see if a program with hundreds or thousands of variables will hold up.

For me speed does not seem to be a problem. Zeus seems to work as fast as VS.
Does intellisense make any attempt to track the entry of function parameters like VS?

No.
BTW, I think I found a bug in the code completion. If you select one of the entries in the list box using the cursor without typing any character, then press tab, only a tab is put in the code. Is this intended?

Yes this is intended. The only way to accept a selection is to hit the enter key or to double click on the item using the mouse. Many other input keys will just cancel the dialog.

The idea is you can basically ignore the intellisense dialog and just keep typing. If you type enough then eventually the dialog will just go away by itself ;)

Cheers Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

The search_tags functions sound like it would be quite useful. I await it eagerly.
This feature is now in the latest release: http://www.zeusedit.com/forum/viewtopic.php?p=4766

Refer to the Zeus help file for the tags_display and the tags_display_file marco scripting functions.

Cheers Jussi
Post Reply