Recent

Author Topic: Enabling Code Completion (a la Notepad++)?  (Read 5973 times)

FiftyTifty

  • Jr. Member
  • **
  • Posts: 56
Enabling Code Completion (a la Notepad++)?
« on: October 25, 2016, 04:24:26 am »
Hullo lads.

Decided to try my hand at another Lazarus program, seeing as how Delphi just made me want ta croak, and I've hit a wee snag.

See, in Notepad++, that I used to make a hoard of pascal scripts for FO4Edit & TES5Edit, the auto-completion will suggest words you've already typed in. To demonstrate, here's a photorealistic image:

(http://i.imgur.com/PnY3OPb.png)

Far as I can tell, Lazarus doesn't have such a feature, as far as the code completion options in the settings go. Any way to get that sweet, sweet completion?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Enabling Code Completion (a la Notepad++)?
« Reply #1 on: October 25, 2016, 04:32:24 am »
word completion? usually ctrl-w  you can re-assign it to other keys (also to ctrl space, if you want).

Though the code completion (ctrl-space) is smarter, as it chechs context.

FiftyTifty

  • Jr. Member
  • **
  • Posts: 56
Re: Enabling Code Completion (a la Notepad++)?
« Reply #2 on: October 25, 2016, 04:50:25 am »
word completion? usually ctrl-w  you can re-assign it to other keys (also to ctrl space, if you want).

Though the code completion (ctrl-space) is smarter, as it chechs context.

Trouble is, you have to keep pressing the hotkey. How it works in Notepad++, is that suggestions appear as soon as you start typing.

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Enabling Code Completion (a la Notepad++)?
« Reply #3 on: October 25, 2016, 06:48:09 am »
Trouble is, you have to keep pressing the hotkey. How it works in Notepad++, is that suggestions appear as soon as you start typing.

I think it's because of the way Lazarus is implemented. It need to scan an parse a lot of code (not only the current file), in order to activate the code completion. Doing it, every time a key is pressed, could be heavy for the CPU.

This code completion library: https://github.com/t-edson/SynFacilCompletion , can open the completion-list every time a key is pressed and some rules are followed.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Enabling Code Completion (a la Notepad++)?
« Reply #4 on: October 25, 2016, 01:37:07 pm »
I think it is not an issue with it not being fast enough.

IMHO it boils down to someone needs to implement it.

Code completion (not word completion) can already start, if you pressed a dot ("."). There is no reason why it could not start, as soon as the current word/token has a configured length.

FiftyTifty

  • Jr. Member
  • **
  • Posts: 56
Re: Enabling Code Completion (a la Notepad++)?
« Reply #5 on: October 25, 2016, 02:30:05 pm »

I think it's because of the way Lazarus is implemented. It need to scan an parse a lot of code (not only the current file), in order to activate the code completion. Doing it, every time a key is pressed, could be heavy for the CPU.

This code completion library: https://github.com/t-edson/SynFacilCompletion , can open the completion-list every time a key is pressed and some rules are followed.

Why would Lazarus have to check every file with code? That's fairly overzealous; just perform word completion for the current .pas, exactly like Notepad++ does.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Enabling Code Completion (a la Notepad++)?
« Reply #6 on: October 25, 2016, 03:47:36 pm »
Lazarus offers 2 completions.
1) Code completien
2) word completion

word completion is simply a list of all words known. (not sure of in the unit, or all open files, but both very easy to scan)

code completion actually knows pascal.
If you type "MyList." it will find the declaration of MyList, find its type's declaration (and all base classes), and list all methods and properties of that class.
But to do so, it must scan more code. For example finding the declaration of the type. "var MyList: TMyListClass". TMyListClass may be declared in more than one unit. In which case the completion will get the same one, that the compiler will use too. But the completion must look at all units that could contain it.
Yet this is all very fast, as most of the scanning is already prepared.

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Enabling Code Completion (a la Notepad++)?
« Reply #7 on: October 25, 2016, 07:24:55 pm »
Why would Lazarus have to check every file with code?
It's Code completion. Martin has explained it.

just perform word completion for the current .pas, exactly like Notepad++ does.
Lazarus is a Pascal IDE. Just suggesting words, out of context, is not the spirit of the IDE (IMHO). That completion would give many erroneous words (syntactically), then people would say "So silly editor".

Anyway you could implement that feature.

I think the correct way would be to maintain the smart Lazarus completion code, just making it automatic, without need to press <Ctrl+Space>.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018