Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Determine which syntax parser being used at cursor location

Is there a way to determine what syntax parser is being used at the current cursor location?

For example, I want to know if the editor thinks that it's in PHP code where the cursor is, so that I can "scan" for some nearby PHP functions.

If this is not possible then can it be added in the next update? Maybe return what syntax scheme is being used where the current cursor position is (where the user is currently editing)?

Thank you.
Tagged:

Comments

  • 10 Comments sorted by Votes Date Added
  • Currently there are no way to achieve it. But, I will check more, it seems from the first look that it can be implemented. 

    However, I want to warn right now, that there are no expected logical relations of schemes. For example, a scheme, like "comment" generally has an array of parent schemes. So, it's a question, whether this information will be really useful.
  • OK, thank you for looking into this.

    My initial desire is to simply know whether the cursor is in PHP code (as opposed to HTML, CSS, JavaScript, JSON, etc). I don't really need to know (at this point) whether the cursor is in a comment, integer, string, etc. but that information could be useful to me in the future... so if you could provide that info as well then great! If not then that's OK too... especially if I can still know whether it's in PHP or not (or JavaScript because I can do a quick 'scan' for JavaScript functions too).
  • I'm about to release a major new version of my software in January 2023.

    I was wondering if this has been implemented? For example, a simple function I could call to determine whether the cursor/caret is in PHP code.

    Thanks.
  • This may be implemented as a part of 2023 release new features. The release itself is expected in the first quarter of the 2023 year. 
  • OK, thanks. I'll keep my fingers crossed. It's obviously not a huge deal but would be nice to have.
  • Just checking in... Any updates on this? It's well past the first quarter of 2023. Thanks.
  • Hi, we still working on the new release now...
  • Hi, the following feature will be available with the next major release, which will be created in a matter of days:

    S := MyDoc.GetParser.GetCurrentSchemes(MyView.CursorOffset);

    The variable S will have a value with a list of currently active schemes, like:

    S = "CSS.CssInProp;CSS.CssProps;CSS.Main;HTML.Css;HTML.Main;"

    or

    S = "JavaScript.Main;HTML.JavaScript;HTML.Main;"

    Hope this will help you. The implementation is not fast, so, you cannot call it like 1000 times per second...
  • edited November 2023 Posts: 177Vote Up0Vote Down
    Yes, that looks good!

    Basically (at least for now), I just want to know if the cursor is in PHP code (or perhaps JavaScript code), so knowing the entire list of active schemes is a bit overkill for my current needs/wants.

    My suggestion is to add a function (that will hopefully also be a faster implementation) that returns only the 'most local' scheme. With that I think I could easily know where the cursor/offset is and whether the cursor/offset is in an HTML, CSS, PHP, JavaScript block, etc.

    Maybe instead of GetCurrentSchemes(), it could be called GetCurrentScheme(). GetCurrentSchemes() could return the entire list, and GetCurrentScheme() would return only the first one (most relevant to where the cursor/offset is). Hopefully GetCurrentScheme() would be a faster implementation because it does not need to return the entire list of currently active schemes, only the first one. In any case, I don't plan to call it many times per seconds... maybe up to once per second when the cursor moves.

  • edited November 2023 Posts: 0Vote Up0Vote Down
    The most local scheme may be "comment" or something like "string-literal", that's why we need the whole stack. Even having the whole stack we can get issues, because schemes are created for coloring, not for semantic use. So, you will try and we will know...
Sign In or Register to comment.