Skip to content

riodelphino/mql-compile.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mql-compile.nvim

Concept

A neovim plugin for compiling MQL5/MQL4 scripts asyncronously.
Without heavy MetaEditor GUI. (Compiling on command-line).

Caution

This is a test version.

Be careful to use at your own risk.

Warning

Not tested in Windows or Linux

Currently ensured to work only in 'macOS + wine(wineskin)' environment.
If anyone encounters any problems while using/testing, please create an issue on GitHub.

Screenshots

With nvim-notify

Note

Sorry, these pics are from older ver.

Error

Quickfix error_quickfix

Notify error_notify

Warning

Quickfix warning_quickfix

Notify warning_notify

Success

Quickfix success_quickfix

Notify success_notify

Features

Main features

  • Async compiling MQL5/MQL4
  • Show quickfix
  • Auto detect MQL5/MQL4
  • Works on MacOS + wine(wineskin) for now

Not implemented

  • Works on Windows (Need tested)
  • Works on Linux (Need tested)

Requirement

Mandatory

  • nvim v0.10.2 (My environment. It seems to work in a little older versions.)
  • MT5 or MT4 installed through wine/wineskin (for now)
  • plenary.nvim Plugin for async

Optional plugins

Warning

Use v3.14.0 or earlier versions of nvim-notify. v3.14.1 not works somewhy with it's error.

Installation

Using Lazy.nvim:

-- Minimum config:
return {
   'riodelphino/mql-compile.nvim',
   dependencies = {
      'nvim-lua/plenary.nvim',
      { 'rcarriga/nvim-notify', commit = 'fbef5d32be8466dd76544a257d3f3dce20082a07' } -- v3.14.0 (later version cause `{ title = '' }` error for now)
   },
   lazy = true,
   ft = { 'cpp', 'c' }, -- If your filetype settings read mql5 as cpp / mql4 as c.
   opts = {
      ft = {
         mql5 = {
            metaeditor_path = '~/Applications/Wineskin/MT5.app/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe', -- your MT5 exe's path
         },
         mql4 = {
            metaeditor_path = '~/Applications/Wineskin/MT4.app/drive_c/Program Files (x86)/XMTrading MT4/metaeditor.exe', -- your MT4 exe's path
         },
      },
   },
   keys = {},
   cmds = {
      { 'MQLCompile', 'MQLCompileSetSource', 'MQLCompileShowOptions' },
   },
}

Default options

opts = {
   priority = { 'mql5', 'mql4' }, -- priority for auto file detection
   log = {
      extension = 'log',
      delete_after_load = true,
   },
   quickfix = {
      types = { 'error', 'warning' }, -- Types to pick up. 'error' | 'warning' | 'information'
      show = {
         copen = true, -- Open quickfix automatically
         with = { 'error', 'warning' }, -- Types to copen. 'error' | 'warning' | 'information'
      },
      parse = nil, -- See '# Parsing quickfix' section
   },
   information = {
      actions = { 'including' }, -- Actions to pick up. 'compiling' | 'including'
      show = {
         notify = true, -- Show 'information' independently in notify
         with = { 'including' }, -- Actions to show. 'compiling' | 'including'
      },
      parse = nil, -- See '# Parsing and formatting information' section
      format = nil, -- See '# Parsing and formatting information' section
   },
   wine = {
      enabled = true, -- On MacOS/Linux, set true for MT5/MT5 on wine(wineskin). On windows, set false.
      command = 'wine', -- Wine command path
   },
   ft = {
      mql5 = {
         metaeditor_path = '', -- '~/Applications/Wineskin/MT5.app/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe', -- your MT5 exe's path
         include_path = '', -- Not supported now
         pattern = '*.mq5',
      },
      mql4 = {
         metaeditor_path = '', -- '~/Applications/Wineskin/MT4.app/drive_c/Program Files (x86)/MetaTrader 4/metaeditor.exe', -- your MT4 exe's path
         include_path = '', -- Not supported now
         pattern = '*.mq4',
      },
   },
   notify = { -- Enable/disable notify
      compile = {
         on_started = true,
         on_finished = true,
      },
      log = {
         on_saved = false,
         on_deleted = false,
      },
      quickfix = {
         on_finished = true, -- Add quickfix counts to main message on 'notify.compile.on_finished'
      },
      information = {},
      levels = { -- Color to notify if compiling was ...
         succeeded = { -- with type ...
            none = vim.log.levels.INFO,
            info = vim.log.levels.INFO,
            warn = vim.log.levels.WARN, -- *.INFO is also good, if you don't like warn color on success.
         },
         failed = vim.log.levels.ERROR,
         information = vim.log.levels.INFO, -- for notifing informations
      },
   },
   highlights = { -- Highlights & syntax on quickfix window
      enabled = true,
      hlgroups = nil, -- See '# Highlights' section
   },
},

