Lazarus

Miscellaneous => Suggestions => IDE/CodeTools => Topic started by: Okoba on April 20, 2020, 07:18:19 pm

Title: Change default type for code completion
Post by: Okoba on April 20, 2020, 07:18:19 pm
Hi,

Is there a way to change default types when you hit Ctrl+Shift+C to define a variable?
Code: Pascal  [Select][+][-]
  1. S := 'Test'
If I hit Ctrl+Shift+C it will add
Code: Pascal  [Select][+][-]
  1. var
  2. S: string;

But how can I change it to add my own string type?
Code: Pascal  [Select][+][-]
  1. var
  2. S: MyStringType;
Title: Re: Change default type for code completion
Post by: Bart on April 20, 2020, 07:22:38 pm
AFAIK: no.

Bart
Title: Re: Change default type for code completion
Post by: Thaddy on April 20, 2020, 07:24:25 pm
Code: Pascal  [Select][+][-]
  1. type mystringtype = type string;

Bart?

Has its own caveats but may be enough.
Title: Re: Change default type for code completion
Post by: Okoba on April 20, 2020, 07:25:58 pm
@Thaddy it still adds 'string' not 'mystringtype'
Title: Re: Change default type for code completion
Post by: Thaddy on April 20, 2020, 07:27:11 pm
A specialized type, like I declared, is distinct from its root type.
You need to read my example very carefully. And the docs.

Note it is still not perfect, but it does what you want.
Title: Re: Change default type for code completion
Post by: Okoba on April 20, 2020, 07:29:08 pm
It seems you did not understand my question.
I know how to define a new type. I want to change CodeTools to complete the code with my custom type not the default 'string'.
Title: Re: Change default type for code completion
Post by: Thaddy on April 20, 2020, 07:31:38 pm
If codetools is well written it should do that automatically.

Note I never used codetools (consciously)
Title: Re: Change default type for code completion
Post by: winni on April 20, 2020, 08:50:46 pm
Hi!

Yes a little bit of doc for the CodeTools is necessary.

In my case if you try "automagic" to define a float it is allways extended.
I never uses extended and for 64 Bit it is not defined - it is just a double.

I want to set my CodeTool definition for a float to a single or a double.

Until now: No answers. Nowhere.

Winni
Title: Re: Change default type for code completion
Post by: PascalDragon on April 21, 2020, 09:38:58 am
If codetools is well written it should do that automatically.

Note I never used codetools (consciously)

This has nothing to do with well written. If the codetools see the following:

Code: Pascal  [Select][+][-]
  1. a := 'whatever';

What do you think should it use as type for a? It does not know about any custom types. What to do if there are multiple type aliases? No, it will use the safest one, which is - if the string contains no characters that require WideChar - a String (otherwise a UnicodeString). This is correct in both $H+ and $H-.
TinyPortal © 2005-2018