@@ -205,6 +205,45 @@ npm install monaco-sql-languages
205205
206206< br / >
207207
208+ ## Run Statement Button
209+
210+ Add a gutter run icon before each SQL statement . Call ` createRunStatementButton ` after creating the editor and dispose the controller when the editor is destroyed .
211+
212+ ` ` ` typescript
213+ import {
214+ LanguageIdEnum,
215+ createRunStatementButton,
216+ getStatementRangesByLanguage
217+ } from 'monaco-sql-languages';
218+
219+ const controller = createRunStatementButton({
220+ editor,
221+ languageId: LanguageIdEnum.FLINK,
222+ glyphMarginHoverMessage: 'Run this statement',
223+ preprocessCode: (code) => code,
224+ onRun: ({ statement, editor, model }) => {
225+ console.log(statement.text);
226+ }
227+ });
228+
229+ // controller.refresh(); // recompute icons manually when needed
230+ // controller.dispose(); // on editor unmount
231+ ` ` `
232+
233+ ** Notes **
234+
235+ - Pass ` languageId ` explicitly so the built - in splitter uses the correct parser .
236+ - Custom ` getStatementRanges ` only needs accurate ` startLineNumber ` and ` text ` ; ` executableLineNumber ` is normalized automatically .
237+ - Icons are hidden and clicks are ignored when the editor is read - only .
238+ - Use ` getStatementRangesByLanguage(code, languageId, preprocessCode) ` if you need the built - in splitter outside the button .
239+ - ` preprocessCode ` must keep the same line mapping as the editor model (no insert /delete that shifts lines ); decorations are applied to the original model .
240+ - By default , blank or semicolon - only fragments (e .g . ` ;;; ` ) do not show a run icon .
241+ - ` executableLineNumber ` detection skips leading comments but does not parse string literals ; a leading string that contains ` /* ` or ` -- ` may be misidentified (rare in practice ).
242+ - When multiple statements share the same ` executableLineNumber ` , a console warning is emitted and the last one wins for gutter clicks .
243+ - Call ` controller.dispose() ` when the editor is destroyed (one controller per editor instance ).
244+
245+ < br / >
246+
208247## SQL Snippets
209248
210249We provide some built - in SQL snippets for each SQL language , which helps us to write SQL quickly .
0 commit comments