Skip to content

[C#] embed SQL instead of using with_prototype#4416

Open
keith-hall wants to merge 1 commit intosublimehq:masterfrom
forkeith:cs_sql_fix
Open

[C#] embed SQL instead of using with_prototype#4416
keith-hall wants to merge 1 commit intosublimehq:masterfrom
forkeith:cs_sql_fix

Conversation

@keith-hall
Copy link
Copy Markdown
Collaborator

@michaelblyons
Copy link
Copy Markdown
Collaborator

Are you going to do long string and/or long format string as well?

@keith-hall
Copy link
Copy Markdown
Collaborator Author

keith-hall commented Dec 18, 2025

Probably we will want to extend the SQL syntax for C# embedding and add some string formatting contexts for those, it isn't quite as straightforward. I agree that it needs to be done, probably this PR doesn't bring much benefit without it... Maybe a job for my next chunk of spare time 😅

@michaelblyons
Copy link
Copy Markdown
Collaborator

I'm not sure if you saw that my "Ripping SQL out of C#" comment on SublimeText/PowerShell#213 was accompanied by SublimeText/PowerShell@cf8df09 that actually does so when embedding the C#.

I don't know how valuable it is to PowerShell users to have the fancy SQL embedding in their C# strings. And it's not like they're losing something they were used to. So no pressing need.

Comment thread C#/C#.sublime-syntax
Comment on lines +1978 to +1979
embed: scope:source.sql
escape: (?=""")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
embed: scope:source.sql
escape: (?=""")
embed: scope:source.sql
escape: (?=""")
pop: 1

@deathaxe
Copy link
Copy Markdown
Collaborator

deathaxe commented Dec 18, 2025

Extending and embedding SQL

pro:

  • core C# syntax becomes smaller again
  • more control over which SQL contexts format string placeholders etc. are injected into
  • SQL is loaded only, if used in a file

contra:

  • overall package size significantly increases as each SQL variant contains various C# contexts, required to render extended placeholders or interpolation patterns

FWIW, I also have a Python (and C#) branch with SQL embedded insead of being included. Current Python with SQL included is about 1.5MB. Embedding SQL shrinks Python to 150kB, but increases whole package's syntax cache size to about 7MB.

It is however the more bullet proove solution, regardless overall size, unless any other syntax pushes C# (or Python) using with_prototype.

@deathaxe
Copy link
Copy Markdown
Collaborator

For those looking for some inspiration ... https://github.com/deathaxe/sublime-packages/tree/pr/cs/embed-sql

Current C# is about 1.4MB of size.

With SQL embedded (3x), each SQL is of about 1MB of size + C# using about 740kB.

@michaelblyons
Copy link
Copy Markdown
Collaborator

Are caches generated for embedded syntaxes whose activating pattern is never encountered?

@deathaxe
Copy link
Copy Markdown
Collaborator

Not until they are loaded, which they are when running syntax tests. Comparing cache sizes, may primarily indicate how good ST can dedup or re-use existing patterns to achieve a certain kind of highlighting. The larger caches are the more distinct patterns are involved, which may also increase RAM usage. It may however also be of no sense, to compare them.

@michaelblyons
Copy link
Copy Markdown
Collaborator

See also #4464

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants