Skip to content

Commit

Permalink
Merge pull request #1986 from codefori/feature/actionCompletion
Browse files Browse the repository at this point in the history
CompletionItemProvider for local actions variables
  • Loading branch information
sebjulliand committed Apr 11, 2024
2 parents c86f779 + f0e75f9 commit c03dd5e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 128 deletions.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
"type": "ibmi"
}
],
"snippets": [
{
"path": "./schemas/local-variables.code-snippets",
"language": "json"
}
],
"jsonValidation": [
{
"fileMatch": [
Expand Down
110 changes: 0 additions & 110 deletions schemas/local-variables.code-snippets

This file was deleted.

26 changes: 14 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The module 'vscode' contains the VS Code extensibility API
import { ExtensionContext, commands, window, workspace } from "vscode";
import { ExtensionContext, commands, languages, window, workspace } from "vscode";

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
Expand All @@ -17,6 +17,7 @@ import { parseErrors } from "./api/errors/parser";
import { DeployTools } from "./api/local/deployTools";
import { Deployment } from "./api/local/deployment";
import { IFSFS } from "./filesystems/ifsFs";
import { LocalActionCompletionItemProvider } from "./languages/actions/completion";
import { updateLocale } from "./locale";
import * as Sandbox from "./sandbox";
import { initialise } from "./testing";
Expand All @@ -42,14 +43,14 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
GlobalStorage.get().setLastConnections(lastConnections);
commands.executeCommand(`setContext`, `code-for-ibmi:hasPreviousConnection`, lastConnections.length > 0);
};

SettingsUI.init(context);
initializeConnectionBrowser(context);
initializeObjectBrowser(context)
initializeIFSBrowser(context);
initializeDebugBrowser(context);

context.subscriptions.push(
context.subscriptions.push(
window.registerTreeDataProvider(
`helpView`,
new HelpView()
Expand Down Expand Up @@ -90,7 +91,8 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
}),
workspace.registerFileSystemProvider(`streamfile`, new IFSFS(), {
isCaseSensitive: false
})
}),
languages.registerCompletionItemProvider({ language: 'json', pattern: "**/.vscode/actions.json" }, new LocalActionCompletionItemProvider(), "&")
);

CompileTools.register(context);
Expand Down Expand Up @@ -122,34 +124,34 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
return { instance, customUI: () => new CustomUI(), deployTools: DeployTools, evfeventParser: parseErrors, tools: Tools };
}

