diff --git a/README.md b/README.md index 23bb19c..89e8ac5 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ These few options allows you to configure extension's behavior but primarily you >+ **"c-style"**: `0x1fff` | `0xB45D` - `z80-macroasm.format.hexaNumberCase` - When reformatting of hexadecimal numbers was enabled, whether it's to be additional case processing applied when `true` means uppercased, `false` lowercased. > default: `"no-change"` +- `z80-macroasm.format.suggestOnInstructions` - Extension will suggest also basic instruction mnemonics for the auto-completion, not only instruction arguments. + > default: `false` - `z80-macroasm.format.splitInstructionsByColon` - Split colon separated instructions to lines. > default: `true` diff --git a/package.json b/package.json index c2349ed..e22ade9 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,11 @@ "default": "no-change", "description": "Formatter: When formatting of hexadecimal numbers was enabled, whether it's to be additional case processing applied (by default keep untouched)." }, + "z80-macroasm.suggestOnInstructions": { + "type": "boolean", + "default": false, + "description": "If true, extension will suggest basic instruction mnemonics for the auto-completion. Otherwise, only instruction arguments will be suggested." + }, "z80-macroasm.seekSymbolsThroughWorkspace": { "type": "boolean", "default": false, diff --git a/src/completionProvider.ts b/src/completionProvider.ts index c44e4ed..0b0b779 100644 --- a/src/completionProvider.ts +++ b/src/completionProvider.ts @@ -179,6 +179,10 @@ export class Z80CompletionProvider extends ConfigPropsProvider implements vscode const shouldSuggestInstructionMatch = regex.shouldSuggestInstruction.exec(fragment); if (shouldSuggestInstructionMatch) { + if (!configProps.suggestOnInstructions) { + vscode.commands.executeCommand('editor.action.triggerSuggest', { auto: false }); + } + const [ fullMatch,,,, instructionPart ] = shouldSuggestInstructionMatch; const uppercase = this._shouldKeywordUppercase( instructionPart, @@ -218,6 +222,7 @@ export class Z80CompletionProvider extends ConfigPropsProvider implements vscode else { const shouldSuggest1ArgRegisterMatch = regex.shouldSuggest1ArgRegister.exec(fragment); const shouldSuggest2ArgRegisterMatch = regex.shouldSuggest2ArgRegister.exec(fragment); + const shouldSuggestConditionalsMatch = regex.shouldSuggestConditionals.exec(fragment); if (shouldSuggest2ArgRegisterMatch) { const uppercase = this._shouldKeywordUppercase( @@ -286,6 +291,22 @@ export class Z80CompletionProvider extends ConfigPropsProvider implements vscode }) ); } + else if (shouldSuggestConditionalsMatch) { + const { 1: instruction } = shouldSuggestConditionalsMatch; + const uppercase = this._shouldKeywordUppercase( + instruction, + configProps.uppercaseKeywords + ); + + output = set.conditionals.map( + (snippet, index) => this._registerMapper({ + ...configProps, + uppercase, + snippet, + index, + }) + ); + } } const symbols = await this.symbolProcessor.symbols(document); diff --git a/src/configProperties.ts b/src/configProperties.ts index 29dacff..8d41294 100644 --- a/src/configProperties.ts +++ b/src/configProperties.ts @@ -7,6 +7,7 @@ export interface ConfigProps { indentSpaces: boolean; indentSize: number; indentDetector: RegExp; + suggestOnInstructions: boolean; // format section baseIndent: number; @@ -33,6 +34,8 @@ export abstract class ConfigPropsProvider { const result: ConfigProps = { ...this.settings?.format, + suggestOnInstructions: this.settings?.suggestOnInstructions === true, + eol: (config.files.eol === vscode.EndOfLine.CRLF) ? '\r\n' : '\n', formatOnType: config.editor.formatOnType === true, indentSpaces: config.editor.insertSpaces === true, diff --git a/src/defs_list.ts b/src/defs_list.ts index ba7c91c..16e23ed 100644 --- a/src/defs_list.ts +++ b/src/defs_list.ts @@ -28,6 +28,8 @@ export default { /* 29 */ 'hl', 'de', 'bc', 'af', 'ix', 'iy', /* 35 */ 'sp', '(sp)', '(ix)', '(iy)' ], + conditionals: ['c', 'nc', 'z', 'nz', 'p', 'm', 'po', 'pe'], + // quick pointers into `registers` regR16Index: 29, regStackIndex: 35, diff --git a/src/defs_regex.ts b/src/defs_regex.ts index 2750849..496facf 100644 --- a/src/defs_regex.ts +++ b/src/defs_regex.ts @@ -52,6 +52,7 @@ export default { nextreg|bs[lr]a|bsr[lf]|brlc ) \s+(\w+|\([^\)]+?\)|\[[^\]]+?\]),\s*?[[(]?([^[(\n]*)$`, + shouldSuggestConditionals: /(j[pr]|call|ret)\s+$/, defineExpression: mkRegex` ^\@?([\w\.]+)\:?\s+( inc(?:bin|hob|trd)|b?include|includelua|insert|binary|