diff --git a/README.md b/README.md index dc0b06c..65062d0 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,32 @@ Texinfo language support for Visual Studio Code. ## Features -**Warning**: This extension is in the early stage of development. **DO NOT USE**. +
+Syntax Highlighting +(Screenshots here...) +
+ +
+Code Completion +(Screenshots here...) +
+ +
+Block Folding +(Screenshots here...) +
+ +
+Display Preview +(Screenshots here...) +
## Requirements -To enable the preview feature, the `makeinfo` command-line tool, which is a part of [GNU Texinfo](https://www.gnu.org/software/texinfo/), should be present on your system. +The "Display Preview" feature depends on the `makeinfo` command-line tool, which is part of [GNU Texinfo](https://www.gnu.org/software/texinfo/). ## Extension Settings -See VSCode settings for details. +See `File -> Preferences -> Settings -> Extensions -> Texinfo` for details. The settings are self-explanatory. + +## Notes diff --git a/src/completion.ts b/src/completion.ts index ccd3f0d..84960b9 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -13,6 +13,13 @@ import * as vscode from 'vscode'; export class CompletionItemProvider implements vscode.CompletionItemProvider { private readonly completionItems = [ + command('ampchar', 'Insert an ampersand, "&"', { hasEmptyArguments: true }), + command('atchar', 'Insert an at sign, "@"', { hasEmptyArguments: true }), + command('backslashchar', 'Insert a blackslash, "\\"', { hasEmptyArguments: true }), + command('lbracechar', 'Insert a left brace, "{"', { hasEmptyArguments: true }), + command('rbracechar', 'Insert a right brace, "{"', { hasEmptyArguments: true }), + commandSnippet('abbr', 'Indicate a general abbreviation', 1, 'abbreviation', 'meaning'), + command('abbr', 'Indicate a general abbreviation', { sortOrder: 1 }), command('c', 'Line comment'), snippet('header', 'c', 'Declare header block', 1, '@c %**start of header\n\n@c %**end of header', 'c %**${1:start of header}\n$2\n@c %**${3:end of header}'), @@ -81,6 +88,28 @@ function command(name: string, detail: string, extraArgs?: { }; } +/** + * Build the completion item for a snippet of a command (with arguments). + * + * @param name The command name. + * @param detail The command description. + * @param numArgsRequired Number of required arguments. + * @param args Argument names. + */ +function commandSnippet(name: string, detail: string, numArgsRequired: number, ...args: string[]) { + const documentation = `@${name}{${args.map((arg, idx) => idx < numArgsRequired ? arg : '?' + arg).join(', ')}}`; + const optionalArgs = args.splice(numArgsRequired).map((arg, idx) => `\${${numArgsRequired + idx + 2}:${arg}}`); + const requiredArgs = args.map((arg, idx) => `\${${idx + 1}:${arg}}`); + const insertText = `${name}{${requiredArgs.join(', ')}\${${numArgsRequired + 1}:, ${optionalArgs.join(', ')}}}`; + return snippet(name, name, detail, 0, documentation, insertText); +} + +/** + * Build the completion item for a snippet of a block. + * + * @param name The snippet name. + * @param detail The snippet description. + */ function blockSnippet(name: string, detail: string): vscode.CompletionItem { return snippet(name, name, detail, 0, `@${name}\n\n@end ${name}`, `${name}\n$1\n@end ${name}`); }