async function fixLoginSettings(){
async function fixLoginSettings() {
const connections = (GlobalConfiguration.get<ConnectionData[]>(`connections`) || []);
let update = false;
for(const connection of connections){
for (const connection of connections) {
//privateKey was used to hold privateKeyPath
if('privateKey' in connection){
if ('privateKey' in connection) {
const privateKey = connection["privateKey"] as string;
if(privateKey){
if (privateKey) {
connection.privateKeyPath = privateKey;
}
delete connection["privateKey"];
update = true;
}

//An empty privateKeyPath will crash the connection
if(!connection.privateKeyPath?.trim()) {
if (!connection.privateKeyPath?.trim()) {
connection.privateKeyPath = undefined;
update = true;
}

//buttons were added by the login settings page
if(`buttons` in connection) {
if (`buttons` in connection) {
delete connection["buttons"];
update = true;
}
}

if(update){
if (update) {
await GlobalConfiguration.set(`connections`, connections);
}
}
Expand Down
47 changes: 47 additions & 0 deletions src/languages/actions/completion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import vscode from "vscode";
import { t } from "../../locale";

type Item = {
name: string
description: string
}

const ITEMS = [
"BASENAME",
"BRANCH",
"BRANCHLIB",
"BUILDLIB",
"CURLIB",
"EXT",
"EXTL",
"FILEDIR",
"FULLPATH",
"HOST",
"LIBLC",
"LIBLS",
"LIBRARY",
"LOCALPATH",
"NAME",
"NAMEL",
"PARENT",
"RELATIVEPATH",
"USERNAME",
"WORKDIR",
];

export class LocalActionCompletionItemProvider implements vscode.CompletionItemProvider {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
//Only provide items if the cursor is on a "command" line
if (/^\s*"command"\s*:/.test(document.lineAt(position.line).text)) {
return ITEMS.map(item => ({
label: item,
detail: t(`actions.${item}`).replaceAll(/<code>|<\/code>|&amp;/g, ""),
insertText: context.triggerCharacter ? undefined : `&${item}`,
kind: vscode.CompletionItemKind.Variable
} as vscode.CompletionItem));
}
else{
return [];
}
}
}
5 changes: 5 additions & 0 deletions src/locale/ids/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export const da: Locale = {
'actions.USERNAME': `Brugernavn for forbindelsen`,
'actions.WORKDIR': `Aktuel arbejdsmappe, kan ændres i IFS Browser`,
'actions.HOST': `Host navn eller IP adresse fra den aktuelle forbindelse`,
'actions.BRANCH': `Nuværende git-gren`,
'actions.BRANCHLIB': `Bibliotek for den nuværende Git-gren`,
'actions.BUILDLIB': `Det samme som <code>&amp;CURLIB</code>`,
'actions.LIBLC': `Liste af biblioteker adskilt af komma`,
'actions.LIBLS': `Liste af biblioteker adskilt af mellemrum`,
Expand All @@ -315,8 +317,11 @@ export const da: Locale = {
'actions.streamfile.EXT': `Filtypen (<code>&amp;EXTL</code> for små bogstaver)`,
'actions.LIBRARY': `Biblioteksnavn med objektet (<code>&amp;LIBRARYL</code> for små bogstaver)`,
'actions.NAME': `Navn på objektet (<code>&amp;NAMEL</code> for små bogstaver)`,
'actions.NAMEL': `Navn på objektet med små bogstaver`,
'actions.object.TYPE': `Typen af objektet (<code>&amp;TYPEL</code> for små bogstaver)`,
'actions.object.EXT': `Objektets attribut (<code>&amp;EXTL</code> for små bogstaver)`,
'actions.EXT': `Filtypen`,
'actions.EXTL': `Filtypen med små bogstaver`,
'actions.mainMenu.workWithActions': `Arbejd med Aktioner`,
'actions.mainMenu.createOrMaintain': `Opret eller revider Aktioner. Aktioner er grupperede efter typen på de vedrørte filer/objekter.`,
'actions.mainMenu.newAction': `Opret`,
Expand Down
5 changes: 5 additions & 0 deletions src/locale/ids/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export const en: Locale = {
'actions.USERNAME': `Username for connection`,
'actions.WORKDIR': `Current working directory, changeable in IFS Browser`,
'actions.HOST': `Hostname or IP address from the current connection`,
'actions.BRANCH': `Current Git branch`,
'actions.BRANCHLIB': `Branch library, based on the current branch`,
'actions.BUILDLIB': `The same as <code>&amp;CURLIB</code>`,
'actions.LIBLC': `Library list delimited by comma`,
'actions.LIBLS': `Library list delimited by space`,
Expand All @@ -315,8 +317,11 @@ export const en: Locale = {
'actions.streamfile.EXT': `Extension of the file (<code>&amp;EXTL</code> for lowercase)`,
'actions.LIBRARY': `Library name where the object lives (<code>&amp;LIBRARYL</code> for lowercase)`,
'actions.NAME': `Name of the object (<code>&amp;NAMEL</code> for lowercase)`,
'actions.NAMEL': `Lowercase name of the object`,
'actions.object.TYPE': `Type of the object (<code>&amp;TYPEL</code> for lowercase)`,
'actions.object.EXT': `Extension/attribute of the object (<code>&amp;EXTL</code> for lowercase)`,
'actions.EXT': `Filte type`,
'actions.EXTL': `Lowercase file type`,
'actions.mainMenu.workWithActions': `Work with Actions`,
'actions.mainMenu.createOrMaintain': `Create or maintain Actions. Actions are grouped by the type of file/object they target.`,
'actions.mainMenu.newAction': `New Action`,
Expand Down
5 changes: 5 additions & 0 deletions src/locale/ids/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export const fr: Locale = {
'actions.USERNAME': `Nom d'utilisateur de la connexion`,
'actions.WORKDIR': `Répertoire de travail actuel, modifiable dans le navigateur IFS`,
'actions.HOST': `Nom d'hôte ou adresse IP de la connexion`,
'actions.BRANCH': `Branche Git en cours`,
'actions.BRANCHLIB': `Bibliothèque de la branche, basée sur la branche en cours`,
'actions.BUILDLIB': `Voir <code>&amp;CURLIB</code>`,
'actions.LIBLC': `Liste des bilbiothèques, séparée par des virgules`,
'actions.LIBLS': `Liste des bilbiothèques, séparée par des espaces`,
Expand All @@ -315,8 +317,11 @@ export const fr: Locale = {
'actions.streamfile.EXT': `Extension du fichier (<code>&amp;EXTL</code> pour le nom en minuscule)`,
'actions.LIBRARY': `Nom de la bibliothèque contenant l'objet (<code>&amp;LIBRARYL</code> pour le nom en minuscule)`,
'actions.NAME': `Nom de l'objet (<code>&amp;NAMEL</code> pour le nom en minuscule)`,
'actions.NAMEL': `Nom de l'objet en minuscule`,
'actions.object.TYPE': `Type de l'objet (<code>&amp;TYPEL</code> pour le nom en minuscule)`,
'actions.object.EXT': `Extension/attribut de l'objet (<code>&amp;EXTL</code> pour le nom en minuscule)`,
'actions.EXT': `Extension du fichier`,
'actions.EXTL': `Extension du fichier en minuscule`,
'actions.mainMenu.workWithActions': `Maintenance des Actions`,
'actions.mainMenu.createOrMaintain': `Créez ou éditez des Actions. Les Actions sont groupées par type.`,
'actions.mainMenu.newAction': `Créer Action`,
Expand Down

0 comments on commit c03dd5e

Please sign in to comment.