diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d5b47..d1fa398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Miva IDE CHANGELOG -## v1.27.0 (latest) +## 1.28.0 (latest) + +* Added global variable autocompletion. + +## v1.27.0 * Added tag mismatch validation for mvt tags. diff --git a/package-lock.json b/package-lock.json index 4e60558..8bba646 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-miva-ide", - "version": "1.27.0", + "version": "1.28.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vscode-miva-ide", - "version": "1.27.0", + "version": "1.28.0", "workspaces": [ "client", "server" @@ -888,7 +888,9 @@ "dev": true }, "node_modules/cross-spawn": { - "version": "7.0.3", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "license": "MIT", "dependencies": { "path-key": "^3.1.0", diff --git a/package.json b/package.json index 85d3b84..cf55d67 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-miva-ide", "displayName": "Miva IDE", "description": "Syntax highlighting, snippets and tools for building websites with Miva.", - "version": "1.27.0", + "version": "1.28.0", "engines": { "vscode": "^1.77.0", "node": ">=16" diff --git a/server/src/miva-features.ts b/server/src/miva-features.ts index 7593f07..d40eb12 100644 --- a/server/src/miva-features.ts +++ b/server/src/miva-features.ts @@ -29,6 +29,7 @@ import { import { URI, Utils } from 'vscode-uri'; import builtinFunctionData from './data/functions-builtin.json'; import merchantFunctionFiles from './data/functions-merchant.json'; +import globalVariableData from './mv/global-variables'; import mvOperatorData from './mv/operators'; import systemVariableData from './mv/system-variables'; import { mvSnippetData, mvTagData } from './mv/tags'; @@ -92,6 +93,7 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro const builtinFunctionCompletions: CompletionList = CompletionList.create( parseCompletionFile( builtinFunctionData ) ); const builtinFunctionHoverMap: Map = getHoverMapFromCompletionFile( builtinFunctionData, false ); const systemVariableCompletions: CompletionList = CompletionList.create( parseCompletionFile( Object.values( systemVariableData ) ) ); + const globalVariableCompletions: CompletionList = CompletionList.create( parseCompletionFile( Object.values( globalVariableData ) ) ); const operatorCompletions: CompletionList = CompletionList.create( parseCompletionFile( Object.values( mvOperatorData ) ) ); // Document cache for Miva Script (this is globally defined since we use .mv documents in MVT for LSK lookups) @@ -140,15 +142,18 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro ?.map(_variable => _variable.replace(foundVariableRegex, '')); return CompletionList.create( - foundVariables.map((variable) => { - return parseCompletion({ - "label": variable, - "kind": "Variable", - "detail": variable, - "documentation": "", - "commitCharacters": [] - }); - }) + [ + ...globalVariableCompletions.items, + ...foundVariables.map((variable) => { + return parseCompletion({ + "label": variable, + "kind": "Variable", + "detail": variable, + "documentation": "", + "commitCharacters": [] + }); + }) + ] ); } @@ -748,6 +753,16 @@ export function activateFeatures({workspaceSymbolProvider, mivaScriptCompilerPro } } + // System variable hover + if (patterns.SHARED.LEFT_VARIABLE_G.test(left)) { + const foundGlobalVariable = globalVariableData[wordLower]; + if (foundGlobalVariable) { + return { + contents: foundGlobalVariable.documentation + }; + } + } + // Tag name hover if (patterns.MVT.LEFT_IN_MVT_TAG.test(left)) { // Determine which tag we are in diff --git a/server/src/mv/global-variables.ts b/server/src/mv/global-variables.ts new file mode 100644 index 0000000..8b813fd --- /dev/null +++ b/server/src/mv/global-variables.ts @@ -0,0 +1,119 @@ +import { CompletionItemKind } from 'vscode-languageserver'; +import { BaseGlobalVariableData, GlobalVariableData } from '../util/interfaces'; + +const baseGlobalVariableData: BaseGlobalVariableData = { + kind: CompletionItemKind.Variable +}; + +const globalVariableData: Record = { + action: { + ...baseGlobalVariableData, + label: 'Action', + detail: 'Action', + documentation: `` + }, + order_id: { + ...baseGlobalVariableData, + label: 'Order_ID', + detail: 'Order ID', + documentation: `` + }, + store_code: { + ...baseGlobalVariableData, + label: 'Store_Code', + detail: 'Store Code', + documentation: `` + }, + product_code: { + ...baseGlobalVariableData, + label: 'Product_Code', + detail: 'Product Code', + documentation: `` + }, + category_code: { + ...baseGlobalVariableData, + label: 'Category_Code', + detail: 'Category Code', + documentation: `` + }, + page_code: { + ...baseGlobalVariableData, + label: 'Page_Code', + detail: 'Page Code', + documentation: `` + }, + error_code: { + ...baseGlobalVariableData, + label: 'Error_Code', + detail: 'Error Code', + documentation: `` + }, + error_message: { + ...baseGlobalVariableData, + label: 'Error_Message', + detail: 'Error Message', + documentation: `` + }, + mvdo_error: { + ...baseGlobalVariableData, + label: 'MvDO_Error', + detail: 'MvDO Error Message', + documentation: `Error message from the last ran \`\` tag.` + }, + mvcall_error: { + ...baseGlobalVariableData, + label: 'MvCALL_Error', + detail: 'MvCALL Error Message', + documentation: `Error message from the last ran \`\` tag.` + }, + screen: { + ...baseGlobalVariableData, + label: 'Screen', + detail: 'Screen', + documentation: `` + }, + session_type: { + ...baseGlobalVariableData, + label: 'Session_Type', + detail: 'Session Type', + documentation: `` + }, + session_id: { + ...baseGlobalVariableData, + label: 'Session_ID', + detail: 'Session ID', + documentation: `` + }, + merchant_local_timezone: { + ...baseGlobalVariableData, + label: 'Merchant_Local_Timezone', + detail: 'Merchant Local Timezone', + documentation: `Timezone of the server.` + }, + module_root_versionless: { + ...baseGlobalVariableData, + label: 'Module_Root_Versionless', + detail: 'Module Root Versionless', + documentation: `Example: \`/mm5/\`` + }, + module_root: { + ...baseGlobalVariableData, + label: 'Module_Root', + detail: 'Module Root', + documentation: `Example: \`/mm5/5.00/\`` + }, + customer_session_id: { + ...baseGlobalVariableData, + label: 'Customer_Session_ID', + detail: 'Customer Session ID', + documentation: `` + }, + customer_session_verified: { + ...baseGlobalVariableData, + label: 'Customer_Session_Verified', + detail: 'Customer Session Verified', + documentation: `` + } +}; + +export default globalVariableData; diff --git a/server/src/util/interfaces.ts b/server/src/util/interfaces.ts index 82a5c78..2845058 100644 --- a/server/src/util/interfaces.ts +++ b/server/src/util/interfaces.ts @@ -243,6 +243,16 @@ export interface SystemVariableData extends BaseSystemVariableData { documentation: string; } +export interface BaseGlobalVariableData { + kind: CompletionItemKind; +} + +export interface GlobalVariableData extends BaseGlobalVariableData { + label: string; + detail: string; + documentation: string; +} + export interface SymbolInformationWithDocumentation extends SymbolInformation { documentation?: MarkupContent; };