Recent

Author Topic: [SynEdit] Get to kown which SynEdit called Highlighter  (Read 5246 times)

Pascal

  • Hero Member
  • *****
  • Posts: 932
[SynEdit] Get to kown which SynEdit called Highlighter
« on: February 17, 2015, 09:53:24 pm »
Hello,

i try to find out which Editor calls the highlighter. I tried this:
Code: [Select]
procedure TsusEditHighlighterCobol.SetCurrentLines(
  const AValue: TSynEditStringsBase);
var
  i: Integer;
  editor: TsusEdit;
  lines: TSynEDitStringList;
begin
  inherited SetCurrentLines(AValue);
  fEditor := nil;
  lines := TSynEditStringList(CurrentLines);
  for i := 0 to lines.AttachedSynEditCount - 1 do begin
    editor := TsusEdit(lines.AttachedSynEdits[i]);
    if editor.Highlighter = self then fEditor := editor;
  end;
end;
 

But i get an Ivalid type cast at run time in this line:
Code: [Select]
  lines := TSynEditStringList(CurrentLines);

What am i doing wrong?
Why does the editor not set himself to an editor property of the highlighter?
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] Get to kown which SynEdit called Highlighter
« Reply #1 on: February 17, 2015, 10:27:19 pm »
It is not guaranteed to be a  TSynEditStringList. It may be a wrapper class.

But even if it was: If the lines have more than one SynEdit, all of them (or any subset) can have the same highlighter. So you would not know the edit.

The design of the highlighter is such that the highlighter should not need to know.

What to you try to archive?

--------
If you want to highlight according to caret pos, or selection, or other editor specifics... That is not the job of the highlighter. For that you should use the Markup classes.

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: [SynEdit] Get to kown which SynEdit called Highlighter
« Reply #2 on: February 18, 2015, 06:06:46 am »
The highlighter generates basic TCobolToken and stores them in the range object.
Later (OnEditorChange) the parser scans these tokens to generate further information.
If for example a Token has an Error it sets a Markup (red wave underline) to the editor at the position and size of the token. Therefore i need to know the corresponding SynEdit.
As Cobol has COPY statements, which are like includes, which also have tokens, but attached to an other (invisible) editor, i need to know the editor.

But if there realy is no way, i have thought of providing the editor object reference to all tokens of the range during begin of a scan of the parser when i have access to the range object of then editor/highlighter.
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] Get to kown which SynEdit called Highlighter
« Reply #3 on: February 18, 2015, 04:06:44 pm »
EDIT: read next reply first [EDIT end]

Quote
If for example a Token has an Error it sets a Markup (red wave underline) to the editor at the position and size of the token. Therefore i need to know the corresponding SynEdit.

The wrong way round, the editor/markup should call the highligter to get the info.

I am also not sure, if this kind of work should be done entirely in the HL (eg. when it affects another file), or should be done in other classes (such as markup)

Worst case, you can use the "SendHighlightChanged" see other post).

---------------------------
To start with:

How does the HL deal with, it affects another editor. Let me go to a pascal example:
Code: [Select]
var
  globalFoo: integer;
.... 1000 lines....
  bar(globalFoo);

If you edit "globalFoo: integer;" into "MyGlobalFoo: integer;"
Then a 1000 lines later there is an error.

Yet, if correctly implemented, a highlighter should in such a case only scan the ONE line you edited. This is the one of the most important parts of the design of the HL.

If you store the list of current know var on the "range", then all ranges after this line change, and all file gets scanned.
Well that will work, but is again not how it is designed. And potentially slow (do that on top of a 300.000 lines file.)
Such checks should be done on idle.

Also if you do that, you use a lot of extra mem. And remember currently "range" objects are kept forever (never destroyed) because by design they are re-usable. (all HL have a finite number of such objects / your concept creates an infinite number)

-------------------------
There are events that tell you in which line edit actions, or hl scans took place. (see other mail).
So you can keep list of variable, etc. And any bigger scans, can the run OnIdle.

Then the markup, simple checks, if an identifier is in any of the lists available. This info can be cached for all visible lines.
« Last Edit: February 18, 2015, 04:10:20 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] Get to kown which SynEdit called Highlighter
« Reply #4 on: February 18, 2015, 04:09:29 pm »
Actually my answer may not much your description.

I assumed " the parser" was equal the HL.

If that is not the case, then most of what I wrote does not apply, and your parser should simply run on "HighlightChanged"

Pascal

  • Hero Member
  • *****
  • Posts: 932
Re: [SynEdit] Get to kown which SynEdit called Highlighter
« Reply #5 on: February 18, 2015, 08:27:48 pm »
Yes, the parser runs on OnChange of the editor and uses the tokens placed in the range objects by the highlighter. The Problem is only the initial run. Afterwards it works with only scanned changed lines.
In your example the highlighter replaces the tokens in the changed lines und after that the parser scans thru all tokens and find the error 1000 lines later.
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] Get to kown which SynEdit called Highlighter
« Reply #6 on: February 18, 2015, 09:35:07 pm »
I guess this is now the same as "how to force a highlighter to rescan complete file and wait" ?

And continued there?

 

TinyPortal © 2005-2018