Skip to content

Commit

Permalink
Setting option to disable intrusive suggestions on instruction mnemonics
Browse files Browse the repository at this point in the history
- solves #29
  • Loading branch information
mborik committed May 3, 2023
1 parent 2e2a786 commit a1ee475
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/completionProvider.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/configProperties.ts
Expand Up @@ -7,6 +7,7 @@ export interface ConfigProps {
indentSpaces: boolean;
indentSize: number;
indentDetector: RegExp;
suggestOnInstructions: boolean;

// format section
baseIndent: number;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/defs_list.ts
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/defs_regex.ts
Expand Up @@ -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|
Expand Down

0 comments on commit a1ee475

Please sign in to comment.