Recent

Author Topic: Lazarus syntax helpers  (Read 414 times)

Weiss

  • Full Member
  • ***
  • Posts: 241
Lazarus syntax helpers
« on: May 24, 2026, 11:37:11 pm »
can we tap into Lazarus, or FP, syntax helpers, for monitoring scripts made outside of Lazarus environment? I understand this is not fair, like riding on Lazarus's developers backs. But alternative will be developing my own, and don't think I will dodge tokenizing and doing the entire lexical analysis.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12398
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus syntax helpers
« Reply #1 on: May 24, 2026, 11:47:38 pm »
Do you mean Codetools (or other code completion techniques)?

FPC afaik can generate "Browerinfo" which can be used, but not sure by which tools...

Codetools can in theory be used outside the IDE. Joost did (did or started?) a "language server" for vscode a long long time ago. But I have no idea what became of it...
I think it may be this ... https://gitlab.com/fpcprojects/lazarus-code.git


Weiss

  • Full Member
  • ***
  • Posts: 241
Re: Lazarus syntax helpers
« Reply #2 on: May 25, 2026, 12:56:18 am »
THANK YOU SIR!!

codeTools looks like it.

just started reading but I think this is exactly what I need. Awesome, thank you again.

Weiss

  • Full Member
  • ***
  • Posts: 241
Re: Lazarus syntax helpers
« Reply #3 on: June 02, 2026, 06:40:12 pm »
it is synEdit component. Exactly what I had in mind.

Now, how to load synEdit with more features beside just highlighting reserved words? Documentation is a bit thin for a dummy. How to make it add "end" with hitting enter after "begin" ?

I will get it eventually, but a quick point to a right direction will go a long way

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12398
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus syntax helpers
« Reply #4 on: June 02, 2026, 07:33:19 pm »
Ok, most of the Highlighting happens in SynEdit (only IFDEF lowlighting involves codetools).

The coloring is done by 2 major concepts:
1) the Highlighter
2) "Markup" classes

The begin/end (highlight the other if either one is touched by the text-cursor/caret) pairs are a combination. The are done by "TSynEditMarkupWordGroup". This however relies on the Highlighter.

The highlighter marks candidates with "sfaMarkup".  That and the fold-level (IIRC).

HL does have FoldConfig, which configures the elements that are considered (if the HL supports it at all)

So you create an instance (and assign the HL to it), and add it (afaik it takes ownership, so no need for freeing it later)
Code: Pascal  [Select][+][-]
  1. SynEdit.MarkupManager.AddMarkUp()

In the IDE that is probably done in ide/SourceSynEditor.pp. (that is were most of the setup of synedit happens / some is done in ide/SourceEditor.pp.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12398
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus syntax helpers
« Reply #5 on: June 02, 2026, 07:37:41 pm »
How to make it add "end" with hitting enter after "begin" ?

Ups. I misread that as "highlight end, when hitting begin" (with the caret). EDIT: Actually looks like, your text asked both question, just on one line...

The auto adding of end, is done by codetools. Codetools just adds it to SynEdit.

Not sure exactly where. (Codetools works on a copy, but keeps info on what needs to be added to SynEdit to sync). Somewhere in the SharedBuffer in SourceEditor... I think UpdateCodeBuffer. But that is just syncing codetools. The actual work, deciding what,where,when... I don't know.

EDIT: This may be your start point (last 2 lines?)
Code: Pascal  [Select][+][-]
  1.   ecLineBreak:
  2.     begin
  3.       AddChar:=true;
  4.       if AutoCompleteChar(aChar,AddChar,acoLineBreak) then ;
  5.       //DebugLn(['TSourceEditor.ProcessCommand ecLineBreak AddChar=',AddChar,' EditorOpts.AutoBlockCompletion=',EditorOpts.AutoBlockCompletion]);
  6.       if not AddChar then Command:=ecNone;
  7.       if EditorOpts.AutoBlockCompletion then
  8.         AutoCompleteBlock;
  9.     end;
  10.  
<<< END EDIT




SynEdit only has:

- A basic indenter (copy indent from line above, etc) => just whitespace.
- add quotes, when adding linebreak in the middle of a string. (or continue comments...)
« Last Edit: June 02, 2026, 07:42:05 pm by Martin_fr »

 

TinyPortal © 2005-2018