Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to define custom highlighter #6

Closed
vladshcherbin opened this issue Apr 22, 2020 · 4 comments
Closed

Add possibility to define custom highlighter #6

vladshcherbin opened this issue Apr 22, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@vladshcherbin
Copy link
Contributor

馃憢

Hey, in a similar library I've used a feature where you could define your custom highlighter with regex and color, something like this:

own: {
  duration: {
    regexp: /^(?:(?! \|).)*/,
    color: 'magenta'
  }
}

It gives possibility to color custom parts of query, for example if it includes query duration.

Would be nice to have something similar here later if possible :)

@scriptcoded
Copy link
Owner

This would absolutely be a useful feature to have. One major issue with the library at the moment is that it's using plain regex for highlighting. While this works fine in most cases, more complex queries and language features might not be properly highlighted, and even break the highlighter as a whole. I think a general improvement for this library would be to look in to alternative methods for matching language features, and perhaps then this would make more sense. I think this feature was to be implemented right now we would also have to provide some way of choosing what position in highlighters the custom regex should end up.

As for this specific case, perhaps the rule is something that should be put into the base library?

@vladshcherbin
Copy link
Contributor Author

@scriptcoded yeah, I understand the difficulty with where you execute custom regex. Maybe it can be set with some kind of an option (order):

duration: {
  regexp: /^(?:(?! \|).)*/,
  color: 'magenta',
  order: 'last'
}

last, first, { after: 'keyword' } - maybe this can be values 馃

Previously, I was using igniculus and this idea (and other my issues) come from there. Custom rules section there also has a warning mark as an experimental advanced feature.

As per my case, I was using this regex to highlight query duration 10.12 ms |, don't think this should be added to base library as format differs according to every dev preferences 馃

@scriptcoded
Copy link
Owner

@vladshcherbin I like the idea of using order. The issue with collisions remains, but I think adding a warning like igniculus did would be enough to warn people. I'll mock something up.

@scriptcoded scriptcoded added the enhancement New feature or request label Oct 5, 2020
scriptcoded pushed a commit that referenced this issue Jan 1, 2021
* fix issue with sqlString getting cut off at the end

* whitespace changes for eslint

* remove console.log

* Increase code coverage back up to 100%

* ESlint wants single quotes

* So, these are the real tests apparently
@scriptcoded
Copy link
Owner

scriptcoded commented Aug 8, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants