Skip to content

Sublime Text 4 refactor #8

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

Merged
merged 18 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.git* export-ignore
tests/ export-ignore
README.md export-ignore
16 changes: 10 additions & 6 deletions .github/workflows/syntax.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Syntax Tests
# https://github.com/sublimetext/syntax-test-action

on:
push:
Expand All @@ -17,17 +18,20 @@ on:
jobs:
main:
name: Syntax Tests (${{ matrix.build }})
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
include:
- build: 3211
packages: st3
- build: 4073
- build: latest
packages: master
runs-on: ubuntu-latest
- build: stable
packages: master
- build: 4134 # Need HTML with `html` context for inclusion
packages: binary
steps:
- uses: actions/checkout@v2
- uses: SublimeText/syntax-test-action@v1
- uses: actions/checkout@v4
- uses: SublimeText/syntax-test-action@v2
with:
build: ${{ matrix.build }}
default_packages: ${{ matrix.packages }}
Expand Down
File renamed without changes.
File renamed without changes.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

[Sublime Text][st] [syntax highlighting][ss-docs] for `.cshtml`, `.aspx`, and similar files.

## Current support
## WebForms

### Highlighting
The old ASP.Net style pages that necessitated creation of this package. Post-Visual Basic ASP, but pre-Razor.

### Current support

#### Highlighting

- Embedded C# (`<script runat="server">`)
+ The `runat="server"` must immediately follow the tag opening.
- `<%` expressions (including `<%=`, `<%#`, `<%:`, `<%$`, `<%--`)

### Functionality
#### Functionality

- Hotkey comment/uncomment server-side comments (<kbd>Ctrl</kbd>+<kbd>/</kbd> or <kbd>Cmd</kbd>+<kbd>/</kbd>)

Expand All @@ -19,37 +23,34 @@
+ Default attributes are subject to change.
- Snippets may require <kbd>Ctrl</kbd>+<kbd>space</kbd>, depending on your environment.
- Some autocomplete within directives.
- Basic "Open `CodeBehind`" shortcut for frontend pages.

### Razor syntax

A huge thank-you to [@keith-hall][keith] for this!

## Future support (maybe)
### Future support (maybe)

- Identify more attributes of directives
- Autocomplete ASP builtins

## Known issues:
### Known issues

- Nothing yet? &#x1f91e;


- "Goto Anything" support is poor.
## Razor

- No recognition of excluded scopes to return to HTML. In the snippet below, the C# scope ends immediately after `"bar`.
The simplified, less-intrusive frontend templating syntax that supplanted WebForms.

```
<%
var foo = "bar%>";
%>
```
A huge thank-you to [@keith-hall][keith] for his work on this.

- Javascript does not always recognize that `Response.Write` output is coming. The `)` is marked as invalid and the conditional scopes are never terminated.
### Current Support

#### Highlighting

The highlighting is not exhaustive, nor is it perfect. Expect some problems.

#### Functionality

- Hotkey comment/uncomment server-side comments (<kbd>Ctrl</kbd>+<kbd>/</kbd> or <kbd>Cmd</kbd>+<kbd>/</kbd>)

```
<script type="text/javascript">
if (true && <%= list.Any() %>) {
doStuff();
}
</script>
```

[pkg]: https://packagecontrol.io/packages/HTML%20(C%23)
[st]: https://www.sublimetext.com/
Expand Down
46 changes: 46 additions & 0 deletions Razor/C# (Razor).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
%YAML 1.2
---
scope: source.cs.embedded.html
hidden: true
# version: 2

extends: Packages/C#/C#.sublime-syntax

##############################################################################

contexts:
# code_block_in:
# - meta_prepend: true
# - match: (%>)(\s*\n)?
# scope: meta.embedded.cs
# captures:
# 1: punctuation.section.embedded.end.cs-razor
# 2: meta.html-newline-after-csharp.cs-razor # used by indentation rules
# push: embedding-syntax

embedding-syntax:
- clear_scopes: true
- meta_scope: embedding.cs text.html.cs.razor
- meta_include_prototype: false
- match: <%(?![=#:$@-])
scope: meta.embedded.cs punctuation.section.embedded.begin.cs-razor
pop: 1
- include: Packages/HTML (C#)/Razor/Razor.sublime-syntax#comments
- include: Packages/HTML (C#)/Razor/Razor.sublime-syntax#html

stray-braces:
- match: (\})(\s*\n)?
scope: meta.embedded.cs
captures:
1: punctuation.section.embedded.end.cs-razor
2: meta.html-newline-after-csharp.cs-razor # used by indentation rules
# - match: \}
# scope: invalid.illegal.stray.cs

stray-brackets:
- match: \]
scope: invalid.illegal.stray.cs

stray-parens:
- match: \)
scope: invalid.illegal.stray.cs
44 changes: 44 additions & 0 deletions Razor/CSS (Razor).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
%YAML 1.2
---
name: CSS (WebForms)
scope: source.css.cs.razor
version: 2

extends: Packages/CSS/CSS.sublime-syntax
hidden: true

contexts:

prototype:
- meta_prepend: true
- include: Razor.sublime-syntax#comments
- include: csharp-embedded

string-content:
- meta_prepend: true
- include: Razor.sublime-syntax#csharp-interpolations

csharp-interpolations:
- meta_include_prototype: false
# - match: (?=@)
# push: csharp-interpolation-body
- include: Razor.sublime-syntax#csharp-interpolations

csharp-interpolation-body:
- clear_scopes: 1
- meta_include_prototype: false
- include: csharp-embedded
- include: immediately-pop

csharp-embedded:
- meta_include_prototype: false
- include: Razor.sublime-syntax#razor-constructs
# - match: <%[=#:$]
# scope: meta.embedded.cs punctuation.section.embedded.begin.cs-webforms
# embed: Packages/C#/C#.sublime-syntax
# embed_scope: meta.embedded.cs source.cs.embedded.css
# escape: (%>)(\s*\n)?
# escape_captures:
# 0: meta.embedded.cs
# 1: punctuation.section.embedded.end.cs-webforms
# 2: meta.html-newline-after-csharp.cs-webforms
43 changes: 43 additions & 0 deletions Razor/JavaScript (Razor).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%YAML 1.2
---
name: JavaScript (Razor)
scope: source.js.cs.razor
version: 2
hidden: true

extends: Packages/JavaScript/JavaScript.sublime-syntax

contexts:

prototype:
- meta_prepend: true
- include: Razor.sublime-syntax#comments
# - include: csharp-embedded

string-content:
- meta_prepend: true
- include: Razor.sublime-syntax#csharp-interpolations

csharp-interpolations:
- meta_include_prototype: false
- match: (?=<%[=#:$])
push: csharp-interpolation-body

csharp-interpolation-body:
- clear_scopes: 1
- meta_include_prototype: false
- include: csharp-embedded
- include: immediately-pop

csharp-embedded:
- meta_include_prototype: false
- include: Razor.sublime-syntax#razor-constructs
# - match: <%[=#:$]
# scope: meta.embedded.cs punctuation.section.embedded.begin.cs-webforms
# embed: Packages/C#/C#.sublime-syntax
# embed_scope: meta.embedded.cs source.cs.embedded.css
# escape: (%>)(\s*\n)?
# escape_captures:
# 0: meta.embedded.cs
# 1: punctuation.section.embedded.end.cs-webforms
# 2: meta.html-newline-after-csharp.cs-webforms
Loading