Bookstore

Recent

Author Topic: What is the result of TSynCustomHighlighter.getTokenKind used for ?  (Read 2528 times)

guest58172

  • Guest
The result of the function TSynCustomHighlighter.GetTokenKind seems to be totally unsused.
  • it's grabbed by GetHighlighterAttriAtRowColEx in a out parameter
  • FindMatchingBracketLogical calls GetHighlighterAttriAtRowColEx and gets indirectly the result in a local variable named TmpAttr
  • TmpAttr is never used !
It looks like a few calls could saved because GetTokenKind is indirectly called each time a the caret reachs a bracket.

Also, inline documentation wouldn't be luxury, even if I know that the doc is easier to add while the stuff are written. Each time something is not clear...forum, message, waiting for Martin Fr answer.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6083
    • wiki
Re: What is the result of TSynCustomHighlighter.getTokenKind used for ?
« Reply #1 on: March 29, 2016, 05:00:28 pm »
Quote
The result of the function TSynCustomHighlighter.GetTokenKind seems to be totally unsused.

I found it used it 2 or 3 places. But that aside many functions are from the original SynEdit project. The Highlighters had a big refactor, but there was no need to remove this.

As for GetTokenKind in GetHighlighterAttriAtRowColEx:

This may be a different story. Probably that code was refactored at some stage too. SVN history may tell....

GetHighlighterAttriAtRowColEx is a puplic function. That means it can be used by user code, and functionality can not be removed.

The only way would be to make a copy of it, and use the copy if less info is needed. That comes with the burden of more maintenance. The function is called ONCE when you get at a bracket or quote. To save that one single call, I would not create copy and paste duplicate code.

Actually FindMatchingBracketLogical should not call GetHighlighterAttriAtRowColEx  at all. "IsContextBracket" should be refactored, so it could return the value, and be used to get token kind.


Also:
TmpAttr is the value from Highlighter.GetTokenAttribute, not GetTokenKind.


guest58172

  • Guest
Re: What is the result of TSynCustomHighlighter.getTokenKind used for ?
« Reply #2 on: March 29, 2016, 08:59:17 pm »
Maybe...But do you see where the lack of documentation lead to ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6083
    • wiki
Re: What is the result of TSynCustomHighlighter.getTokenKind used for ?
« Reply #3 on: March 30, 2016, 04:21:15 pm »
Feel free to add documentation.

Besides docs would explain the purpose of a function. Not why it is implemented in a specific way.

GetTokenKind: get the integer representation for the "current" token kind (key, identifier, comment, ...). "current" refers to TokenPos. Only valid during a linescan (see SetLine/Next)


GetHighlighterAttriAtRowColEx: get information about the highlighter token at a given pos.
... details on the param.

FindMatchingBracketLogical
find the matching bracket or quote, takes the highlighter context (comment, code, string) into consideration.

-----------------
Docs dont tell why which internal function is called.
Docs tell how to use, and/or what for to use a function.