diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-13 05:58:39 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-13 05:58:39 +0000 |
| commit | e52266d8ce8823866b2dad3e04ffc78438e08397 (patch) | |
| tree | 6fbda74ac31a1d5db2e765d5ca086ae45df861ff /plugin/src/extension.js | |
| parent | be8154fac8a0ea5eb3dddef4053f12d67102009d (diff) | |
feat(plugin): add keyword Tab indentation and selection formatting
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'plugin/src/extension.js')
| -rw-r--r-- | plugin/src/extension.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/plugin/src/extension.js b/plugin/src/extension.js index 1101ed6..a7b4834 100644 --- a/plugin/src/extension.js +++ b/plugin/src/extension.js @@ -1,6 +1,33 @@ 'use strict'; -// Language registration and TextMate highlighting are declarative. -function activate() {} +const vscode = require('vscode'); +const { indentationEdits } = require('./indentation'); +const { codeOnly } = require('./lexical'); +const languageId = 'cie-pseudocode'; + +function formatLines(document, startLine, endLine, keepBlankIndent = false) { + const lines = document.getText().split(/\r?\n/); + return indentationEdits(lines, startLine, endLine, keepBlankIndent).map(edit => + vscode.TextEdit.replace(new vscode.Range(edit.line, 0, edit.line, edit.length), edit.text)); +} + +function activate(context) { + context.subscriptions.push( + vscode.languages.registerDocumentRangeFormattingEditProvider(languageId, { + provideDocumentRangeFormattingEdits(document, range) { + const endLine = range.end.character === 0 && range.end.line > range.start.line + ? range.end.line - 1 : range.end.line; + return formatLines(document, range.start.line, endLine); + } + }), + vscode.languages.registerOnTypeFormattingEditProvider(languageId, { + provideOnTypeFormattingEdits(document, position, char) { + if (char !== '\n' && !/^\s*(?:ELSE|ENDIF|ENDWHILE|UNTIL|NEXT|ENDFUNCTION|ENDPROCEDURE|ENDTYPE)\b/.test( + codeOnly(document.lineAt(position.line).text))) return []; + return formatLines(document, position.line, position.line, char === '\n'); + } + }, '\n', 'E', 'F', 'L', 'T', 'N') + ); +} module.exports = { activate }; |
