Page 1 of 1
Add auto-complete support for macros of structures
Posted: Sun Nov 06, 2016 11:53 pm
by Mistrel
I cannot use auto-completion with macros of structures. I'm transitioning to using macros more widely in my projects and this is creating a problem.
Code: Select all
Structure SomeStruct
Field.i
EndStructure
Macro MACRO_STRUCT
SomeStruct
EndMacro
Define a.SomeStruct
Define b.MACRO_STRUCT
;/ Auto-completes OK
a\Field
;/ Does not auto-complete
b\
Procedure SomeProc(a.SomeStruct, b.MACRO_STRUCT)
;/ Auto-completes OK
a\Field
;/ Does not auto-complete
b\
EndProcedure
Re: Add auto-complete support for macros of structures
Posted: Mon Nov 07, 2016 12:49 pm
by #NULL
you might know, but freak explained here why this is not working currently:
http://www.purebasic.fr/blog/?p=417
but you could trick the IDE if you really need to.
Code: Select all
Structure SomeStruct
Field.i
EndStructure
CompilerIf 0
Structure MACRO_STRUCT
Field.i
EndStructure
CompilerEndIf
Macro MACRO_STRUCT
SomeStruct
EndMacro
Define a.SomeStruct
Define b.MACRO_STRUCT
;/ Auto-completes OK
a\Field = 123
;/ Does not auto-complete
b\Field = 234
Procedure SomeProc(*a.SomeStruct, *b.MACRO_STRUCT)
;/ Auto-completes OK
*a\Field = 456
;/ Does not auto-complete
*b\Field = 678
EndProcedure
Re: Add auto-complete support for macros of structures
Posted: Tue Nov 08, 2016 10:23 am
by Mistrel
Thanks for the work-around.
This adds a LOT of duplicate definitions and bloat though.
Re: Add auto-complete support for macros of structures
Posted: Tue Nov 08, 2016 7:29 pm
by freak
I don't really understand the specific use case here. Why do you need a macro in this case?
If you just want to define an alias for the structure, just use the "Extends" keyword:
Code: Select all
Structure SomeStruct
Field.i
EndStructure
Structure MACRO_STRUCT Extends SomeStruct: EndStructure
Define a.SomeStruct
Define b.MACRO_STRUCT
;/ Auto-completes OK
a\Field
;/ Does not auto-complete
b\
Procedure SomeProc(a.SomeStruct, b.MACRO_STRUCT)
;/ Auto-completes OK
a\Field
;/ Does not auto-complete
b\
EndProcedure
The IDE can resolve this properly. No macro required.
Re: Add auto-complete support for macros of structures
Posted: Tue Nov 08, 2016 9:23 pm
by Mistrel
I use macros like this by convention in other languages like C and C++ and it's convenient to keep this consistent when updating code back and forth. It's also convenient to see what macros are available for various types in the Procedures tab in the IDE.
Would it be possible to support my particular use case?

Re: Add auto-complete support for macros of structures
Posted: Wed Nov 09, 2016 7:56 am
by Mistrel
I looked at using the a structure with the Extends keyword but would still rather use macros even with the added code bloat. The added use of structures causes a mess in the debugger by creating variations of the same structure when viewing variables where they should be the same type. It also screws with my convention in the debugger as well.
For example, I use all-caps only for macros so seeing it as a structure is hiding the actual structure it's supposed to be using which makes things harder to read. I have to go back and figure out what is being extended.
I hope this makes sense.
Re: Add auto-complete support for macros of structures
Posted: Wed Nov 09, 2016 2:53 pm
by #NULL
probably not useful in your case, but funnily autocompletion as well as debugger tooltips are working if a macro is used in the structure definition.
Code: Select all
Macro MACRO_STRUCT
SomeStruct
EndMacro
Structure MACRO_STRUCT
Field.i
EndStructure
Define a.SomeStruct
Define b.MACRO_STRUCT
a\Field = 123
b\Field = 234
Procedure SomeProc(*a.SomeStruct, *b.MACRO_STRUCT)
*a\Field = 456
*b\Field = 678
ProcedureReturn
EndProcedure
SomeProc(a, b)
Re: Add auto-complete support for macros of structures
Posted: Thu Nov 10, 2016 3:20 am
by Mistrel
That is horrible. But I can see that it does indeed work and may be the least painful way of implementing it with regards to code bloat and not having to maintain duplicate structures.
Now that I've seen it I don't know if I can ever un-see it..
Re: Add auto-complete support for macros of structures
Posted: Thu Nov 10, 2016 7:07 pm
by freak
You can also combine #NULLs first suggestion with mine to get this:
Code: Select all
Structure SomeStruct
Field.i
EndStructure
; This is just for IDE support
CompilerIf 0
Structure MACRO_STRUCT Extends SomeStruct
EndStructure
CompilerEndIf
Macro MACRO_STRUCT
SomeStruct
EndMacro
; ...
This way you at least don't have to keep multiple structure definitions in sync.
The thing is that macro expansion simply does not fit into the way the whole AutoComplete feature currently works (see the blog post mentioned above). I see no way to add it so that it really works in all circumstance without doing pretty much an actual compilation of the code. A feature that works only in simple circumstances will look like a buggy feature and cause more frustration than help. So I don't think macro expansion will be possible in AutoComplete any time soon.
Re: Add auto-complete support for macros of structures
Posted: Fri Nov 11, 2016 8:35 am
by Mistrel
That's probably the best compromise as it keeps the layout I want with structs and macros.
Thanks for the tips.