Default 'metaeditor_path'

Below are the default path for MetaEditor exe in opts.ft.[mql5|mql4].
(It depends on your settings on installing.)

MT5

 -- MacOS (via wine)
 metaeditor_path = '~/Applications/Wineskin/MT5.app/drive_c/Program Files/MetaTrader 5/MetaEditor64.exe'
 -- Windows (NOT TESTED. just a note)
 metaeditor_path = 'C:\\Program Files\\MetaTrader 5\\MetaEditor64.exe'

'MT5.app' is the name of app you set on wineskin.

MT4

-- MacOS (via wine)
metaeditor_path = '~/Applications/Wineskin/MT5.app/drive_c/Program Files (x86)/MetaTrader 4/metaeditor.exe'
-- Windows (NOT TESTED. just a note)
metaeditor_path = 'C:\\Program Files (x86)\\MetaTrader 4\\metaeditor.exe'

'MT4.app' is the name of app you set on wineskin.

Parsing and formatting

You can modify parsing & formatting functions, if you need.
Leave 'parse' or 'format' as nil to use these default functions.

Parsing quickfix

This is the parsing function, from log to quickfix Default:

opts = {
   quickfix = {
      parse = function(line, type)
         local e = {}
         if type == 'error' or type == 'warning' then
            e.filename, e.lnum, e.col, e.type, e.nr, e.text = line:match('^(.*)%((%d+),(%d+)%) : (.*) (%d+): (.*)$')
         elseif type == 'information' then
            e.filename, e.type, e.text = line:match('^(.*) : (.*): (.*)$')
            e.lnum = 1
            e.col = 1
            e.nr = 0
         end
         e.type = e.type:sub(1, 1):upper() -- Convert type to E/W/I/H/N
         return e
      end,
   },
},

Parsing and formatting information

This is the parsing and formatting function, from log to information

Default:

opts = {
   information = {
      parse = function(line)
         local i = {}
         i.file, i.type, i.action, i.details = line:match('^(.-) : (%w+): (%w+) (.+)')
         return i
      end,
      format = function(i)
         local formated = string.format('%s %s', i.action, i.details)
         return formated
      end,
   },
},

Commands

Compiling

This plugin compiles mql5/4 asyncronously.

" Set mql5 path
:MQLCompileSetSource my_ea.mq5
" Compile it
:MQLCompile

or

" Set current file path
:MQLCompileSetSource
" Compile it
:MQLCompile

or

" Compile with path
:MQLCompile my_ea.mq5
" Compile with file name modifier
:MQLCompile %

This plugin auto-detects mql5/mql4 by patterns given in opts.ft.[mql5|mql4].pattern. See Auto detection rules.

" Set source in NO mql5/4 buffers (like *.md)
:MQLCompileSetSource
" Automatically detect file, and set it as source

" Compiling also works same way.
:MQLCompile
" Automatically detect file, and compile it

So, :MQLCompileSetSource & Auto-detection allow you to compile the file anywhere in the project.

Show options

Show all current options as table. Just for checking.

:MQLCompileShowOptions

Lua functions

Below lua functions are also available. (with auto-detection by the extension)

-- Set mql5 path
require('mql_compile').set_source('my_ea.mq5')
-- Compile it
require('mql_compile').compile()

or

