feat: add builtin types/functions to diagnostics and completions
Files Modified/Created: - src/builtin_instructions.lua - NEW: Contains all TIA Portal built-in types, FBs, and functions - src/diagnostics.lua - Added missing data types + builtin instruction checking - src/main.lua - Added completion support for built-in types/F Bs/functions - src/plc_json.lua - Added .db file parsing + BOM handling fixes - lua/scl/blink_cmp_source.lua - Extended completion with all built-in types/F Bs/functions - src/node-types.json - Added node types for parser - AGENTS.md - Updated documentation Features Added: 1. Diagnostics - No more false "Unknown data type" warnings for: - All elementary types (USINT, SINT, UINT, UDINT, LINT, ULINT, TOD, DTL, etc.) - Timer/counter types (IEC_TON, TOF, TP, CTU, CTD, CTUD) - TIA Portal built-in FBs and functions 2. Auto-completion - Shows in VAR section after :: - 28 elementary data types - 23 built-in function blocks (TON, TOF, TP, CTU, CTD, CTUD, R_TRIG, F_TRIG, etc.) - 80+ built-in functions (ADD, SUB, MUL, DIV, SIN, COS, SQRT, etc.)
This commit is contained in:
@@ -0,0 +1,249 @@
|
||||
local M = {}
|
||||
|
||||
M.FUNCTIONS = {
|
||||
ADD = true,
|
||||
SUB = true,
|
||||
MUL = true,
|
||||
DIV = true,
|
||||
MOD = true,
|
||||
ABS = true,
|
||||
NEG = true,
|
||||
SQR = true,
|
||||
SQRT = true,
|
||||
EXP = true,
|
||||
LN = true,
|
||||
LOG = true,
|
||||
SIN = true,
|
||||
COS = true,
|
||||
TAN = true,
|
||||
ASIN = true,
|
||||
ACOS = true,
|
||||
ATAN = true,
|
||||
MIN = true,
|
||||
MAX = true,
|
||||
LIMIT = true,
|
||||
CALCULATE = true,
|
||||
CONVERT = true,
|
||||
ROUND = true,
|
||||
TRUNC = true,
|
||||
CEIL = true,
|
||||
FLOOR = true,
|
||||
SCALE_X = true,
|
||||
NORM_X = true,
|
||||
LEN = true,
|
||||
CONCAT = true,
|
||||
LEFT = true,
|
||||
RIGHT = true,
|
||||
MID = true,
|
||||
INSERT = true,
|
||||
DELETE = true,
|
||||
REPLACE = true,
|
||||
FIND = true,
|
||||
AND = true,
|
||||
OR = true,
|
||||
XOR = true,
|
||||
NOT = true,
|
||||
SHL = true,
|
||||
SHR = true,
|
||||
ROL = true,
|
||||
ROR = true,
|
||||
DECO = true,
|
||||
ENCO = true,
|
||||
BCD_I = true,
|
||||
I_BCD = true,
|
||||
DI_BCD = true,
|
||||
DI_R = true,
|
||||
I_DI = true,
|
||||
R_DI = true,
|
||||
R_DB = true,
|
||||
MOVE = true,
|
||||
FILL = true,
|
||||
SWAP = true,
|
||||
PEEK = true,
|
||||
POKE = true,
|
||||
GET_ERROR = true,
|
||||
GET_ERR_ID = true,
|
||||
RESET_ERR = true,
|
||||
T_CONV = true,
|
||||
T_ADD = true,
|
||||
T_SUB = true,
|
||||
T_DIFF = true,
|
||||
T_COMBINE = true,
|
||||
DT_DATE = true,
|
||||
DT_TOD = true,
|
||||
DATE_TO_DTL = true,
|
||||
DTL_TO_DATE = true,
|
||||
TOD_TO_DTL = true,
|
||||
DTL_TO_TOD = true,
|
||||
TimeToTicks = true,
|
||||
TicksToTime = true,
|
||||
GETHIGHNUM = true,
|
||||
GETLOWNUM = true,
|
||||
SAMPLE = true,
|
||||
SAMPLE_TRIG = true,
|
||||
WRIT_HIST = true,
|
||||
READ_HIST = true,
|
||||
COMPRESS = true,
|
||||
READFILE = true,
|
||||
WRITEFILE = true,
|
||||
READ_DB = true,
|
||||
WRITE_DB = true,
|
||||
RDREC = true,
|
||||
WRREC = true,
|
||||
RALRM = true,
|
||||
GET_DIAG = true,
|
||||
DPRINT = true,
|
||||
CTRL_PWM = true,
|
||||
CTRL_PTO = true,
|
||||
STATUS_PTO = true,
|
||||
HOME = true,
|
||||
MOVE_JOG = true,
|
||||
MOVE_VEL = true,
|
||||
MOVE_AXIS = true,
|
||||
POS_PULSE = true,
|
||||
POS_MC = true,
|
||||
SET_CAM = true,
|
||||
CAM_TB = true,
|
||||
CAM_TE = true,
|
||||
CAM_DOWN = true,
|
||||
MC_CamIn = true,
|
||||
MC_CamOut = true,
|
||||
MC_Superimpose = true,
|
||||
MC_GearIn = true,
|
||||
MC_GearOut = true,
|
||||
MC_Phasing = true,
|
||||
MC_CombineAxes = true,
|
||||
MC_Interpolate = true,
|
||||
MC_MoveLinear = true,
|
||||
MC_MoveCircular = true,
|
||||
MC_MoveDirect = true,
|
||||
MC_Home = true,
|
||||
MC_Halt = true,
|
||||
MC_Stop = true,
|
||||
MC_Power = true,
|
||||
MC_Reset = true,
|
||||
MC_ReadParam = true,
|
||||
MC_WriteParam = true,
|
||||
MC_ReadAxisError = true,
|
||||
MC_TouchProbe = true,
|
||||
MC_AbortTrigger = true,
|
||||
MC_ExtSetPointGen = true,
|
||||
MC_Generator = true,
|
||||
MC_BRIDGE = true,
|
||||
MC_BRIDGE_OFF = true,
|
||||
ENABLE = true,
|
||||
DISABLE = true,
|
||||
DISPLAY = true,
|
||||
LOG_EVENT = true,
|
||||
ALARM = true,
|
||||
ALARM_DQ = true,
|
||||
GET_ALARM = true,
|
||||
GETINST = true,
|
||||
GETALARMST = true,
|
||||
CHANGEOVER = true,
|
||||
REPLY_VALUE = true,
|
||||
NOTIFY = true,
|
||||
NOTIFY_WITH_ACK = true,
|
||||
ASGEN = true,
|
||||
HMI_R_DISCONNECT = true,
|
||||
HMI_R_CONNECT = true,
|
||||
HMI_R_SEND = true,
|
||||
HMI_R_RECEIVE = true,
|
||||
HMI_R_GET_STATE = true,
|
||||
MODBUSPN = true,
|
||||
MODBUSCP = true,
|
||||
TSEND = true,
|
||||
TRCV = true,
|
||||
TCON = true,
|
||||
TDISCON = true,
|
||||
TSEND_C = true,
|
||||
TRCV_C = true,
|
||||
TUSEND = true,
|
||||
TURCV = true,
|
||||
TCONNECT = true,
|
||||
TDISCONNECT = true,
|
||||
GETHNSON = true,
|
||||
DELHNSON = true,
|
||||
DNS_CLIENT = true,
|
||||
DHCP_CLIENT = true,
|
||||
DCP_CLIENT = true,
|
||||
}
|
||||
|
||||
M.FUNCTION_BLOCKS = {
|
||||
TON = true,
|
||||
TOF = true,
|
||||
TP = true,
|
||||
TONR = true,
|
||||
CTU = true,
|
||||
CTD = true,
|
||||
CTUD = true,
|
||||
IEC_TIMER = true,
|
||||
IEC_TON = true,
|
||||
IEC_TOF = true,
|
||||
IEC_TP = true,
|
||||
IEC_COUNTER = true,
|
||||
IEC_CTU = true,
|
||||
IEC_CTD = true,
|
||||
IEC_CTUD = true,
|
||||
R_TRIG = true,
|
||||
F_TRIG = true,
|
||||
SR = true,
|
||||
RS = true,
|
||||
SCHEDULE = true,
|
||||
BPM = true,
|
||||
LOG = true,
|
||||
DATALOG = true,
|
||||
}
|
||||
|
||||
M.DATA_TYPES = {
|
||||
BOOL = true,
|
||||
BYTE = true,
|
||||
WORD = true,
|
||||
DWORD = true,
|
||||
LWORD = true,
|
||||
CHAR = true,
|
||||
WCHAR = true,
|
||||
STRING = true,
|
||||
WSTRING = true,
|
||||
INT = true,
|
||||
DINT = true,
|
||||
LINT = true,
|
||||
USINT = true,
|
||||
SINT = true,
|
||||
UINT = true,
|
||||
UDINT = true,
|
||||
ULINT = true,
|
||||
REAL = true,
|
||||
LREAL = true,
|
||||
TIME = true,
|
||||
DATE = true,
|
||||
TOD = true,
|
||||
TIME_OF_DAY = true,
|
||||
DATE_AND_TIME = true,
|
||||
DT = true,
|
||||
S5TIME = true,
|
||||
LTIME = true,
|
||||
DTL = true,
|
||||
}
|
||||
|
||||
function M.is_known_function(name)
|
||||
return M.FUNCTIONS[name:upper()] or false
|
||||
end
|
||||
|
||||
function M.is_known_function_block(name)
|
||||
return M.FUNCTION_BLOCKS[name:upper()] or false
|
||||
end
|
||||
|
||||
function M.is_known_data_type(name)
|
||||
return M.DATA_TYPES[name:upper()] or false
|
||||
end
|
||||
|
||||
function M.is_known_instruction(name)
|
||||
return M.is_known_function(name) or M.is_known_function_block(name) or false
|
||||
end
|
||||
|
||||
function M.is_known_type_or_instruction(name)
|
||||
return M.is_known_data_type(name) or M.is_known_instruction(name) or false
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user