Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keybinding sources #80

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rech-editor-cobol",
"displayName": "Rech COBOL",
"description": "Edit COBOL files with vscode.",
"version": "1.0.136",
"version": "1.0.138",
"publisher": "rechinformatica",
"engines": {
"vscode": "^1.47.0"
Expand Down Expand Up @@ -69,17 +69,17 @@
"description": "COBOL tabstops."
},
"rech.editor.cobol.showConditionalBlockCobolFlow": {
"type": [
"boolean",
"boolean"
],
"enum": [
false,
true
],
"description": "Show conditional blocks on COBOL Flow Tree View.",
"default": true
},
"type": [
"boolean",
"boolean"
],
"enum": [
false,
true
],
"description": "Show conditional blocks on COBOL Flow Tree View.",
"default": true
},
"rech.editor.cobol.formatter.location": {
"type": "string",
"description": "External COBOL formatter location."
Expand Down Expand Up @@ -186,7 +186,7 @@
"path": "./syntaxes/COBOL.tmLanguage.json"
}
],
"snippets": [
"snippets": [
{
"language": "COBOL",
"path": "./snippets/cobol.json"
Expand Down Expand Up @@ -349,6 +349,18 @@
{
"command": "rech.editor.cobol.extractParagraph",
"title": "Rech COBOL: Extract selected lines to a new paragraph"
},
{
"command": "rech.editor.cobol.changeParagraphSource",
"title": "Rech COBOL: Muda fonte de análise do autocompletar para parágrafos"
},
{
"command": "rech.editor.cobol.changeVariableSource",
"title": "Rech COBOL: Muda fonte de análise do autocompletar para variáveis"
},
{
"command": "rech.editor.cobol.changeBothSourceOfCompletion",
"title": "Rech COBOL: Muda fonte de análise do autocompletar para parágrafos/variáveis"
}
],
"keybindings": [
Expand Down Expand Up @@ -461,6 +473,11 @@
"command": "rech.editor.cobol.showElementProperties",
"key": "shift+alt+q",
"when": "editorLangId == COBOL"
},
{
"command": "rech.editor.cobol.changeBothSourceOfCompletion",
"key": "ctrl+alt+j",
"title": "Rech COBOL: Muda fonte de análise do autocompletar para parágrafos/variáveis"
}
]
},
Expand Down
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ async function _activate(context: any) {
SourceOfCompletions.toggleTheVariableSource(document.fileName, context);
}
}));
context.subscriptions.push(commands.registerCommand('rech.editor.cobol.changeBothSourceOfCompletion', () => {
const activeEditor = window.activeTextEditor;
if (activeEditor) {
const document = activeEditor.document;
SourceOfCompletions.toggleBothSource(document.fileName, context);
}
}));
context.subscriptions.push(commands.registerCommand('rech.editor.cobol.definesSourceExpander', () => {
const activeEditor = window.activeTextEditor;
if (activeEditor) {
Expand Down
29 changes: 24 additions & 5 deletions src/lsp/commons/SourceOfCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ export class SourceOfCompletions {
}
}

/**
* Toggles both paragraph and variable sources, ensuring they match and then inverting them.
* Paragraph will always toggle, and variable toggles only if it differs.
*
* @param fileName - The name of the file currently being edited.
* @param context - The extension context used to save the updated state.
*/
public static toggleBothSource(fileName: string, context: ExtensionContext) {
this.toggleTheParagraphSource(fileName, context);

const paragraphSource = SourceOfCompletions.getSourceOfParagraphCompletions(fileName);
const variableSource = SourceOfCompletions.getSourceOfVariableCompletions(fileName);

if (paragraphSource !== variableSource) {
this.toggleTheVariableSource(fileName, context);
}
}


/**
* Toggles the paragraph source between "local" and "expanded" for the given file.
*
Expand All @@ -128,10 +147,10 @@ export class SourceOfCompletions {
* @param fileName - The name of the file currently being edited.
* @param context - The extension context used to save the updated state.
*/
public static toggleTheVariableSource(fileName: string, context: ExtensionContext) {
if (SourceOfCompletions.getSourceOfVariableCompletions(fileName) == SOURCE_LOCAL) {
SourceOfCompletions.variableSource.set(fileName, SOURCE_EXPANDED);
SourceOfCompletions.variableStatusBar!.text = VARIABLE_SOURCE_EXPANDED_FILE
public static toggleTheVariableSource(fileName: string, context: ExtensionContext) {
if (SourceOfCompletions.getSourceOfVariableCompletions(fileName) == SOURCE_LOCAL) {
SourceOfCompletions.variableSource.set(fileName, SOURCE_EXPANDED);
SourceOfCompletions.variableStatusBar!.text = VARIABLE_SOURCE_EXPANDED_FILE
} else {
SourceOfCompletions.variableSource.set(fileName, SOURCE_LOCAL);
SourceOfCompletions.variableStatusBar!.text = VARIABLE_SOURCE_LOCAL_FILE
Expand Down Expand Up @@ -159,7 +178,7 @@ export class SourceOfCompletions {
* @param fileName - The name of the file for which to get the source.
* @returns The source of variable completions ("local" or "expanded").
*/
public static getSourceOfVariableCompletions(fileName: string) {
public static getSourceOfVariableCompletions(fileName: string) {
const config = SourceOfCompletions.variableSource.get(fileName);
if (config) {
return config
Expand Down