@@ -81,25 +81,28 @@ to match as a builtin, not a generic function call.
8181### Pattern Types:
8282
8383#### 1. Simple Match (one line)
84+
8485``` json
8586{
86- "name" : " keyword.control.flow.scriptit" , // Scope to assign
87- "match" : " \\ b(if|elif|else|for|while)\\ b" // Regex pattern
87+ "name" : " keyword.control.flow.scriptit" , // Scope to assign
88+ "match" : " \\ b(if|elif|else|for|while)\\ b" // Regex pattern
8889}
8990```
9091
9192#### 2. Match with Captures (parts get different scopes)
93+
9294``` json
9395{
9496 "match" : " \\ b(fn)\\ s+([a-zA-Z_][a-zA-Z0-9_]*)\\ s*\\ (" ,
9597 "captures" : {
96- "1" : { "name" : " keyword.declaration.function.scriptit" }, // fn
98+ "1" : { "name" : " keyword.declaration.function.scriptit" }, // fn
9799 "2" : { "name" : " entity.name.function.definition.scriptit" } // function name
98100 }
99101}
100102```
101103
102104#### 3. Begin/End (multi-character or multi-line regions)
105+
103106``` json
104107{
105108 "begin" : " \" " ,
@@ -112,6 +115,7 @@ to match as a builtin, not a generic function call.
112115```
113116
114117#### 4. Begin/End with Sub-patterns (e.g., function parameters)
118+
115119``` json
116120{
117121 "begin" : " \\ b(fn)\\ s+([a-zA-Z_][a-zA-Z0-9_]*)\\ s*\\ (" ,
@@ -128,30 +132,32 @@ to match as a builtin, not a generic function call.
128132 ]
129133}
130134```
135+
131136This captures everything between ` fn name( ` and ` ): ` — each identifier inside
132137becomes ` variable.parameter ` .
133138
134139### Scope Naming Convention:
135140
136141VS Code themes map scopes to colors. Use standard names:
137142
138- | Scope prefix | What it colors | Example |
139- | -------------| ---------------| ---------|
140- | ` keyword.* ` | Language keywords | ` if ` , ` fn ` , ` var ` |
141- | ` entity.name.function.* ` | Function/method names | ` add ` , ` myFunc ` |
142- | ` variable.parameter.* ` | Function parameters | ` x ` , ` y ` in ` fn f(x, y) ` |
143- | ` variable.other.* ` | Variables | ` x ` in ` var x = 10 ` |
144- | ` support.function.* ` | Built-in functions | ` print ` , ` sin ` |
145- | ` constant.numeric.* ` | Numbers | ` 42 ` , ` 3.14 ` |
146- | ` constant.language.* ` | Language constants | ` True ` , ` False ` , ` None ` |
147- | ` string.quoted.* ` | String literals | ` "hello" ` |
148- | ` comment.* ` | Comments | ` # note ` |
149- | ` storage.modifier.* ` | Modifiers | ` @ ` in ` @param ` |
150- | ` punctuation.* ` | Punctuation | ` . ` , ` ; ` , ` , ` |
143+ | Scope prefix | What it colors | Example |
144+ | ------------------------ | --------------------- | ------------------------ |
145+ | ` keyword.* ` | Language keywords | ` if ` , ` fn ` , ` var ` |
146+ | ` entity.name.function.* ` | Function/method names | ` add ` , ` myFunc ` |
147+ | ` variable.parameter.* ` | Function parameters | ` x ` , ` y ` in ` fn f(x, y) ` |
148+ | ` variable.other.* ` | Variables | ` x ` in ` var x = 10 ` |
149+ | ` support.function.* ` | Built-in functions | ` print ` , ` sin ` |
150+ | ` constant.numeric.* ` | Numbers | ` 42 ` , ` 3.14 ` |
151+ | ` constant.language.* ` | Language constants | ` True ` , ` False ` , ` None ` |
152+ | ` string.quoted.* ` | String literals | ` "hello" ` |
153+ | ` comment.* ` | Comments | ` # note ` |
154+ | ` storage.modifier.* ` | Modifiers | ` @ ` in ` @param ` |
155+ | ` punctuation.* ` | Punctuation | ` . ` , ` ; ` , ` , ` |
151156
152157### How Variable Highlighting Works:
153158
154159For ` var x, b = ... ` :
160+
155161``` json
156162"var-declaration" : {
157163 "patterns" : [{
@@ -167,9 +173,11 @@ For `var x, b = ...`:
167173 }]
168174}
169175```
176+
170177Result: ` var ` → blue keyword, ` x ` → light blue variable, ` b ` → light blue variable.
171178
172179For function calls like ` myFunc(x) ` :
180+
173181``` json
174182"function-call" : {
175183 "patterns" : [{
@@ -180,6 +188,7 @@ For function calls like `myFunc(x)`:
180188 }]
181189}
182190```
191+
183192Result: ` myFunc ` → yellow (function call color).
184193
185194---
@@ -205,6 +214,7 @@ Result: `myFunc` → yellow (function call color).
205214```
206215
2072162 . ** Include it in the top-level patterns** (before ` identifiers ` !):
217+
208218``` json
209219"patterns" : [
210220 ...
@@ -285,6 +295,7 @@ myNewFunc: {
285295```
286296
287297This automatically provides:
298+
288299- ** Hover tooltip** : Shows signature + description when hovering
289300- ** Signature help** : Shows parameter info when typing ` myNewFunc( `
290301
@@ -300,15 +311,15 @@ Edit `src/server/server.ts`, in `validateTextDocument()`:
300311// After the existing static checks, add:
301312// Check for deprecated function
302313if (/ \b oldFunc\s * \( / .test (trimmed )) {
303- diagnostics .push ({
304- severity: DiagnosticSeverity .Warning ,
305- range: {
306- start: { line: i , character: codePart .indexOf (' oldFunc' ) },
307- end: { line: i , character: codePart .indexOf (' oldFunc' ) + 7 }
308- },
309- message: ` 'oldFunc' is deprecated. Use 'newFunc' instead. ` ,
310- source: ' scriptit'
311- });
314+ diagnostics .push ({
315+ severity: DiagnosticSeverity .Warning ,
316+ range: {
317+ start: { line: i , character: codePart .indexOf (" oldFunc" ) },
318+ end: { line: i , character: codePart .indexOf (" oldFunc" ) + 7 },
319+ },
320+ message: ` 'oldFunc' is deprecated. Use 'newFunc' instead. ` ,
321+ source: " scriptit" ,
322+ });
312323}
313324```
314325
@@ -321,9 +332,16 @@ Edit `src/server/diagnostics.ts`, in `parseErrors()`:
321332// Pattern: MyCustomError at position N: message
322333match = trimmed .match (/ MyCustomError\s + at\s + position\s + (\d + )\s * :\s * (. + )/ i );
323334if (match ) {
324- const lineNum = Math .max (0 , parseInt (match [1 ]) - 1 );
325- diagnostics .push (this .createDiagnostic (lineNum , match [2 ], sourceLines , DiagnosticSeverity .Error ));
326- continue ;
335+ const lineNum = Math .max (0 , parseInt (match [1 ]) - 1 );
336+ diagnostics .push (
337+ this .createDiagnostic (
338+ lineNum ,
339+ match [2 ],
340+ sourceLines ,
341+ DiagnosticSeverity .Error ,
342+ ),
343+ );
344+ continue ;
327345}
328346```
329347
@@ -347,6 +365,7 @@ Edit `snippets/scriptit.json`:
347365```
348366
349367Snippet syntax:
368+
350369- ` ${1:placeholder} ` — Tab stop 1 with default text
351370- ` $0 ` — Final cursor position
352371- ` ${1|choice1,choice2|} ` — Drop-down choice
@@ -379,6 +398,7 @@ Cell execution request
379398```
380399
381400The kernel protocol is JSON over stdin/stdout:
401+
382402```
383403Request: {"action": "execute", "cell_id": "...", "code": "..."}
384404Response: {"cell_id": "...", "status": "ok", "stdout": "...", "stderr": "..."}
@@ -405,6 +425,7 @@ VS Code (client) ←── IPC ──→ Language Server (server.ts)
405425### Adding a new LSP feature:
406426
4074271 . Register the capability in ` connection.onInitialize() ` :
428+
408429``` typescript
409430capabilities : {
410431 ...
@@ -413,10 +434,11 @@ capabilities: {
413434```
414435
4154362 . Add the handler:
437+
416438``` typescript
417439connection .onDocumentFormatting ((params ) => {
418- // Return TextEdit[] with formatting changes
419- return [];
440+ // Return TextEdit[] with formatting changes
441+ return [];
420442});
421443```
422444
@@ -455,6 +477,7 @@ code --install-extension scriptit-lang-0.1.0.vsix
455477
456478Use ` Ctrl+Shift+P ` → "Developer: Inspect Editor Tokens and Scopes"
457479Click on any character to see:
480+
458481- Token type
459482- Assigned scope (e.g., ` keyword.control.flow.scriptit ` )
460483- Theme color applied
@@ -463,17 +486,17 @@ Click on any character to see:
463486
464487## File Map (quick reference)
465488
466- | I want to... | Edit this file |
467- | -------------| ---------------|
468- | Add syntax highlighting for a new keyword | ` syntaxes/scriptit.tmLanguage.json ` |
469- | Add a new auto-completion item | ` src/server/completions.ts ` |
470- | Add hover documentation | ` src/server/hover.ts ` |
471- | Add a new error check (static) | ` src/server/server.ts ` → ` validateTextDocument() ` |
472- | Add a new error pattern (subprocess) | ` src/server/diagnostics.ts ` → ` parseErrors() ` |
473- | Add a code snippet | ` snippets/scriptit.json ` |
474- | Change bracket/comment/indent behavior | ` language-configuration.json ` |
475- | Add a new command | ` src/client/extension.ts ` + ` package.json ` commands |
476- | Change file associations | ` package.json ` → languages |
477- | Add a new file icon | ` images/ ` + ` themes/scriptit-icon-theme.json ` |
478- | Modify notebook serialization | ` src/client/notebookSerializer.ts ` |
479- | Modify kernel execution | ` src/client/notebookController.ts ` |
489+ | I want to... | Edit this file |
490+ | ----------------------------------------- | --------------------------------------------------- |
491+ | Add syntax highlighting for a new keyword | ` syntaxes/scriptit.tmLanguage.json ` |
492+ | Add a new auto-completion item | ` src/server/completions.ts ` |
493+ | Add hover documentation | ` src/server/hover.ts ` |
494+ | Add a new error check (static) | ` src/server/server.ts ` → ` validateTextDocument() ` |
495+ | Add a new error pattern (subprocess) | ` src/server/diagnostics.ts ` → ` parseErrors() ` |
496+ | Add a code snippet | ` snippets/scriptit.json ` |
497+ | Change bracket/comment/indent behavior | ` language-configuration.json ` |
498+ | Add a new command | ` src/client/extension.ts ` + ` package.json ` commands |
499+ | Change file associations | ` package.json ` → languages |
500+ | Add a new file icon | ` images/ ` + ` themes/scriptit-icon-theme.json ` |
501+ | Modify notebook serialization | ` src/client/notebookSerializer.ts ` |
502+ | Modify kernel execution | ` src/client/notebookController.ts ` |
0 commit comments