Skip to content

Add way to style identifiers (i.e. schema, table, and column names) #147

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wkeese opened this issue Oct 4, 2023 · 5 comments · Fixed by #148
Closed

Add way to style identifiers (i.e. schema, table, and column names) #147

wkeese opened this issue Oct 4, 2023 · 5 comments · Fixed by #148

Comments

@wkeese
Copy link
Contributor

wkeese commented Oct 4, 2023

As seen from the ‘getSegments’ tests, identifiers with backticks are classified as “string”,

it('complex query', () => {
  expect(getSegments("SELECT COUNT(id), `id`, `username` FROM `users` WHERE `email` = '[email protected]' AND `foo` = 'BAR' OR 1=1"))
    .toStrictEqual([
      ...
      { name: 'string', content: '`email`' },
      ...
      { name: 'string', content: "'[email protected]'" },

That means that you can’t set a specific style for backticked identifiers, they just appear in the same color as strings. In the example above, `email` and '[email protected]' end up with the same styling.

Furthermore, identifiers without backticks are lumped together with whitespace and identified as “default”.:

it('test how default works', () => {
  expect(getSegments('SELECT * FROM hr.emp'))
    .toStrictEqual([
      { name: 'keyword', content: 'SELECT' },
      { name: 'default', content: ' ' },
      { name: 'special', content: '*' },
      { name: 'default', content: ' ' },
      { name: 'keyword', content: 'FROM' },
      { name: 'default', content: ' hr.emp' }
    ])
})

That means that (for example) you can’t set a background-color for identifiers like “hr.emp”, because then the background-color would apply to the whitespace before “hr.emp” too, in addition to the whitespace before and after the * character.

wkeese added a commit to wkeese/sql-highlight that referenced this issue Oct 4, 2023
…th fallback to "unknown" token.

Also, change backticked identifiers like `foo` to be classified as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" token.

Fixes scriptcoded#147.
@scriptcoded
Copy link
Owner

Conversation in #148 to avoid multiple threads.

wkeese added a commit to wkeese/sql-highlight that referenced this issue Oct 4, 2023
Replace "default" token with "whitespace" and "identifier" tokens, with fallback to "unknown" token.
Also, classify backticked identifiers like `foo` as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" token.

Fixes: scriptcoded#147.
wkeese added a commit to wkeese/sql-highlight that referenced this issue Oct 4, 2023
Replace "default" segment with "whitespace" and "identifier" segments,
with fallback to "unknown" segment.

Also, classify backticked identifiers like `foo` as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" segment.

BREAKING CHANGE: The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.

Fixes scriptcoded#147.
@scriptsbot
Copy link
Collaborator

This issue has been marked as stale because it has been open for 14 days with no activity. Remove the stale label or comment or this will be closed in 5 days.

@wkeese
Copy link
Contributor Author

wkeese commented Oct 19, 2023

This should stay open, see #148.

@scriptsbot scriptsbot removed the Stale label Oct 20, 2023
scriptcoded pushed a commit that referenced this issue Oct 24, 2023
Replace "default" segment with "whitespace" and "identifier" segments,
with fallback to "unknown" segment.

Also, classify backticked identifiers like `foo` as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" segment.

BREAKING CHANGE: The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.

Fixes #147
github-actions bot pushed a commit that referenced this issue Oct 24, 2023
# [5.0.0-beta.2](v5.0.0-beta.1...v5.0.0-beta.2) (2023-10-24)

### Features

* add way to style identifiers ([01df1cd](01df1cd)), closes [#147](#147)

### BREAKING CHANGES

* The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 5.0.0-beta.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

scriptcoded pushed a commit that referenced this issue Jun 23, 2024
Replace "default" segment with "whitespace" and "identifier" segments,
with fallback to "unknown" segment.

Also, classify backticked identifiers like `foo` as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" segment.

BREAKING CHANGE: The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.

Fixes #147
scriptcoded pushed a commit that referenced this issue Jun 23, 2024
* add way to style identifiers ([01df1cd](01df1cd)), closes [#147](#147)

* The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.
scriptcoded pushed a commit that referenced this issue Jun 23, 2024
Replace "default" segment with "whitespace" and "identifier" segments,
with fallback to "unknown" segment.

Also, classify backticked identifiers like `foo` as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" segment.

BREAKING CHANGE: The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.

Fixes #147
scriptcoded pushed a commit that referenced this issue Jul 2, 2024
Replace "default" segment with "whitespace" and "identifier" segments,
with fallback to "unknown" segment.

Also, classify backticked identifiers like `foo` as "identifier" rather than "string".

This allows for identifiers to be styled independently from strings and whitespace.

It also simplifies getSegments() from 30 lines down to 5, by removing the special-case
code for the "default" segment.

BREAKING CHANGE: The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.

Fixes #147
scriptsbot added a commit that referenced this issue Jul 2, 2024
# [5.0.0](v4.4.2...v5.0.0) (2024-07-02)

* chore!: add support for Node 22 ([9478bf1](9478bf1))

### Bug Fixes

* improve number detection ([02d459a](02d459a)), closes [#149](#149)
* improve operator detection ([183a4fb](183a4fb)), closes [#150](#150)
* typo in unknown segments ([70af287](70af287)), closes [#148](#148) [#178](#178) [#148](#148)

### Features

* add way to style identifiers ([25677d4](25677d4)), closes [#147](#147)
* release 5.1.0 ([cb0c0f1](cb0c0f1))

### BREAKING CHANGES

* The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.
* drop support for Node 14.
scriptsbot added a commit that referenced this issue Jul 2, 2024
# [5.0.0](v4.4.2...v5.0.0) (2024-07-02)

* chore!: add support for Node 22 ([9478bf1](9478bf1))

### Bug Fixes

* improve number detection ([02d459a](02d459a)), closes [#149](#149)
* improve operator detection ([183a4fb](183a4fb)), closes [#150](#150)
* typo in unknown segments ([70af287](70af287)), closes [#148](#148) [#178](#178) [#148](#148)

### Features

* add way to style identifiers ([25677d4](25677d4)), closes [#147](#147)

### BREAKING CHANGES

* The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.
* drop support for Node 14.
scriptsbot added a commit that referenced this issue Jul 2, 2024
# [6.0.0](v5.0.0...v6.0.0) (2024-07-02)

### Bug Fixes

* improve number detection ([02d459a](02d459a)), closes [#149](#149)
* improve operator detection ([183a4fb](183a4fb)), closes [#150](#150)
* typo in unknown segments ([70af287](70af287)), closes [#148](#148) [#178](#178) [#148](#148)

### Features

* add way to style identifiers ([25677d4](25677d4)), closes [#147](#147)
* release 5.1.0 ([3a58def](3a58def))

### BREAKING CHANGES

* The `default` segment has been split into `identifier` and `whitespace`
segments.  There's also a new `unknown` segment that will only show up for malformed
SQL such as an unclosed string.

However, the highlight() function works largely the same as before, both normal mode and HTML mode,
except for the bug fix to stop classifying identifiers as strings.  In other words, SQL like

select * from EMP where NAME="John Smith"

will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME.
@scriptsbot
Copy link
Collaborator

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants