Recent

Author Topic: Change default type for code completion  (Read 4767 times)

Okoba

  • Hero Member
  • *****
  • Posts: 555
Change default type for code completion
« 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;

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: Change default type for code completion
« Reply #1 on: April 20, 2020, 07:22:38 pm »
AFAIK: no.

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 16193
  • Censorship about opinions does not belong here.
Re: Change default type for code completion
« Reply #2 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.
« Last Edit: April 20, 2020, 07:26:08 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Okoba

  • Hero Member
  • *****
  • Posts: 555
Re: Change default type for code completion
« Reply #3 on: April 20, 2020, 07:25:58 pm »
@Thaddy it still adds 'string' not 'mystringtype'

Thaddy

  • Hero Member
  • *****
  • Posts: 16193
  • Censorship about opinions does not belong here.
Re: Change default type for code completion
« Reply #4 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.
« Last Edit: April 20, 2020, 07:29:16 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Okoba

  • Hero Member
  • *****
  • Posts: 555
Re: Change default type for code completion
« Reply #5 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'.

Thaddy

  • Hero Member
  • *****
  • Posts: 16193
  • Censorship about opinions does not belong here.
Re: Change default type for code completion
« Reply #6 on: April 20, 2020, 07:31:38 pm »
If codetools is well written it should do that automatically.

Note I never used codetools (consciously)
If I smell bad code it usually is bad code and that includes my own code.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Change default type for code completion
« Reply #7 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
« Last Edit: April 20, 2020, 08:52:20 pm by winni »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: Change default type for code completion
« Reply #8 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