-- Set current file path
require('mql_compile').set_source()
-- Compile it
require('mql_compile').compile()

or

-- Compile with path
require('mql_compile').compile('my_ea.mq5')
-- Compile with file name modifier
require('mql_compile').compile('%')

Keymaps

Sample:

keys = {
    { '<F4>', '<cmd>MQLCompileSetSource<cr>' },
    { '<F7>', '<cmd>MQLCompile<cr>' },
},

or

keys = {
    { '<F4>', function() require('mql_compile').set_source() end },
    { '<F7>', function() require('mql_compile').compile() end },
},

Highlights

Warning

Highlighting(and syntaxing) has not finished yet.

Tip

Quickfix highlighting should not be modified by this plugin ?

Set-up highlight groups in quickfix list.

To use default, leave hlgroups = nil.

opts = {
   highlights = { -- Highlights on quickfix window
      enabled = true,
      hlgroups = {
         filename = { 'qfFileName', { link = 'Directory' } },  -- { '<Highlight name>' , { <highlight options> } }
         separator_left = { 'qfSeparatorLeft', { fg = '#cccccc' } },
         separator_right = { 'qfSeparatorRight', { fg = '#cccccc' } },
         line_nr = { 'qfLineNr', { fg = '#888888' } },
         col = { 'qfCol', { link = 'DiagnosticError' } },
         error = { 'qfError', { link = 'DiagnosticError' } },
         warning = { 'qfWarning', { link = 'DiagnosticWarn' } },
         info = { 'qfInfo', { link = 'DiagnosticInfo' } },
         hint = { 'qfHint', { link = 'DiagnosticHint' } },
         note = { 'qfNote', { link = 'DiagnosticHint' } },
         code = { 'qfCode', { fg = '#888888' } },
         text = { 'qfText', { link = 'Normal' } },
      },
   },
},

Auto detection rules

:MQLCompileSetSource

If the arg is set like :MQLCompileSetSource % or :MQLCompileSetSource my_ea.mq5, the command set it as source path preferentially.

But if no args are set, like :MQLCompileSetSource, the commannd detect the files automatically.
The detection order is below.

  1. Current buffer (if mql5/4)
  2. First detected mql5/4 file in git root dir (recursively)
  3. First detected mql5/4 file in cwd dir (recursively)

If no files are detected, the command returns error.

:MQLCompile

The compiling command without arg, like :MQLCompile, also detects the files in almost same way.

  1. Current buffer (if mql5/4)
  2. The path set by :MQLCompileSetSource command previousely
  3. First detected mql5/4 file in git root dir (recursively)
  4. First detected mql5/4 file in cwd dir (recursively)

Lua functions

And these lua functions follow same rules.

notify

Warning

Use v3.14.0 or earlier versions of nvim-notify. v3.14.1 not works somewhy with it's error.

This plugin optionally uses vim.notify() to show messages to users.
For those who want to have nicer messages, follow this.

  1. Install nvim-notify
  2. Put below code in init.lua, to replace default notify.
-- ex.) for lazy.nvim, `config = {}` in `lua/plugins/notify.lua`
vim.notify = require('notify')

Then mql-compile shows messages through it.

License

MIT License

TO-DO

  • Add version management
    • grep '#property version "x.xx"'
    • Auto mv ex5/ex4 to 'archive' dir, after compiling
    • Add ft.mql[5/4].compiled_extension
  • opts.information.actions has other actions ?
    • Now only 'compiling' & 'including' are confirmed
  • Auto compiling on save ? (Complicated...)
    • Should set source_path before.
    • Should search & dig including paths
    • If current buffer is matched to the included path ?
    • Compile source_path
  • Fit for https://github.com/kevinhwang91/nvim-bqf ?
  • git
    • Detect git root
    • List up & select from git root's mql5 files
    • If only one mql5 on git root, compile without prompt
  • Show fugitive message on progress & success or error
  • include path NOT WORKS for the space char in Program Files

Tip

Use vim.o.format ?

  • Easy to use, but not so customizable.
  • See naoina/syntastic-MQL
  • Counting functions should be suitable for it.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages